Mengenal Apa itu CDN dan Bagaimana cara membuat CDN Server sendiri

Mengenal Apa itu CDN dan Bagaimana cara membuat CDN Server sendiri

Dalam artikel sebelumnya, kami pernah membahas Cara membuat CDN Server sendiri dengan BIND (Silahkan Baca Artikelnya), Namun terakhir kami cek, ternya

Mengenal Apa itu DNS (Domain Name System)
Cara membuat CDN Sendiri dengan BIND dan GeoIP

Dalam artikel sebelumnya, kami pernah membahas Cara membuat CDN Server sendiri dengan BIND (Silahkan Baca Artikelnya), Namun terakhir kami cek, ternyata link download untuk GeoIP CSV sudah berubah sehingga tutorial tersebut tidak bisa berjalan dengan baik, dan perlu beberapa modifikasi yang akan dibahas di tutorial ini. Selain itu, dalam tutorial ini juga akan kami bahas secara detail tentang cara setting BIND9 di Ubuntu server.

Apa itu CDN

Sebelum melangkah lebih jauh, ada baiknya kita mengingat lagi apa itu CDN ? CDN adalah kependekan dari Content Delivery Network. Dengan CDN, kita bisa memperpendek routing karena setiap user akan mengambil content dari server terdekat.

Dalam tutorial ini, kita akan belajar membuat GeoDNS yang akan mengelompokkan pengunjung menjadi 2 regional yang berbeda. Kita akan menggunakan domain blog milik kami yaitu Humayraa.com. Agar Lebih simple, skenarionya adalah sebagai berikut:
1. Pengunjung dari Asia dan Australia
Pengunjung dari Asia (Indonesia, Singapore, Malaysia, Vietnam, Japan, Australia) akan kami arahkan ke server IIX di jakarta.
2. Pengunjung Selain Asia dan Australia
Pengunjung asia akan kita arahkan ke server german (Eropa). Dengan demikian mereka akan mendapatkan speed loading yang optimal dibanding dengan server IIX.

Sebelum memulai itu semua, kita butuh Server DNS. di Ubuntu dan CentOS yang paling banyak digunakan adalah BIND9. Sehingga langkah pertama yang harus kita lakukan adalah install BIND9

Cara Install BIND9

Siapkan server DNS dengan sebuah VPS kecil (misal VPS dengan RAM 512 atau 256MB) yang sudah diinstall OS Ubuntu 16.04 atau Ubuntu 18.04 kemudian install BIND 9 dengan perintah berikut:

apt-get install -y bind9

Setelah BIND9 terinstall, langkah berikutnya adalah setting GeoDNS dengan menggunakan GeoIP

Membuat GeoDNS

Point utama dalam artikel ini adalah GeoDNS, yaitu Domain name server yang bisa mendeteksi lokasi pengunjung web. Untuk bisa mengetahui dari mana asal pengunjung, kita perlu menggunakan GeoIP. Anda bisa mendownload GeoIP di http://geoip.site/download/MaxMind/GeoIP.acl dan menyimpannya di VPS. Lakukan langkah berikut:

cd /etc/bind
wget https://geoip.site/download/MaxMind/GeoIP.acl

Karena IP selalu berkembang dan mengalami penambahan, maka disarankan langkah di atas Anda lakukan secara ruin setiap satu atau dua bulan sekali.

