我只是做个测试[varnish动静分离]
1,动静分离只有在安装网页程序后实现的
2,通过nfs共享将两台httpd服务的网页数据都有mariadb共享,然后安装网页,等安装成功后将nfs共享的数据复制到本地httpd服务器上
然后关闭nfs共享
3,就可以测试了,可以发现静态资源的目录大小在不断增加,而动态资源一般不会增加
4,请关闭防火墙和selinux
操作如下:
先配置mariadb和nfs
yum install mariadb-server nfs-utils id apache || useradd -r -g 48 apache mkdir /web/apps/dz systemctl start nfs
vim /etc/exports
/web/apps/dz 192.168.153.0/24(rw,sync)
cp /share/lamp/Discuz_X3.2_SC_UTF8.zip . unzip Discuz_X3.2_SC_UTF8.zip mv upload/* /web/apps/dz/ setfacl -R -m u:apache:rwx /web/apps/dz/ touch /web/apps/dz/.check #varnish 健康检查文件
create database dz; grant all on dz.* to 'dzuser'@'192.168.153.%' identified by 'dzpass'; flush privileges;
2,配置http动态服务器
yum install httpd php php-mysql nfs-utils mount -t nfs 192.168.153.133:/web/apps/dz /var/www/html/ iptables -F setenforce 0 systemctl start httpd
3,配置静态资源服务器
yum install httpd nfs-utils php php-mysql mount -t nfs 192.168.153.133:/web/apps/dz /var/www/html/ iptables -F setenforce 0 systemctl start httpd
4,配置varnish
yum install varnish
vim /etc/varnish/varnish.params
vim /etc/varnish/default.vcl
# 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"; } import directors; probe healthcheck { .url = "/.check"; .window = 3; .threshold = 3; .interval = 1s; .timeout = 1s; } backend one { .host = "192.168.153.131"; .port = "80"; .probe = healthcheck; } backend two { .host = "192.168.153.132"; .port = "80"; .probe = healthcheck; } 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. if(req.url ~ "(?i)\.php$"){ set req.backend_hint = one; } else { set req.backend_hint = two; } } 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. if (beresp.http.cache-control !~ "s-maxage"){ if(bereq.url ~ "(?i)\.(jpg|jpeg|png|gif|css|js)$"){ unset beresp.http.Set-Cookie; set beresp.ttl = 3600s; } } } sub vcl_deliver { # Happens when we have all the pieces we need, and are about to send the # response to the client. # # You can do accounting or modifying the final object here. if(obj.hits>0){ set resp.http.X-Cache ="HIT via"+" "+server.ip; } else { set resp.http.X-Cache = "MISS via"+" "+server.ip; } }
5安装网页
动态服务器操作如下
cd cp -a /var/www/html/ . systemctl stop httpd umount /var/www/html/ rm -rf /var/www/html/* cp -a html/ /var/www/ systemctl start httpd
静态服务器操作如下
cd cp /var/www/html/ . systemctl stop httpd umount /var/www/html/ rm -rf /var/www/html/* cp -a html/ /var/www/ systemctl start httpd
mariadb 数据库
systemctl stop nfs
再次进行测试