Nginx+Haproxy搭建高可用web集群

如图所示:
在这里插入图片描述
Nginx的详细安装
网页信息:
nginx01:aaa.benet.com
nginx02:bbb.benet.com
1.安装Nginx网站。(Nginx02同理)
[root@nginx01 ~]# yum -y install pcre-devel zlib-devel
[root@nginx01 ~]# useradd -M -s /sbin/nologin nginx
[root@nginx01 nginx-1.6.0]# ./configure --prefix=/usr/local/nginx --user=nginx --group=nginx --with-http_stub_status_module
[root@nginx01 nginx-1.6.0]# make && make install
[root@nginx01 nginx-1.6.0]# ln -s /usr/local/nginx/sbin/* /usr/local/sbin/
2.安装Haproxy。
1)安装Haproxy。
[root@haproxy haproxy-1.4.24]# make TARGET=linux26
[root@haproxy haproxy-1.4.24]# make install
2)优化命令。
[root@haproxy /]# mkdir /etc/haproxy
[root@haproxy /]# mkdir -p /usr/share/haproxy 服务运行的临时文件
[root@haproxy /]# ln -s /usr/local/sbin/haproxy /usr/sbin/haproxy
[root@haproxy /]# cp /usr/src/haproxy-1.4.24/examples/haproxy.cfg /etc/haproxy/
3)创建自启项。
[root@haproxy /]# cp /usr/src/haproxy-1.4.24/examples/haproxy.init /etc/init.d/haproxy
[root@haproxy /]# chmod +x /etc/init.d/haproxy
[root@haproxy /]# chkconfig --add /etc/init.d/haproxy
[root@haproxy /]# chkconfig --level 35 haproxy on
3.编辑主配置文件。(将自带的其他配置注销)
[root@haproxy /]# vim /etc/haproxy/haproxy.cfg
:27,80 s/^/#
27 listen nginx 192.168.200.30:80
28 option httpchk GET /index.html
29 balance roundrobin
30 server nginx01 192.168.200.10:80 check inter 2000 fall 3 weight 1
31 server nginx02 192.168.200.20:80 check inter 2000 fall 3 weight 1
4.配置防火墙策略。
[root@firewalld ~]# firewall-cmd --zone=external --add-rich-rule=" rule family=ipv4 destination address=192.168.100.40/32 forward-port port=80 protocol=tcp to-addr=192.168.200.30 " 将内网200.30映射到外网接口的100.40上,用于外网访问内网
[root@firewalld ~]# firewall-cmd --zone=external --add-service=http
5.客户端测试。
在这里插入图片描述在这里插入图片描述
主配置文件:(一下内容可以不更改)

global	                        	全局配置	
        log 127.0.0.1   local0		日志文件的输出定向请查看下面的日志配置
        log 127.0.0.1   local1 notice	
        #log loghost    local0 info	
        maxconn 4096				最大并发连接数
        chroot /usr/share/haproxy	将当前目录给改为/usr/share/haproxy,安全方面的配置
        uid 99						运行haproxy进程的用户id
        gid 99						运行haproxy进程的组id
        daemon						守护进程,运行在前台或者后台
        #debug
        #quiet
 
defaults
        log     global
        mode    http			所处理的类别,默认采用http模式,可配置成tcp做4层消息转发
        option  httplog			日志类别,采用httplog
        option  dontlognull		当serverid对应的服务器挂掉后,强制定向到其它健康的服务器
        retries 3	
        redispatch	
        maxconn 2000			最大并发连接数
        contimeout      5000	连接超时时间
        clitimeout      50000	客户端连接超时时间
        srvtimeout      50000	服务器端连接超时时间
发布了52 篇原创文章 · 获赞 4 · 访问量 1万+

猜你喜欢

转载自blog.csdn.net/HCY_2315/article/details/104395953