Chia Sẽ Kinh Nghiệm Về IT



Tìm Kiếm Với Google
-


Gởi Ðề Tài Mới  Gửi trả lời
 
Công Cụ Xếp Bài
Tuổi 13-04-2015, 03:01 PM   #1
hoctinhoc
Guest
 
Trả Lời: n/a
Hướng dẫn sử dụng Varnish 4 trên CentOS 6, Centos 7 (Giải thích các thông số của Var)
Hướng dẫn sử dụng Varnish 4 trên CentOS 6, Centos 7

Giải thích các thông số của Varnish

http://sharadchhetri.com/2014/12/20/...ntos-7-rhel-7/

How to install Varnish 4 version on CentOS 7 / RHEL 7



In this tutorial we will learn, how to install Varnish 4 version on CentOS 7 / RHEL 7 . Varnish is populalry known for Frontend Web Cacheing software. Whereas it can also be used as loadbalancer.
Recently , the Varnish version 4 is released, which comes up with new features and also new syntaxes/parameters.
The Varnish 4 has lots of changes. We will strictly recommend if you are planning to upgrade Varnish from version 3 to 4, do it in test or staging server. You will see lots of syntax and parameters difference. Hence, when you upgrade the Varnish by using yum or apt-get command, the Varnish service will not start, only due to incompatible syntaxes/parameters.




Before starting installing Varnish 4.x version on CentOS 7 Server. Do not forget to read below given links.


1. Changes in Varnish version 4
2. Varnish VSL Query Expression
Follow the Given below steps to install Varnish 4.x on CentOS 7 / RHEL 7

Step 1. Create varnish.repo file in /etc/yum.repos.d/ . We use vi editior, you can use your favourite file editor.
vi /etc/yum.repos.d/varnish.repo

Paste below given yum configuration in varnish.repo file .
[varnish-4.0]
name=Varnish 4.0 for Enterprise Linux
baseurl=https://repo.varnish-cache.org/redhat/varnish-4.0/el7/$basearch
enabled=1
gpgcheck=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-VARNISH


Step 2. Use yum command to install Varnish


yum install varnish varnish-libs varnish-libs-devel

Step 3. Now you will get new varnish configuration directory and files.
Varnish Configuration Directory : /etc/varnish
Varnish Configuration Files : We will get 3 new files in /etc/varnish directory

(a) default.vcl

(b) secret

(c) varnish.params




Step 4. Bydefault Varnish 4 listens on port 6081 . This information we can get in file varnish.params. I hope you are also aware that http listen on port 80. Hence, we will change the port 6081 to 80 so that website first access Varnish Cached in frontend.
By default Varnish listen on port 6081.
VARNISH_LISTEN_PORT=6081 Edit varnish.params file and in paramter VARNISH_LISTEN_PORT change port 6081 to 80 , so that Varnish will listen on port 80


vi /etc/varnish/varnish.params

VARNISH_LISTEN_PORT=80

Step 5. In this step we will decide the Varnish Cache storage. We have two option here,



NOTE: select any one option. NOT BOTH


(i) Varnish Cache storage on Disk
(ii) Varnish Cache storage on Memory (RAM) [ For more faster access ].
Here, you have to decide which option varnish storage option you will go for.


(i) Setting Varnish Cache Storage on disk :
In this setting, edit varnish.params file and set value on the parameter VARNISH_STORAGE .


vi /etc/varnish/varnish.params

Below given is default value for VARNISH_STORAGE . The storage file varnish_storage.bin has size of 1 GB and located at /var/lib/varnish/


VARNISH_STORAGE="file,/var/lib/varnish/varnish_storage.bin,1G" (ii) Setting Varnish Cache Storage on RAM :

This is another option which is faster than varnish storage on disk and that is using RAM.If you have server with high RAM configuration and have enough of free RAM for Varnish,use this option then.
NOTE:Meaning of Malloc is “Allocate memory block”.


vi /etc/varnish/varnish.params

We have assigned 512m RAM for Varnish storage. (You can replace with your desired value as per your system’s RAM availability)


VARNISH_STORAGE="malloc,512m"

Learn More About Varnish Storage Backend
Step 6. Now about default.vcl file . It is set of VCL rules that are built in to Varnish.
Below given is default.vcl reference.