Anda bisa lihat isi file GeoIP.acl sebagai berikut :
(cara melihat text file bisa dengan perintah cat yaitu cat /etc/bind/GeoIP.acl
dan hasilnya adalah sebagai berikut:

acl "A1" {
        64.46.32.0/23;
        64.46.35.0/24;
        64.46.40.64/26;
        64.46.42.0/23;
        64.46.47.0/24;
        66.38.243.0/24;
        67.15.183.0/25;
        69.10.130.128/26;
        69.10.139.0/25;
        69.10.140.192/26;
...
acl "GB" {
        2.6.190.56/29;
        9.20.0.0/17;
        12.129.72.32/29;
        23.0.0.0/9;
        25.0.0.0/8;
        32.58.57.0/29;
        32.58.58.0/28;
        32.58.59.0/29;
        32.60.34.96/27;
        51.0.0.0/8;
...

A1, GB adalah kode negara pemilik IP (Country Code). Untuk memudahkan Anda, berikut adalah Country code untuk pembagian regional sesuai dengan GeoIP standard:

A1,"Anonymous Proxy"
A2,"Satellite Provider"
O1,"Other Country"
AD,"Andorra"
AE,"United Arab Emirates"
AF,"Afghanistan"
AG,"Antigua and Barbuda"
AI,"Anguilla"
AL,"Albania"
AM,"Armenia"
AO,"Angola"
AP,"Asia/Pacific Region"
AQ,"Antarctica"
AR,"Argentina"
AS,"American Samoa"
AT,"Austria"
AU,"Australia"
AW,"Aruba"
AX,"Aland Islands"
AZ,"Azerbaijan"
BA,"Bosnia and Herzegovina"
BB,"Barbados"
BD,"Bangladesh"
BE,"Belgium"
BF,"Burkina Faso"
BG,"Bulgaria"
BH,"Bahrain"
BI,"Burundi"
BJ,"Benin"
BL,"Saint Bartelemey"
BM,"Bermuda"
BN,"Brunei Darussalam"
BO,"Bolivia"
BQ,"Bonaire, Saint Eustatius and Saba"
BR,"Brazil"
BS,"Bahamas"
BT,"Bhutan"
BV,"Bouvet Island"
BW,"Botswana"
BY,"Belarus"
BZ,"Belize"
CA,"Canada"
CC,"Cocos (Keeling) Islands"
CD,"Congo, The Democratic Republic of the"
CF,"Central African Republic"
CG,"Congo"
CH,"Switzerland"
CI,"Cote d'Ivoire"
CK,"Cook Islands"
CL,"Chile"
CM,"Cameroon"
CN,"China"
CO,"Colombia"
CR,"Costa Rica"
CU,"Cuba"
CV,"Cape Verde"
CW,"Curacao"
CX,"Christmas Island"
CY,"Cyprus"
CZ,"Czech Republic"
DE,"Germany"
DJ,"Djibouti"
DK,"Denmark"
DM,"Dominica"
DO,"Dominican Republic"
DZ,"Algeria"
EC,"Ecuador"
EE,"Estonia"
EG,"Egypt"
EH,"Western Sahara"
ER,"Eritrea"
ES,"Spain"
ET,"Ethiopia"
EU,"Europe"
FI,"Finland"
FJ,"Fiji"
FK,"Falkland Islands (Malvinas)"
FM,"Micronesia, Federated States of"
FO,"Faroe Islands"
FR,"France"
GA,"Gabon"
GB,"United Kingdom"
GD,"Grenada"
GE,"Georgia"
GF,"French Guiana"
GG,"Guernsey"
GH,"Ghana"
GI,"Gibraltar"
GL,"Greenland"
GM,"Gambia"
GN,"Guinea"
GP,"Guadeloupe"
GQ,"Equatorial Guinea"
GR,"Greece"
GS,"South Georgia and the South Sandwich Islands"
GT,"Guatemala"
GU,"Guam"
GW,"Guinea-Bissau"
GY,"Guyana"
HK,"Hong Kong"
HM,"Heard Island and McDonald Islands"
HN,"Honduras"
HR,"Croatia"
HT,"Haiti"
HU,"Hungary"
ID,"Indonesia"
IE,"Ireland"
IL,"Israel"
IM,"Isle of Man"
IN,"India"
IO,"British Indian Ocean Territory"
IQ,"Iraq"
IR,"Iran, Islamic Republic of"
IS,"Iceland"
IT,"Italy"
JE,"Jersey"
JM,"Jamaica"
JO,"Jordan"
JP,"Japan"
KE,"Kenya"
KG,"Kyrgyzstan"
KH,"Cambodia"
KI,"Kiribati"
KM,"Comoros"
KN,"Saint Kitts and Nevis"
KP,"Korea, Democratic People's Republic of"
KR,"Korea, Republic of"
KW,"Kuwait"
KY,"Cayman Islands"
KZ,"Kazakhstan"
LA,"Lao People's Democratic Republic"
LB,"Lebanon"
LC,"Saint Lucia"
LI,"Liechtenstein"
LK,"Sri Lanka"
LR,"Liberia"
LS,"Lesotho"
LT,"Lithuania"
LU,"Luxembourg"
LV,"Latvia"
LY,"Libyan Arab Jamahiriya"
MA,"Morocco"
MC,"Monaco"
MD,"Moldova, Republic of"
ME,"Montenegro"
MF,"Saint Martin"
MG,"Madagascar"
MH,"Marshall Islands"
MK,"Macedonia"
ML,"Mali"
MM,"Myanmar"
MN,"Mongolia"
MO,"Macao"
MP,"Northern Mariana Islands"
MQ,"Martinique"
MR,"Mauritania"
MS,"Montserrat"
MT,"Malta"
MU,"Mauritius"
MV,"Maldives"
MW,"Malawi"
MX,"Mexico"
MY,"Malaysia"
MZ,"Mozambique"
NA,"Namibia"
NC,"New Caledonia"
NE,"Niger"
NF,"Norfolk Island"
NG,"Nigeria"
NI,"Nicaragua"
NL,"Netherlands"
NO,"Norway"
NP,"Nepal"
NR,"Nauru"
NU,"Niue"
NZ,"New Zealand"
OM,"Oman"
PA,"Panama"
PE,"Peru"
PF,"French Polynesia"
PG,"Papua New Guinea"
PH,"Philippines"
PK,"Pakistan"
PL,"Poland"
PM,"Saint Pierre and Miquelon"
PN,"Pitcairn"
PR,"Puerto Rico"
PS,"Palestinian Territory"
PT,"Portugal"
PW,"Palau"
PY,"Paraguay"
QA,"Qatar"
RE,"Reunion"
RO,"Romania"
RS,"Serbia"
RU,"Russian Federation"
RW,"Rwanda"
SA,"Saudi Arabia"
SB,"Solomon Islands"
SC,"Seychelles"
SD,"Sudan"
SE,"Sweden"
SG,"Singapore"
SH,"Saint Helena"
SI,"Slovenia"
SJ,"Svalbard and Jan Mayen"
SK,"Slovakia"
SL,"Sierra Leone"
SM,"San Marino"
SN,"Senegal"
SO,"Somalia"
SR,"Suriname"
SS,"South Sudan"
ST,"Sao Tome and Principe"
SV,"El Salvador"
SX,"Sint Maarten"
SY,"Syrian Arab Republic"
SZ,"Swaziland"
TC,"Turks and Caicos Islands"
TD,"Chad"
TF,"French Southern Territories"
TG,"Togo"
TH,"Thailand"
TJ,"Tajikistan"
TK,"Tokelau"
TL,"Timor-Leste"
TM,"Turkmenistan"
TN,"Tunisia"
TO,"Tonga"
TR,"Turkey"
TT,"Trinidad and Tobago"
TV,"Tuvalu"
TW,"Taiwan"
TZ,"Tanzania, United Republic of"
UA,"Ukraine"
UG,"Uganda"
UM,"United States Minor Outlying Islands"
US,"United States"
UY,"Uruguay"
UZ,"Uzbekistan"
VA,"Holy See (Vatican City State)"
VC,"Saint Vincent and the Grenadines"
VE,"Venezuela"
VG,"Virgin Islands, British"
VI,"Virgin Islands, U.S."
VN,"Vietnam"
VU,"Vanuatu"
WF,"Wallis and Futuna"
WS,"Samoa"
YE,"Yemen"
YT,"Mayotte"
ZA,"South Africa"
ZM,"Zambia"
ZW,"Zimbabwe"

Konfigurasi BIND9 untuk GeoDNS

untuk bisa membuat GeoDNS dengan BIND9, tambahkan baris berikut di /etc/bind/named.conf :

include "/etc/bind/GeoIP.acl";

sehingga isi dari /etc/bind/named.conf menjadi:

// This is the primary configuration file for the BIND DNS server named.
//
// Please read /usr/share/doc/bind9/README.Debian.gz for information on the
// structure of BIND configuration files in Debian, *BEFORE* you customize
// this configuration file.
//
// If you are just adding zones, please do that in /etc/bind/named.conf.local
include "/etc/bind/GeoIP.acl";
include "/etc/bind/named.conf.options";
include "/etc/bind/named.conf.local";
include "/etc/bind/named.conf.default-zones";

setelah itu edit file /etc/bind/named.conf.local

//
// Do any local configuration here
//
// Consider adding the 1918 zones here, if they are not used in your
// organization
//include "/etc/bind/zones.rfc1918";
view "asia" {
              match-clients { SG; MY; BN; HK; KP; KR; PH; TH; CN; AU; JP;};
              recursion no;
              zone "humayraa.com" {
                    type master;
                    file "/etc/bind/asia-humayraa.com.db";
              };
};
view "negara-lain" {
              match-clients { any; };
              recursion no;
              zone "humayraa.com" {
                    type master;
                    file "/etc/bind/de-humayraa.com.db";
              };
};

Setelah itu, edit pula named.conf.default-zones dan tambahkan di awal baris:

view "default" {
              match-clients { any; };
              recursion no;

dan di akhir baris tambahkan penutup };

sehingga isi file named.conf.default-zones adalah sebagai berikut:

view "default" {
              match-clients { any; };
              recursion no;

// prime the server with knowledge of the root servers
zone "." {
        type hint;
        file "/etc/bind/db.root";
};

// be authoritative for the localhost forward and reverse zones, and for
// broadcast zones as per RFC 1912



zone "localhost" {
        type master;
        file "/etc/bind/db.local";
};

zone "127.in-addr.arpa" {
        type master;
        file "/etc/bind/db.127";
};

zone "0.in-addr.arpa" {
        type master;
        file "/etc/bind/db.0";
};

zone "255.in-addr.arpa" {
        type master;
        file "/etc/bind/db.255";
};


};

Buat zone untuk masing-masing region.
gunakan perintah nano atau vim untuk membuat zone.

nano /etc/bind/asia-humayraa.com.db

Isi dari zone /etc/bind/asia-humayraa.com.db adalah:

; Zone file for humayraa.com
$TTL 14400
humayraa.com.   86400   IN      SOA     cdn1.bestariwebhost.com.        support.bestariwebhost.com.     (
                                                2019060306 ;Serial Number
                                                3600 ;refresh
                                                1800 ;retry
                                                1209600 ;expire
                                                86400 ;minimum
        )
humayraa.com.   86400   IN      NS      cdn1.bestariwebhost.com.
humayraa.com.   86400   IN      NS      cdn2.bestariwebhost.com.
humayraa.com.   14400   IN      A       45.64.99.226
humayraa.com.   14400   IN      MX      0       mx.bestariwebhost.com.
mail    14400   IN      CNAME   humayraa.com.
www     14400   IN      CNAME   humayraa.com.

Kemudian buat Zone /etc/bind/de-humayraa.com.db dengan isi sebagai berikut:

; Zone file for humayraa.com
$TTL 14400
humayraa.com.   86400   IN      SOA     cdn1.bestariwebhost.com.        support.bestariwebhost.com.     (
                                                2019060306 ;Serial Number
                                                3600 ;refresh
                                                1800 ;retry
                                                1209600 ;expire
                                                86400 ;minimum
        )
humayraa.com.   86400   IN      NS      cdn1.bestariwebhost.com.
humayraa.com.   86400   IN      NS      cdn2.bestariwebhost.com.
humayraa.com.   14400   IN      A       85.114.138.250
humayraa.com.   14400   IN      MX      0       mx.bestariwebhost.com.
mail    14400   IN      CNAME   humayraa.com.
www     14400   IN      CNAME   humayraa.com.

Perhatikan bahwa A record untuk kedua zone antara /etc/bind/asia-humayraa.com.db dan /etc/bind/de-humayraa.com.db berbeda.
Setalah anda membuat zone, Pastikan permission file di 644, dengan cara

chmod 644 /etc/bind/*-humayraa.com.db

setelah itu restart BIND9 dengan perintah berikut:

service bind9 restart

check hasilnya di whatsmydns.net sebagai berikut:

cara membuat cdn server sendiri dengan bind9

Silahkan edit kembali file /etc/bind/named.conf.local untuk pembagian regional yang lebih presisi, dan jangan lupa untuk restart BIND9 setiap anda selesai melakukan editing regional.
Semoga bermanfaat

COMMENTS

WORDPRESS: 0
DISQUS: 1