赞
踩
常见的Web集群调度器
目前常见的Web集群调度器分为软件和硬件,软件通常使用开源的LVS、 Haproxy、 Nginx,硬件一般使用比较多的是F5,也有很多人使用国内的一些产品,如梭子鱼、绿盟等
LVS虽然在企业应用中抗负载能力很强,但存在不足
Haproxy是一款可提供高可用性、负载均衡、及基于TCP和HTTP应用的代理的软件
[root@nginx1 ~]# mount.cifs //192.168.23.1/ccc /mnt '//挂载宿主机文件夹'
[root@nginx1 mnt]# cd /mnt/LNMP
[root@nginx1 LNMP-C7]# tar zxvf nginx-1.12.2.tar.gz -C /opt '//解压NGINX源码包'
[root@nginx1 LNMP-C7]# cd /opt/nginx-1.12.2/
[root@nginx1 nginx-1.12.2]# ./configure --prefix=/usr/local/nginx --user=nginx --group=nginx '//configure 配置'
[root@nginx1 nginx-1.12.2]# make && make install '//编译安装'
[root@nginx1 nginx-1.12.2]# echo "this is erbao web" > /usr/local/nginx/html/test.html '//创建站点首页'
[root@nginx1 nginx-1.12.2]# ln -s /usr/local/nginx/sbin/nginx /usr/local/sbin/ '//创建nginx命令软连接'
[root@nginx1 nginx-1.12.2]# nginx -t '//检查语法'
nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful
[root@nginx1 nginx-1.12.2]# nginx '//开启nginx'
[root@nginx1 nginx-1.12.2]# systemctl stop firewalld.service '//关闭防火墙'
[root@nginx1 nginx-1.12.2]# setenforce 0
'//第二台节点采用相同方法设置,其中站点首页需要更改,内容为this is sanbao web'
使用源码编译的方式进行安装
关闭 Firewall防火墙
安装基础软件包
增加系统用户账号 nginx
编译安装 Nginx并启动
[root@haproxy ~]# mount.cifs //192.168.23.1/ccc /mnt [root@haproxy ~]# cd /mnt/ccc [root@haproxy ccc]# tar zxvf haproxy-1.5.19.tar.gz -C /opt [root@haproxy ccc]# cd /opt/haproxy-1.5.19 [root@haproxy haproxy-1.5.19]# make TARGET=linux26 [root@haproxy haproxy-1.5.19]# make install [root@haproxy haproxy-1.5.19]# mkdir /etc/haproxy [root@haproxy haproxy-1.5.19]# cp examples/haproxy.cfg /etc/haproxy/ [root@haproxy haproxy-1.5.19]# cd /etc/haproxy/ [root@haproxy haproxy]# vim haproxy.cfg # this config needs haproxy-1.1.28 or haproxy-1.2.1 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 webcluster 0.0.0.0:80 '//删除原本listen内容,添加一下内容' option httpchk GET /test.html '//监听检查服务器的index.html文件(节点服务器的主页)' balance roundrobin '//负载均衡调度算法使用轮询算法' server inst1 192.168.79.134:80 check inter 2000 fall 3 '//定义在线节点' server inst1 192.168.79.135:80 check inter 2000 fall 3 [root@haproxy haproxy]# cp /opt/haproxy-1.5.19/examples/haproxy.init /etc/init.d/haproxy '//复制创建启动脚本' [root@haproxy haproxy]# chmod +x /etc/init.d/haproxy '//添加启动脚本权限' [root@haproxy haproxy]# chkconfig --add /etc/init.d/haproxy '//为service添加启动脚本' [root@haproxy haproxy]# ln -s /usr/local/sbin/haproxy /usr/sbin/ '//创建命令软连接' [root@haproxy haproxy]# service haproxy start '//开启haproxy' Starting haproxy (via systemctl): [ 确定 ] [root@haproxy haproxy]# netstat -ntap | grep haproxy '//检查开启状态' tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 26964/haproxy
Haproxy的日志默认是输出到系统的 syslog中,在生产环境中一般单独定义出来
定义的方法步骤
# this config needs haproxy-1.1.28 or haproxy-1.2.1 global log /dev/log local0 info log /dev/log local1 notice ...省略内容 [root@haproxy haproxy]# service haproxy restart '//重启haproxy服务' Restarting haproxy (via systemctl): [ 确定 ] [root@haproxy haproxy]# touch /etc/rsyslog.d/haproxy.conf '//创建一个新haproxy配置文件' [root@haproxy 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@haproxy haproxy]# systemctl restart rsyslog.service '//重启日志服务'
'//未访问网页,查看/var/log'
[root@haproxy dev]# cd /var/log
[root@haproxy log]# ls
发现没有haproxy文件
'//查看网页之后,再次查看/var/log'
[root@haproxy log]# ls
已经生成haproxy文件了,可以进去查看
[root@haproxy log]# cd haproxy/
[root@haproxy haproxy]# ls
haproxy-info.log
[root@haproxy haproxy]# cat haproxy-info.log
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。