您的位置:首页 > 运维架构 > Nginx

linux企业常用服务---haproxy+nginx搭建web高可用集群

2016-05-15 18:07 1081 查看
部署前准备:iptables和selinux没配置,关掉挂载系统镜像作为本地yum源,修改yum文件源码包准备 nginx.1.6.0.tar.gz haproxy-1.4.24.tar.gz实验环境描述:
两个nginx分别为192.168.100.110 and192.168.100.120
一个haproxy为192.168.100.160

1 、分别在110和120上搭建nginx
yum -y install pcre-devel zlib-devel ##安装依赖包
useradd -M -s /sbin/nologon nginx
tar zxvf nginx-1.6.0.tar.gz -C /usr/src/ ##解压并释放
cd /usr/src/nginx-1.6.0/
./configure --prefix=/usr/local/nginx --user=nginx --group=nginx &&make &&make install ##编译安装nginx
cd /usr/local/nginx/html/

echo "server 192.168.100.110" >test.html ##创建测试页面
/usr/local/nginx/sbin/nginx ##启动nginx
netstat -utpln |grep nginx
注意
120和110上设置一样,只是测试网页不同
echo "server 192.168.100.120" >test.html

访问测试http://192.168.100.110/test.htmlhttp://192.168.100.120/test.html

2、编译安装haproxy 160上做
yum -y install pcre-devel bzip2-devel
tar zxvf haproxy-1.4.24.tar.gz -C /usr/src
cd /usr/src/haproxy
make TARGET=generic ##安装时需要注意
make install



vi examples/haproxy.cfg




mkdir /etc/haproxy ##创建配置文件目录

cp examples/haproxy.cfg /etc/haproxy/ ##将ha的文件复制过来
cp /usr/src/haproxy-1.4.24/examples/haproxy.init /etc/init.d/haproxy ##创建自启动脚本
ln -s /usr/local/sbin/haproxy /usr/lib/haproxy

chmod +x /etc/init.d/haproxy ##加执行权限
/etc/init.d/haproxy start ##启动

访问测试:http://192.168.100.160

3、haproxy日志管理:
vi /etc/rsyslog.conf
local0.* /var/log/haproxy/ha-info.log
local1.* /var/log/haproxy/ha-notice.log
:wq
vi /etc/sysconfig/rsyslog
SYSLOGD_OPTIONS="-r -m 0 -c 2"
:wq
/etc/init.d/rsyslog restart
/etc/init.d/haproxy restart
tail -f /var/log/haproxy/ha-info.log

本文出自 “LP-linux” 博客,谢绝转载!
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: