Build a Web cluster using Haproxy
Experimental Introduction: Haproxy is a popular cluster scheduling tool, compared to similar cluster scheduling tools such as LVs and Nginx, LVS performance is the best, but the building is relatively complex, nginx upstream module support cluster function, However, the health function of the cluster node is not strong, the performance is not haproxy good, so this time we use Haproxy to build the cluster.
Case Environment
Host |
Operating System |
IP Address |
main software |
Haproxy Server |
Centos 7 |
192.169.100.222 |
Haproxy-1.5.19.tar.gz |
Nginx server 1 |
Centos 7 |
192.168.100.221 |
Nginx-1.15.0.tar.gz |
Nginx server 2 |
Centos 7 |
192.168.100.220 |
Nginx-1.15.0.tar.gz |
Client |
Win7 |
192.168.100.100 |
IE browser |
1. First compile and install two Nginx server as node (real) server. First install the required Toolkit and development package for the compilation.
yum install -y pcre-devel \ #pcre语言开发包zlib-devel \ #压缩模块开发包gcc \ #c语言包gcc-c++ \ #c++语言包make #make工具包
2, Nginx service program by default is run as nobody, add users and groups running Nginx, do not establish the host folder, and also prohibit logging into the shell environment.
useradd -M -s /sbin/nologin nginx #-M 不建立家目录 -s 指定shell环境
3, unzip the nginx-1.15.0.tar.gz to the/OPT directory, easy to compile and install
tar zxvf nginx-1.15.0.tar.gz -C /opt/
4. Switch to the/opt/nginx-1.15.0 directory for configuration
cd /opt/nginx-1.15.0./configure \ #指定配置程序--prefix=/usr/local/nginx \ #指定安装路径--user=nginx \ #指定运行用户--group=nginx #指定运行组
5, to compile and install
make && make install
6, after installation, to the default home storage directory, set up a test page
cd /usr/local/nginx/htmlecho "this is accp web" > test.html
7, the Nginx Start command to establish a soft link to the/usr/local/sbin, directory.
ln -s /usr/local/nginx/sbin/nginx /usr/local/sbin/
8. Start the Nginx and see if the 80 port of the system is turned on.
nginxnetstat -ntap | grep nginx
9, in order to facilitate the experiment, the URL is not configured domain name, directly with IP access, in the client Access http://192.168.100.220/test.html test, as shown in.
10, build another Nginx server, the same steps, the difference is to establish a test page.
cd /usr/local/nginx/htmlecho "this is benet web" > test.html
11. Test the client Access http://192.168.100.221/test.html as shown in
12. Compile and install Haproxy in the dispatch server, install the required development kits and kits with the Yum repository
yum install -y pcre-devel bzip2-devel \ #安装bzip2压缩模块gcc gcc-c++ make
13. Unzip the haproxy-1.5.19 into the/opt directory
tar zxvf haproxy-1.5.19.tar.gz -C /opt/
14, to the haproxy-1.5.19 directory, to compile and install
cd haproxy-1.5.19/make TARGET=linux26 #指定为64位系统make install
15, establish the Haproxy configuration file
16, configure the Haproxy configuration file, where globle is the global configuration, defaults is the default setting, listen for the application component configuration, delete the following statement.
chroot /usr/share/haproxy #更换haproxy根目录redispatch #强制发送请求到已经down掉的服务器
17. Remove all listen items and replace them with the following statements, and then save the exit.
listen webcluster 0.0.0.0:80 option httpchk GET /test.html balance roundrobin server inst1 192.168.100.221:80 check inter 2000 fall 3 server inst2 192.168.100.222:80 check inter 2000 fall 3
18. Copy the Haproxy Boot command to the system startup directory and add the Execute permission to join the system administration.
cp /opt/haproxy-1.5.19/examples/haproxy.init /etc/init.d/haproxychmod +x haproxychkconfig --add /etc/init.d/haproxyln -s /usr/local/sbin/haproxy /usr/sbin/haproxy
19. Open Haproxy Service
service haproxy start
20, test the Web cluster, open http://192.168.100.222/test.html in the client browser, access two times
Build a Web cluster using Haproxy