1、在cs二、cs三、cs4上安裝httpdjavascript
[root@cs2 ~]# yum install httpd
[root@cs3 ~]# yum install httpd
[root@cs4 ~]# yum install httpd
2、在cs三、cs4上安裝php和php-mysqlphp
[root@cs3 ~]# yum install php
[root@cs3 ~]# yum install php-mysql
[root@cs4 ~]# yum install php
[root@cs4 ~]# yum install php-mysql
3、在cs5上安裝mysqlcss
[root@cs5 ~]# yum install mariadb-server
4、在cs5上給dz論壇建立數據庫html
[root@cs5 ~]# systemctl start mariadb
[root@cs5 ~]# mysql
#建立一個discuz用的數據庫,庫名叫dz
MariaDB [(none)]> create database dz;
#建立並受權帳號dzadmin密碼123321給dz庫,受權範圍爲全網
MariaDB [(none)]> grant all privileges on dz.* to dzadmin@'%' identified by '123321';
#受權帳號dzadmin密碼123321給dz庫,受權範圍爲本地
MariaDB [(none)]> grant all privileges on dz.* to dzadmin@localhost identified by '123321';
#刷新權限
MariaDB [(none)]> flush privileges;
5、配置cs二、cs三、cs4的httpd前端
[root@cs2 ~]# vim /etc/httpd/conf/httpd.conf
ServerName cs2.xinfeng.com:80 #修改此處
DocumentRoot "/var/www/html/upload" #由於次文件還不存在,因此會報錯,等裝了dz以後再執行以後的就OK了
[root@cs2 ~]# httpd -t
[root@cs2 ~]# systemctl start httpd
[root@cs3 ~]# vim /etc/httpd/conf/httpd.conf
ServerName cs3.xinfeng.com:80 #修改此處
DocumentRoot "/var/www/html/upload"
[root@cs3 ~]# httpd -t
[root@cs3 ~]# systemctl start httpd
[root@cs4 ~]# vim /etc/httpd/conf/httpd.conf
ServerName cs4.xinfeng.com:80 #修改此處
DocumentRoot "/var/www/html/upload"
[root@cs4 ~]# httpd -t
[root@cs4 ~]# systemctl start httpd
6、在cs3安裝discuzjava
[root@cs3 ~]# wget http://download.comsenz.com/DiscuzX/3.2/Discuz_X3.2_SC_UTF8.zip
[root@cs3 ~]# mkdir Discuz
[root@cs3 ~]# unzip -d /root/Discuz Discuz_X3.2_SC_UTF8.zip
[root@cs3 ~]# cp -a /root/Discuz/* /var/www/html/
[root@cs3 ~]# chmod -R 777 /var/www/html/upload/*
打開cs3.xinfeng.com安裝mysql
論壇管理員帳號admin,密碼123linux
7、將cs3上安裝完成後的網站根目錄複製到cs2和cs4上ajax
#複製cs3下的/var/www/html全部文件到cs2/var/www/html/下
[root@cs3 ~]# scp -r /var/www/html/* 192.168.1.114:/var/www/html/
#複製cs3下的/var/www/html全部文件到cs4/var/www/html/下
[root@cs3 ~]# scp -r /var/www/html/* 192.168.1.115:/var/www/html/
8、將cs3和cs4的靜態文件存放目錄掛載到cs2下redis
#/var/www/html/upload中須要掛載的目錄以下
data ┄┄┄數據緩存及附件
static ┄┄┄靜態文件
設置cs2爲NFS服務器
[root@cs2 ~]# yum install nfs-utils
[root@cs2 ~]# yum install rpcbind
[root@cs2 ~]# service rpcbind start
[root@cs2 ~]# vim /etc/exports
#NFS輸出目錄爲data,能夠訪問這個目錄的主機爲cs3和cs4,權限爲讀寫,訪問uid爲0(root),容許超過1024的端口號鏈接
/var/www/html/upload/data/ 192.168.1.113(rw,all_squash,anonuid=0,insecure)
/var/www/html/upload/data/ 192.168.1.115(rw,all_squash,anonuid=0,insecure)
#NFS輸出目錄爲static,能夠訪問這個目錄的主機爲cs3和cs4,權限爲讀寫,訪問uid爲0(root),容許超過1024的端口號鏈接
/var/www/html/upload/static/ 192.168.1.113(rw,all_squash,anonuid=0,insecure)
/var/www/html/upload/static/ 192.168.1.115(rw,all_squash,anonuid=0,insecure)
[root@cs2 ~]# service nfs start
#查看共享狀態
[root@cs2 ~]# showmount -e
Export list for cs2.xinfeng.com:
/var/www/html/upload/static 192.168.1.115,192.168.1.113
/var/www/html/upload/data 192.168.1.115,192.168.1.113
在cs3上掛載
[root@cs3 ~]# yum install nfs-utils
[root@cs3 ~]# yum install rpcbind
[root@cs3 ~]# service rpcbind start
[root@cs3 ~]# service nfs start
[root@cs3 ~]# mount 192.168.1.114:/var/www/html/upload/data/ /var/www/html/upload/data/
[root@cs3 ~]# mount 192.168.1.114:/var/www/html/upload/static/ /var/www/html/upload/static/
[root@cs3 ~]# showmount -e 192.168.1.114
Export list for 192.168.1.114:
/var/www/html/upload/static 192.168.1.115,192.168.1.113
/var/www/html/upload/data 192.168.1.115,192.168.1.113
在cs4上掛載
[root@cs4 ~]# yum install nfs-utils
[root@cs4 ~]# yum install rpcbind
[root@cs4 ~]# service rpcbind start
[root@cs4 ~]# service nfs start
[root@cs4 ~]# mount 192.168.1.114:/var/www/html/upload/data/ /var/www/html/upload/data/
[root@cs4 ~]# mount 192.168.1.114:/var/www/html/upload/static/ /var/www/html/upload/static/
[root@cs4 ~]# showmount -e 192.168.1.114
Export list for 192.168.1.114:
/var/www/html/upload/static 192.168.1.115,192.168.1.113
/var/www/html/upload/data 192.168.1.115,192.168.1.113
開起日誌功能
[root@cs1 ~]# vim /etc/rsyslog.conf
#打開或增長一下幾行,讓udp514端口處於監聽狀態,並將日誌紀錄到指定文件中
$ModLoad imudp
$UDPServerRun 514
local2.* /var/log/haproxy.log
[root@cs1 ~]# systemctl restart rsyslog.service
[root@cs1 ~]# ss -unl | grep 514
UNCONN 0 0 *:514 *:*
UNCONN 0 0 :::514 :::*
配置haproxy
[root@cs1 ~]# yum install haproxy
[root@cs1 ~]# vim /etc/haproxy/haproxy.cfg
#---------------------------------------------------------------------
global #全局配置
log 127.0.0.1 local2 #日誌紀錄位置
chroot /var/lib/haproxy #haproxy的工做目錄
pidfile /var/run/haproxy.pid #pid文件位置
maxconn 4000 #最大鏈接數
user haproxy #運行時使用的用戶身份
group haproxy #運行時使用的組身份
daemon #啓動爲守護進程,不加此處運行在前臺
stats socket /var/lib/haproxy/stats #本地訪問stats統計信息時以套接字方式通訊
defaults #默認配置
mode http #已http模式運行
log global #默認日誌爲全局配置中日誌的設置
option httplog
option dontlognull
option http-server-close
option forwardfor except 127.0.0.0/8 #除本機外全部發往服務器的請求首部中加入「X-Forwarded-For」首部
option redispatch
retries 3
timeout http-request 10s
timeout queue 1m
timeout connect 10s
timeout client 1m
timeout server 1m
timeout http-keep-alive 10s
timeout check 10s
maxconn 3000 #前端最大併發鏈接數
listen static #設置統計報告頁面
bind *:9000 #監聽在本機9000端口
stats enable #打開
stats hide-version #隱藏haproxy版本
stats uri /hadzadmin?stats #統計頁面路徑
stats realm "HAProxy/ Static" #打開統計頁面的認證功能
stats auth hasts:123 #進入統計頁面所使用的帳號hasts和密碼123
stats admin if TRUE #條件知足時進入管理級別
frontend dz #前端設置
bind *:80 #監聽在80端口
acl url_static path_beg -i /data /static /images /javascript /stylesheets #url開頭爲這些的靜態內容
acl url_static path_end -i .jpg .gif .png .css .js .html .ico #url結尾帶爲這些的靜態內容
use_backend staser if url_static #若是靜態內容符合url_static的條件,就調度到staser中的服務器
default_backend dyser #其餘默認調度到dyser中的服務器
backend dyser #後端動態內容服務器設置
cookie srv insert nocache #在cookie中插入srv字串防止登陸信息丟失
balance roundrobin #調度算法爲輪詢
server cs3 192.168.1.113:80 check
server cs4 192.168.1.115:80 check
backend staser #後端靜態內容服務器設置
balance roundrobin
server cs1 192.168.1.114:80 check
[root@cs1 ~]# systemctl start haproxy
修改cs二、cs三、cs4的http配置文件,讓他們能收到真實訪問的ip
[root@cs2 ~]# vim /etc/httpd/conf/httpd.conf
#修改一下內容
LogFormat "%{X-Forwarded-For}i %l %u %t "%r" %>s %b "%{Referer}i" "%{User-Agent}i"" combined
[root@cs2 ~]# service httpd reload
#cs3和cs4執行一樣的操做
10、測試
分別看下cs2,cs3,cs4最近的訪問日誌
[root@cs2 ~]# tail -1 /var/log/httpd/access_log
192.168.1.110 - - [05/Jun/2016:16:36:12 +0800] "GET /data/attachment/forum/201606/05/161843j4au463pthh432zf.png HTTP/1.1" 304 - "-" "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/38.0.2125.122 Safari/537.36 SE 2.X MetaSr 1.0"
[root@cs3 uc_server]# tail -1 /var/log/httpd/access_log
192.168.1.110 - - [05/Jun/2016:16:33:07 +0800] "GET /misc.php?mod=patch&action=ipnotice&_r=0.40765136777967004&inajax=1&ajaxtarget=ip_notice HTTP/1.1" 200 65 "http://cs1.xinfeng.com/forum.php?mod=viewthread&tid=1&extra=page%3D1" "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/50.0.2661.102 Safari/537.36
[root@cs4 data]# tail -1 /var/log/httpd/access_log
192.168.1.110 - - [05/Jun/2016:16:33:07 +0800] "GET /misc.php?mod=patch&action=pluginnotice&inajax=1&ajaxtarget=plugin_notice HTTP/1.1" 200 65 "http://cs1.xinfeng.com/forum.php?mod=viewthread&tid=1&extra=page%3D1" "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/50.0.2661.102 Safari/537.36"