标签:执行 直接 user int cto 构建 dir The 安装
拓扑架构图主机 | 操作系统 | IP地址 | 软件包 |
---|---|---|---|
负载调度服务器: | CentOS 7.0 x86_64 | 192.168.100.25 | haproxy-1.5.19.tar.gz |
web1节点服务器: | CentOS 7.0 x86_64 | 192.168.100.26 | nginx-1.12.0.tar.gz |
web2节点服务器: | CentOS 7.0 x86_64 | 192.168.100.27 | nginx-1.12.0.tar.gz |
Win 7 客户端: | Windows 7 | 192.168.100.30 | 无 |
yum install -y pcre-devel zlib-devel gcc gcc-c++ make
useradd -M -s /sbin/nologin nginx
tar zxvf nginx-1.12.0.tar.gz -C /opt/
cd /opt/nginx-1.12.0/
./configure \
--prefix=/usr/local/nginx \ #安装目录
--user=nginx \ #用户
--group=nginx #用户组
make && make install
echo "<h1>this is nginx2 web</h1>" > /usr/local/nginx/html/index.html
ln -s /usr/local/nginx/sbin/nginx /usr/local/sbin/
nginx -t
nginx
systemctl stop firewalld.service
setenforce 0
yum install -y pcre-devel zlib-devel gcc gcc-c++ make
useradd -M -s /sbin/nologin nginx
tar zxvf nginx-1.12.0.tar.gz -C /opt/
cd /opt/nginx-1.12.0/
./configure \
--prefix=/usr/local/nginx \ #安装目录
--user=nginx \ #用户
--group=nginx #用户组
make && make install
echo "<h1>this is nginx1 web</h1>" > /usr/local/nginx/html/index.html
ln -s /usr/local/nginx/sbin/nginx /usr/local/sbin/
nginx -t
nginx
systemctl stop firewalld.service
setenforce 0
yum install -y pcre-devel bzip2-devel gcc gcc-c++ make
tar zxvf /linux-tools/haproxy-1.5.19.tar.gz -C /opt/
cd /opt/haproxy-1.5.19/
make TARGET=linux26
make install
mkdir /etc/haproxy
cp examples/haproxy.cfg /etc/haproxy/
vim /etc/haproxy/haproxy.cfg
#1.删除以下2行语句
chroot /usr/share/haproxy
redispatch#2.删除所有listen项目
#3.新添加以下数据
listen webcluster 0.0.0.0:80
option httpchk GET /index.html
balance roundrobin
server inst1 192.168.100.26:80 check inter 2000 fall 3
server inst2 192.168.100.27: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/haproxy
service haproxy start
systemctl stop firewalld.service
setenforce 0
win7客户端:http://192.168.100.25/
说明:haproxy默认是不会直接输出文件日志,所以我们要借助Linux的rsyslog来让haproxy输出日志
vim /etc/haproxy/haproxy.cfg
#将信息提示与告警进行分离
log /dev/log local0 info
log /dev/log local0 notice
service haproxy restart
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
cat /var/log/haproxy/haproxy-info.log
至此,Haproxy搭建Web群集已经完成了。
标签:执行 直接 user int cto 构建 dir The 安装
原文地址:http://blog.51cto.com/10316297/2133770