赞
踩
[root@web1 ~]# yum install -y \ pcre-devel \ zlib-devel \ gcc \ gcc-c++ \ make [root@web1 ~]# useradd -M -s /sbin/nologin nginx [root@web1 ~]# tar zxvf nginx-1.12.0.tar.gz '解压NGINX源码包' [root@web1 ~]# cd nginx-1.12.0/ [root@web1 nginx-1.12.2]# ./configure \ 'configure 配置' --prefix=/usr/local/nginx \ --user=nginx \ --group=nginx [root@web1 nginx-1.12.2]# make && make install '编译安装' [root@web1 nginx-1.12.2]# cd /usr/local/nginx/html [root@web1 html]# echo "this is kevin web" > test.html '创建站点首页' [root@web1 html]# ln -s /usr/local/nginx/sbin/nginx /usr/sbin '创建nginx命令软连接' [root@web1 html]# nginx -t [root@web1 html]# nginx '开启nginx' [root@web1 html]# netstat -ntap |grep nginx '第二台节点采用相同方法设置,其中站点首页需要更改,内容为this is benet web'
[root@localhost ~]# yum install -y \ pcre-devel \ bzip2-devel \ gcc \ gcc-c++ \ make [root@localhost ~]# tar zxvf haproxy-1.5.19.tar.gz [root@localhost ~]# cd haproxy-1.5.19/ [root@localhost haproxy-1.5.19]# make TARGET=linux26 [root@localhost haproxy-1.5.19]# make install [root@localhost haproxy-1.5.19]# mkdir /etc/haproxy [root@localhost haproxy-1.5.19]# cp examples/haproxy.cfg /etc/haproxy/ [root@localhost haproxy-1.5.19]# cd /etc/haproxy [root@localhost haproxy]# vim haproxy.cfg global log 127.0.0.1 local0 log 127.0.0.1 local1 notice #log loghost local0 info maxconn 4096 # chroot /usr/share/haproxy '固有目录,可注释掉' uid 99 gid 99 daemon #debug #quiet defaults log global mode http option httplog option dontlognull retries 3 # redispatch '注释' maxconn 2000 contimeout 5000 clitimeout 50000 srvtimeout 50000 '删除原本listen内容,添加以下内容' listen webcluster 0.0.0.0:80 option httpchk GET /test.html '监听检查服务器的index.html文件(节点服务器的主页)' balance roundrobin '负载均衡调度算法使用轮询算法' server inst1 20.0.0.52:80 check inter 2000 fall 3 '定义在线节点' server inst2 20.0.0.47:80 check inter 2000 fall 3 [root@localhost haproxy]# cp /opt/haproxy-1.5.19/examples/haproxy.init /etc/init.d/haproxy '复制创建启动脚本' [root@localhost haproxy]# cd /etc/init.d/ [root@localhost init.d]# chmod +x haproxy '添加启动脚本权限' [root@localhost init.d]# chkconfig --add /etc/init.d/haproxy '为service添加启动脚本' [root@localhost init.d]# ln -s /usr/local/sbin/haproxy /usr/sbin/haproxy '创建命令软连接' [root@localhost init.d]# service haproxy start [root@localhost init.d]# iptables -F [root@localhost init.d]# setenforce 0
测试Haproxy集群
[root@localhost haproxy]# vim /etc/haproxy/haproxy.cfg '编辑haproxy配置文件'
'在global下,将127.0.0.1修改为/dev/log'
log /dev/log local0 info
log /dev/log local1 notice
[root@localhost haproxy]# service haproxy restart '重启haproxy服务'
[root@localhost haproxy]# touch /etc/rsyslog.d/haproxy.conf '创建一个新haproxy配置文件'
[root@localhost haproxy]# vim /etc/rsyslog.d/haproxy.conf '编写haproxy配置文件脚本'
if ($programname == 'haproxy' and $syslogseverity-text == 'info')
then -/var/log/haproxy/haproxy-info.log
&~
if ($programname == 'haproxy' and $syslogseverity-text == 'notice')
then -/var/log/haproxy/haproxy-notice.log
&~
[root@localhost haproxy]# systemctl restart rsyslog.service '重启日志服务'
'未访问网页,查看/var/log'
[root@haproxy dev]# cd /var/log
[root@haproxy log]# ls
'发现没有haproxy文件生成'
'查看网页之后,再次查看/var/log'
'发现已经生成haproxy文件了,可以进去查看'
[root@localhost haproxy]# cd /var/log/haproxy/
[root@localhost haproxy]# ls
haproxy-info.log haproxy-notice.log
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。