# This is an example VCL file for Varnish.
#
# It does not do anything by default, delegating control to the
# builtin VCL. The builtin VCL is called when there is no explicit
# return statement.
#
# See the VCL chapters in the Users Guide at https://www.varnish-cache.org/docs/
# and http://varnish-cache.org/trac/wiki/VCLExamples for more examples.


# Marker to tell the VCL compiler that this VCL has been adapted to the
# new 4.0 format.
vcl 4.0;
# Default backend definition. Set this to point to your content server.
backend default {
.host = "127.0.0.1";
.port = "8080";
}
sub vcl_recv {
# Happens before we check if we have this in cache already.
#
# Typically you clean up the request here, removing cookies you don't need,
# rewriting the request, etc.
}
sub vcl_backend_response {
# Happens after we have read the response headers from the backend.
# # Here you clean the response headers, removing silly Set-Cookie headers
# and other mistakes your backend does.
} sub vcl_deliver {
# Happens when we have all th pieces we need, and are about to send the
# response to the client.
#
# You can do accounting or modifying the final object here.
}


The default.vcl file is actually is not fully configured.Hence, there is nothing for vcl_recv, vcl_backend_response and vcl_deliver.
It is important to know, to direct the marker for Varnish 4.x setting, in default.vcl file vcl 4.0; should be set. (see above default.vcl file)
As per backend director defined in default.vcl file. The web traffic goes to loopback IP address 127.0.0.1 and connect to port 8080 for http communication.


backend default {
.host = "127.0.0.1";
.port = "8080";
}


As per above backend default configuration, it means – the Varnish and web server are running in single same server.
We have already changed the Varnish port to 80 in Step 4. Now as per configuration, web server should listen the port no. 8080. If your web server is running on different port no. , give the same port no. in “backend default” respective to server.

Change apache port no. to 8080

Here, we will quickly change the Apache’s port no. to 8080 because the port no. 8080 we have defined in varnish default.vcl file.
change the value of Listen in httpd.conf
vi /etc/httpd/conf/httpd.conf

Listen *:8080

Changing port no. in the Apache’s Virtual Host to 8080. Below is the sample vhost configuration.


vi /etc/httpd/conf/httpd.conf

<VirtualHost *:8080>
ServerAdmin sharad@example.com
ServerName example.com
DocumentRoot /var/www/html/
ErrorLog logs/sample-error.log
CustomLog logs/sampleaccess_log common
</VirtualHost>

Final Step: Start/restart the Varnish,Apache services



Now we are almost finish to Varnish setup. Go step wise.
1. Restart the Apache (Webserver) : To effectively change the port no. of Apache service. Restart the apache service on CentOS 7/RHEL 7 server.


systemctl restart httpd

No the apache will lsiten the port 8080. Use ss command.
2. Restart the Varnish server : After varnish get restarted the varnish will lsiten to port 80. Hence, whenever user browse the http website, first the content will be served by Varnish Server from Cache (either from Disk or RAM [malloc] , as we have set in Step 5)


systemctl restart varnishd

3. Enable Varnish logging : Logs are important for any service, therefore we will enable the Varnish logging. Restart the varnishncsa and varnishlog server.
Restart varnishncsa.


systemctl restart varnishncsa

Restart varnishlog .


systemctl restart varnishlog

By defualt Varnish log directory path is /var/log/varnish/
You will see two log files of Varnish
[root@server ~]# ls -l /var/log/varnish/
total 11740
-rw-r--r-- 1 root root 20454 Dec 20 13:09 varnish.log
-rw-r--r-- 1 root root 11994544 Dec 20 13:09 varnishncsa.log
[root@server ~]#

Now your site is up and running. And at frontend the Varnish Cache server will serve the content first. It will make your website access faster.


http://sharadchhetri.com/2014/12/20/...ntos-7-rhel-7/
  Trả lời ngay kèm theo trích dẫn này
Gửi trả lời



Quyền Hạn Của Bạn
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is Mở
Hình Cảm xúc đang Mở
[IMG] đang Mở
Mã HTML đang Tắt




Bây giờ là 05:25 AM. Giờ GMT +7



Diễn đàn tin học QuantriNet
quantrinet.com | quantrimang.co.cc
Founded by Trương Văn Phương | Developed by QuantriNet's members.
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.