标签:use lan timeout 启动脚本 url nod Fix etc cli
案例环境
实验步骤如下:
编辑安装nginx服务器
安装依赖包下载nginx-01服务器
[root@node-1 ~]# yum -y install gcc pcre-devel zlib-devel
[root@node-1 ~]# wget https://nginx.org/download/nginx-1.6.3.tar.gz
[root@node-1 ~]# tar zxvf nginx-1.6.3.tar.gz
[root@node-1 ~]# cd nginx-1.6.3/
[root@node-1 nginx-1.6.3]# ./configure --prefix=/usr/local/nginx
[root@node-1 nginx-1.6.3]# make && make install
[root@node-1 nginx-1.6.3]# cd /usr/local/nginx/html/
建立测试页面
[root@node-1 html]# echo "192.168.150.129" >> index.html
启动nginx
[root@node-1 html]# /usr/local/nginx/sbin/nginx
建立防火墙机制
[root@node-1 html]# iptables -I INPUT -p tcp --dport 80 -j ACCEPT
搭建nginx-02服务器
[root@node2 ~]# yum -y install gcc pcre-devel zlib-devel
[root@node2 ~]# wget https://nginx.org/download/nginx-1.6.3.tar.gz
[root@node2 ~]# tar zxvf nginx-1.6.3.tar.gz
[root@node2 ~]# cd nginx-1.6.3/
[root@node2 nginx-1.6.3]# ./configure --prefix=/usr/local/nginx
[root@node2 nginx-1.6.3]# make && make install
[root@node2 nginx-1.6.3]# cd /usr/local/nginx/html/
建立测试页面
[root@node2 html]# echo "192.168.150.133" >> index.html
启动nginx
[root@node2 html]# /usr/local/nginx/sbin/nginx
建立防火墙机制
[root@node2 html]# iptables -I INPUT -p tcp --dport 80 -j ACCEPT
安装完成后,在客户端访问nginx进行测试,如下图所示:
[root@node-3 haproxy-1.4.27]# cat /etc/haproxy/haproxy.cfg
global
log 127.0.0.1 local2
chroot /var/lib/haproxy
pidfile /var/run/haproxy.pid
maxconn 4000
user haproxy
group haproxy
daemon
stats socket /var/lib/haproxy/stats
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
frontend main *:80
acl url_static path_beg -i /static /images /javascript /stylesheets
acl url_static path_end -i .jpg .gif .png .css .js
default_backend app
backend app
balance roundrobin
server app1 192.168.150.129:80 check
server app2 192.168.150.133:80 check
配置文件因版本而已 请不要复制 参数基本一样
[root@node-3 haproxy-1.4.27]# cp examples/haproxy.init /etc/init.d/haproxy
[root@node-3 haproxy-1.4.27]# ln -s /usr/local/sbin/haproxy /usr/sbin/haproxy
[root@node-3 haproxy-1.4.27]# chmod +x /etc/init.d/haproxy
[root@node-3 haproxy-1.4.27]#systemctl start haproxy
(2)测试高可用
现在将nginx1服务停用,在客户端访问代理服务器,浏览器会显示nginx2网页内容,不会影响集群的使用,满足了集群的高可用性
标签:use lan timeout 启动脚本 url nod Fix etc cli
原文地址:https://blog.51cto.com/xia1314520ting/2406983