Pengantar
Cache sering kali merupakan perangkat lunak paling penting untuk bisnis berbasis web.
Tembolok Pernis adalah mesin HTTP open source/proxy HTTP terbalik yang populer – dan kuat yang digunakan oleh lebih dari 3,4 juta situs web.
Varnish Cache adalah proksi balik HTTP caching open-source yang dapat membantu meningkatkan kinerja server web.
Dalam panduan ini, kami akan menunjukkan cara menginstal Varnish Cache dan menggunakannya.
Jadi silakan ikuti langkah-langkah di bawah ini:
Instal Apache
- Instal server HTTP Apache dengan perintah:
dnf install httpd -y
- Ubah port Apache dari 80 ke 8080 . cukup buka httpd.conf dan mengubahnya.
vim /etc/httpd/conf/httpd.conf
Barisnya harus seperti itu :
Listen 8080
- Mulai dan aktifkan apache
systemctl start httpd.service
systemctl enable httpd.service
Mengonfigurasi setelan Firewall
- Cukup edit firewall untuk mengizinkan lalu lintas di port 80
firewall-cmd --zone=public --add-service=http --permanent
firewall-cmd --reload
Periksa konfigurasi Apache
- Sentuh file bernama unixcop.html
touch /var/www/html/unixcop.html
- Gunakan ikal untuk menguji server pada port 8080.
[root@unixcop ~]# curl -I http://localhost:8080/unixcop.html
HTTP/1.1 200 OK
Date: Wed, 29 Sep 2021 14:59:19 GMT
Server: Apache/2.4.37 (centos)
Last-Modified: Wed, 29 Sep 2021 14:58:59 GMT
ETag: "0-5cd2391f65f14"
Accept-Ranges: bytes
Content-Type: text/html; charset=UTF-8
[root@unixcop ~]#
Instal cache Pernis
- Unduh repositori EPEL-Release.
dnf install epel-release -y
- Tambahkan repo Cache Pernis. Buka /etc/yum.repos.d/varnish.repo dengan vim.
vim /etc/yum.repos.d/varnish.repo
- Kemudian tambahkan yang berikut ini.
[varnish]
name=varnishcache_varnish
baseurl=https://packagecloud.io/varnishcache/varnish60lts/el/8/x86_64
repo_gpgcheck=1
gpgcheck=0
enabled=1
gpgkey=https://packagecloud.io/varnishcache/varnish60lts/gpgkey
sslverify=1
sslcacert=/etc/pki/tls/certs/ca-bundle.crt
metadata_expire=300
- Perbarui cache dnf untuk repo Varnish.
[root@unixcop ~]# dnf -q makecache -y --disablerepo='*' --enablerepo='varnish'
Importing GPG key 0xA750EDCD:
Userid : "https://packagecloud.io/varnishcache/varnish60lts (https://packagecloud.io/docs#gpg_signing) <[email protected]>"
Fingerprint: 48D8 1A24 CB04 56F5 D594 31D9 4CFC FD6B A750 EDCD
From : https://packagecloud.io/varnishcache/varnish60lts/gpgkey
[root@unixcop ~]#
- Instal cache Varnish.
dnf install varnish -y
- Pastikan Varnish sudah terpasang.
[root@unixcop ~]# varnishd -V
varnishd (varnish-6.0.6 revision 29a1a8243dbef3d973aec28dc90403188c1dc8e7)
Copyright (c) 2006 Verdens Gang AS
Copyright (c) 2006-2019 Varnish Software AS
[root@unixcop ~]#
- Aktifkan Varnish di sistem setelah reboot.
systemctl enable --now varnish
- Port default pernis adalah 6081 . Jadi edit varnish.service lalu ganti dengan port 80 .
vim /usr/lib/systemd/system/varnish.service
Anda harus mengedit ExecStart dan ganti portnya. Garis harus seperti yang ditunjukkan pada tangkapan layar.
![](https://m.unixlinux.online/article/uploadfiles/202204/2022042816033574.png)
- Mulai ulang Pernis.
systemctl restart varnish
Uji Pernis
- Gunakan juga curl untuk menguji pernis.
curl -I http://localhost/unixcop.html
Outputnya akan muncul seperti itu.
X-Varnish:2 dan Melalui:1.1 varnish (Varnish/6.0) saat Varnish Cache sedang berjalan.
[root@unixcop ~]# curl -I http://localhost/unixcop.html
HTTP/1.1 200 OK
Date: Wed, 29 Sep 2021 15:08:35 GMT
Server: Apache/2.4.37 (centos)
Last-Modified: Wed, 29 Sep 2021 14:58:59 GMT
ETag: "0-5cd2391f65f14"
Content-Length: 0
Content-Type: text/html; charset=UTF-8
X-Varnish: 2
Age: 0
Via: 1.1 varnish (Varnish/6.0)
Accept-Ranges: bytes
Connection: keep-alive
[root@unixcop ~]#
Pastikan semuanya baik-baik saja
- Jadi Periksa port untuk memverifikasi proses mana yang mendengarkan di port mana menggunakan ss seperti gambar di bawah ini:
ss -lnpt | grep 80
![](https://m.unixlinux.online/article/uploadfiles/202204/2022042816033683.png)
Anda mungkin memperhatikan bahwa pernis sedang mendengarkan di port 80 dan httpd ada di port 8080 seperti yang ditunjukkan pada tangkapan layar di atas.
Uji pernis dari server lain
- Anda harus menggunakan curl untuk menguji varnish dan memberikan IP server tempat varnish berjalan.
[qadry@rhel-pc ~]$ curl -I http://192.168.13.135/unixcop.html
HTTP/1.1 200 OK
Date: Wed, 29 Sep 2021 15:11:26 GMT
Server: Apache/2.4.37 (centos)
Last-Modified: Wed, 29 Sep 2021 14:58:59 GMT
ETag: "0-5cd2391f65f14"
Content-Length: 0
Content-Type: text/html; charset=UTF-8
X-Varnish: 5
Age: 0
Via: 1.1 varnish (Varnish/6.0)
Accept-Ranges: bytes
Connection: keep-alive
[qadry@rhel-pc ~]$
Kesimpulan
Jadi itu saja..
Kami mengilustrasikan cara memasang dan menggunakan cache pernis yang dapat membantu meningkatkan kinerja server web.
Terima kasih!!