初学者的haproxy实验

tech2022-09-22  74

文章目录

haproxy实验配置web1安装环境包创建用户解压包配置编译编写网页创建软连接启动服务查看接口web2和web1基本相同,差异内容如下 配置haproxy解压包编译修改配置文件修改如下:添加权限并创建软连接,启动服务编写脚本文件

haproxy实验

配置web1

安装环境包

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

配置

cd nginx-1.12.0/ ./configure --prefix=/usr/local/nginx --user=nginx --group=nginx

编译

make && make install

编写网页

cd /usr/local/nginx/html vim test.html <h1>this is C7-2T</h1>

创建软连接

ln -s /usr/local/nginx/sbin/nginx /usr/local/sbin/

启动服务

nginx

查看接口

netstat -ntap | grep nginx

web2和web1基本相同,差异内容如下

cd /usr/local/nginx/html vim test.html <h1>this is C7-2T</h1>

配置haproxy

yum -y install pcre-devel bzip2-devel gcc gcc-c++ make

解压包

tar zxvf haproxy-1.5.19.tar.gz

编译

cd haproxy-1.5.19/ make TARGET=linux26 make install mkdir /etc/haproxy

修改配置文件

cp examples/haproxy.cfg /etc/haproxy/ cd /etc/haproxy/

修改如下:

vim haproxy.cfg # this config needs haproxy-1.1.28 or haproxy-1.2.1 global log /dev/log local0 info log /dev/log local0 notice #log loghost local0 info maxconn 4096 #chroot /usr/share/haproxy uid 99 gid 99 daemon #debug #quiet defaults log global mode http option httplog option dontlognull retries 3 # redispatch ​ maxconn 2000 ​ contimeout 5000 ​ clitimeout 50000 ​ srvtimeout 50000 listen webcluster 0.0.0.0:80 option httpchk GET /test.html balance roundrobin server inst1 192.168.209.132:80 check inter 2000 fall 3 server inst2 192.168.209.133:80 check inter 2000 fall 3

添加权限并创建软连接,启动服务

cd cd haproxy-1.5.19/examples/ cp haproxy.init /etc/init.d/haproxy cd /etc/init.d/ chmod +x haproxy chkconfig --add /etc/init.d/haproxy ln -s /usr/local/sbin/haproxy /usr/sbin/haproxy service haproxy start

编写脚本文件

cd /etc/rsyslog.d/ vim 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
最新回复(0)