haproxy + varnish 實(shí)現(xiàn)動(dòng)靜分離

網(wǎng)絡(luò)拓?fù)?/h1>
image
image

準(zhǔn)備工作:

禁用selinux,清空防火墻規(guī)則。
iptables -F
setenforce 0

配置各主機(jī)配置:

static server:

systemctl start httpd
image
image

dynamic server

yum install httpd php php-mysql php-mbstring php-mcrypt
vim /var/www/html/index.php     
Dynamic Server -----three        
<?php 
 phpinfo();
?>
image
image

nfs以及mysql服務(wù)器:

[root@centos7 ~]#yum  -y install nfs-server  nfs-utils mariadb-server
[root@centos7 ~]#systemctl start  nfs-server.service
[root@centos7 ~]#systemctl start  mariadb.service
[root@centos7 ~]#mysql_secure_installation  //進(jìn)行mysql安全設(shè)置
[root@centos7 ~]#mysql -uroot -p123456 //以mysql的root身份登入。
MariaDB [(none)]> create database blogdb; //創(chuàng)建WordPress數(shù)據(jù)庫(kù)
MariaDB [(none)]> grant all on blogdb.* to wpuser@'192.168.18.%' identified by '123456';  
//創(chuàng)建WordPress用戶和密碼 
下載WordPress并解壓到、/app/blog下
[root@centos7 ~]#useradd -u 48  -r -s /sbin/nologin apache
[root@centos7 ~]#vim wp-config.php //直接對(duì)配置文件修改,
/** WordPress數(shù)據(jù)庫(kù)的名稱 */
define('DB_NAME', 'blogdb');
/** MySQL數(shù)據(jù)庫(kù)用戶名 */
define('DB_USER', 'wpuser');
/** MySQL數(shù)據(jù)庫(kù)密碼 */
define('DB_PASSWORD', '123456');
/** MySQL主機(jī) */
define('DB_HOST', '172.16.%。%');
[root@centos7 ~]#vim /etc/exports  //編輯nfs配置文件
/app/blog 192.168.18.0/24(rw,all_squash,anonuid=48,anongid=48)
掛載:

[root@centos7 ~]#vim /etc/fstab //寫進(jìn)配置文件??梢砸院箝_機(jī)自動(dòng)掛載。
192.168.18.103:/app/blog        /var/www/html/blog       nfs     defaults  0 0 //在最后添加這條記錄
[root@centos7 ~]#mkdir /var/www/html/blog -pv 
[root@centos7 ~]#mount -a  
image
image

varnish主機(jī):

Vim /etc/varnish/default.vcl
vcl 4.0;
import directors;   # 導(dǎo)入負(fù)載均衡模塊
# Default backend definition. Set this to point to your content server.
probe healthchk {    # 配置健康狀態(tài)檢查
        .url = "/.healthchk.html";   # 檢查狀態(tài)檢查的URL
        .timeout = 2s; # 超時(shí)時(shí)間
        .interval = 2s;# 每2秒檢查一次
        .window = 8; # 一共檢查的次數(shù)
        .threshold = 5; # 如果大于4次則為健康
}

backend appsrv1 {   # 配置后端主機(jī)
    .host = "172.16.251.240";
    .port = "80";
    .probe = healthchk;
}

haproxy 主機(jī):

Vim /etc/haproxy/haproxy.cfg
    frontend  main
    bind        *:80
    rspadd          X-Via:\ HAProxy-1
    rspidel         Server.*
    acl static      path_end -i .html .css .js
    acl static      path_end -i .jpg .jpeg .gif .png
    acl static      path_beg -i /images /static
    use_backend     websrvs if static
    default_backend appsrvs
listen status
    bind *:9009
    acl auth_admin  src 192.168.52.1
    stats           enable
    stats uri       /myhaproxy?status
    stats realm     HAProxy\ Admin\ Area
    stats auth      admin:admin
    stats admin     if auth_admin
backend websrvs
    option      forwardfor header X-Client
    balance     uri
    server      web1    172.16.252.31:6081 check
    hash-type   consistent
backend appsrvs
    option      forwardfor header X-Client
    balance     uri
    server      app1     172.16.252.59:80 cookie app1 check
    hash-type   consistent
image
image
image
image
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容