赞
踩
实验环境:
类型 | IP地址 | 系统 | 软件包 |
Haproxy调度器 | 192.168.179.148 | centos7 | haproxy-1.5.19.tar.gz |
Nginx服务器1 | 192.168.179.132 | centos7 | nginx-1.12.2.tar.gz |
Nginx服务器2 | 192.168.179.228 | centos7 | nginx-1.12.2.tar.gz |
客户
|
- //解压缩包
- tar zxvf nginx-1.12.2.tar.gz -C /opt
-
- //创建用户
- useradd -M -s /sbin/nologin nginx
-
- //安装环境依赖包
- yum install gcc gcc-c++ pcre pcre-devel zlib-devel -y
-
- //配置
- ./configure \
- --prefix=/usr/local/nginx \
- --user=nginx \
- --group=nginx \
- --with-http_stub_status_module
-
- //创建软连接,便于管理服务命令
- ln -s /usr/local/nginx/sbin/* /usr/local/sbin
-
- //便于service管理服务
- vim /etc/init.d/nginx
- #!/bin/bash
- # chkconfig: - 99 20
- # description: Nginx Service Control Script
- PROG="/usr/local/nginx/sbin/nginx"
- PIDF="/usr/local/nginx/logs/nginx.pid"
-
- case "$1" in
- start)
- $PROG;;
- stop)
- kill -s QUIT $(cat $PIDF);;
- restart)
- $0 stop
- $0 start;;
- reload)
- kill -s HUP $(cat $PIDF);;
- *)
- exit 1
- esac
- exit 0
-
- //添加执行权限
- chmod +x /etc/init.d/nginx
-
- //添加为系统服务
- chkconfig --add nginx
-
- //创建站点目录
- cd /usr/local/nginx/html
- vim test.html
-
- <h1>this is web1</h1>
- <h1>this is web2</h1>
-
-
- //启动服务
- service nginx start
- //验证服务
- netstat -ntap | grep nginx
- yum install pcre-devel pcre bzip2-devel gcc gcc-c++ make -y
-
- //解压缩包
- tar zxvf haproxy-1.5.19.tar.gz -C /opt/
-
- //安装配置
- make TARGET=linux26
- make install
-
-
- //创建工作目录
- mkdir /etc/haproxy
- cp examples/haproxy.cfg /etc/haproxy/
-
- //修改配置文件
- vim /etc/haproxy/haprox.cfg
-
- 注释 #chroot /usr/share/haproxy
- 注释 #redispatch
- 删除所有listen
- 添加
- listen webcluster 0.0.0.0:80
- option httpchk GET /test.html
- balance roundrobin
- server inst1 192.168.179.228:80 check inter 2000 fall 3
- server inst1 192.168.179.132:80 check inter 2000 fall 3
-
- //启动脚本
- cp /opt/haproxy-1.5.19/examples/haproxy.init /etc/init.d/haproxy
- chmod +x /etc/init.d/haproxy
- chkconfig --add /etc/init.d/haproxy
-
- ln -s /usr/local/sbin/haproxy /usr/sbin/
-
- //启动服务
- service haproxy start
- netstat -ntap | grep haproxy
-
- //访问代理服务器IP地址haproxy
- IP/test.html
- vim /etc/haproxy/haproxy.cfg
-
- global中更改
- log /dev/log local0 info
- log /dev/log local0 notice
-
- service haproxy restart
-
- touch /etc/rsyslog.d/haproxy.conf
-
- vim /etc/rsyslog.d/haproxy.conf
-
- 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
- &~
-
- //重启日志服务
- systemctl restart rsyslog.service
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。