1.安装程序
分别在lab2,lab3,lab4上安装httpd,
在lab3,lab4上安装php以及php-mysql
2.部署论坛
#在Mysql服务器上创建一个Discuz数据库
mysql> create database discuz;
#为Mysql提供远程访问帐号,并配置密码
mysql> grant all on discuz.* to bbs@'172.16.21.%' identified by '123456';
#将论坛程序解压到lab3的网站根目录,通过网页访问lab3,安装论坛程序
论坛程序已经可以访问
将网站根目录复制到lab4及lab2的对应目录下,并保证文件权限
[root@lab4 ~]# scp -r lab3:/var/www/html/* /var/www/html/ [root@lab4 ~]# scp -r lab2:/var/www/html/* /var/www/html/
3.创建配置共享存储
[root@lab2 html]# cat /etc/exports /var/www/html/data 172.16.21.0/24(rw,all_squash,anonuid=48,insecure) #lab3挂载 [root@lab4 data]# mount lab2:/var/www/html/data/ /var/www/html/data/ #lab4挂载 [root@lab4 data]# mount lab2:/var/www/html/data/ /var/www/html/data/
#Haproxy配置文件
[root@lab1 ~]# cat /etc/haproxy/haproxy.cfg #--------------------------------------------------------------------- # Global settings #--------------------------------------------------------------------- global #全局配置 log 127.0.0.1 local2 chroot /var/lib/haproxy pidfile /var/run/haproxy.pid maxconn 4000 user haproxy group haproxy daemon # turn on stats unix socket stats socket /var/lib/haproxy/stats #--------------------------------------------------------------------- # common defaults that all the 'listen' and 'backend' sections will # use if not designated in their block #--------------------------------------------------------------------- defaults #默认配置 mode http log global option httplog option dontlognull option http-server-close option forwardfor except 127.0.0.0/8 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 #--------------------------------------------------------------------- # main frontend which proxys to the backends #--------------------------------------------------------------------- frontend web *:80 #前端接收设置 acl url_static path_beg -i /data /static /images /javascript /stylesheets #定义静态内容前缀 acl url_static path_end -i .jpg .gif .png .css .js .html .ico #定义静态内容后缀 use_backend static if url_static default_backend app #--------------------------------------------------------------------- # static backend for serving up images, stylesheets and such #--------------------------------------------------------------------- backend static #后端静态服务器设置 balance roundrobin server static 172.16.21.102:80 check option forwardfor except 127.0.0.1/8 option originalto #--------------------------------------------------------------------- # round robin balancing between the various backends #--------------------------------------------------------------------- backend app #后端动态服务器设置 balance roundrobin #使用轮询的调度方式 cookie srv insert nocache #插入cookie,使其可以访问到后端的同一台动态服务器,防止登录信息丢失 server app1 172.16.21.103:80 check cookie app1 server app2 172.16.21.104:80 check cookie app2 option forwardfor except 127.0.0.1/8 #添加X-forwarded-for头部信息,向后端主机提供真实访问IP,需要在httpd配置文件中修改 option originalto listen admin_stat #状态页面设置 bind *:8080 stats enable stats uri /haproxy stats refresh 10s stats auth haadmin:haadmin stats admin if TRUE option forwardfor except 127.0.0.1/8 option originalto
启动Haproxy,访问论坛
发帖,图片上传测试
#帖子图片访问正常
#清除Cookie后访问成功
#Httpd配置调整
将日志格式中需要记录访问IP的%h更改为{X-Forwarded-For}i,以方便记录统计数据