Haproxy Building a Web cluster

Source: Internet
Author: User
Tags system log node server haproxy rsyslog

Topology architecture diagram

System environment:
Host Operating System IP Address Package
Load Dispatch server: CentOS 7.0 x86_64 192.168.100.25 Haproxy-1.5.19.tar.gz
WEB1 node Server: CentOS 7.0 x86_64 192.168.100.26 Nginx-1.12.0.tar.gz
WEB2 node Server: CentOS 7.0 x86_64 192.168.100.27 Nginx-1.12.0.tar.gz
Win 7 Client: Windows 7 192.168.100.30 No
Start deploying one, Web1 node server 1. Install the Environment pack
2. New Admin user Nginx
useradd -M -s /sbin/nologin nginx
3. Add compressed Nginx Package
tar zxvf nginx-1.12.0.tar.gz -C /opt/
4. Switch to Nginx directory
cd /opt/nginx-1.12.0/
5. Configuration

./configure \
--prefix=/usr/local/nginx \ #安装目录
--user=nginx \ #用户
--group=nginx #用户组

6. Compiling and installing
make && make install
7. Create a Web site home index.html
echo "
8. Establish soft links for easy management of Nginx
ln -s /usr/local/nginx/sbin/nginx /usr/local/sbin/
9. Check Nginx Configuration
nginx -t

10. Start the service
nginx
Shutting down firewalls and SELinux
systemctl stop firewalld.service setenforce 0
Test

II. web2 node server 1. Install the Environment pack
2. New User Nginx
useradd -M -s /sbin/nologin nginx
3. Add compressed Nginx Package
tar zxvf nginx-1.12.0.tar.gz -C /opt/
4. Switch to Nginx directory
cd /opt/nginx-1.12.0/
5. Configuration

./configure \
--prefix=/usr/local/nginx \ #安装目录
--user=nginx \ #用户
--group=nginx #用户组

6. Compiling and installing
make && make install
7. Create a Web site home index.html
echo "
8. Establish soft links for easy management of Nginx
ln -s /usr/local/nginx/sbin/nginx /usr/local/sbin/
9. Check Nginx Configuration
nginx -t

10. Start the service
nginx
Shutting down firewalls and SELinux
systemctl stop firewalld.service setenforce 0
Test

Third, Haproxy server 1. Install Environment pack
yum install -y pcre-devel bzip2-devel gcc gcc-c++ make
2. Unzip the Haproxy
tar zxvf /linux-tools/haproxy-1.5.19.tar.gz -C /opt/
3. Switch to the Haproxy directory
cd /opt/haproxy-1.5.19/
4. Compiling and installing
make TARGET=linux26make install
5. Create the Haproxy profile directory
mkdir /etc/haproxy
6. Copy the template configuration file to the Haproxy directory
cp examples/haproxy.cfg /etc/haproxy/     
7. Edit Haproxy. CFG configuration file
vim /etc/haproxy/haproxy.cfg

#1. Delete the following 2 lines of statements
Chroot/usr/share/haproxy
Redispatch

#2. Delete all Listen items
#3. New Add the following data
Listen Webcluster 0.0.0.0:80
Option Httpchk get/index.html
Balance Roundrobin
Server Inst1 192.168.100.26:80 check Inter fall 3
Server Inst2 192.168.100.27:80 check Inter fall 3

8. Create a startup script Haproxy
cp /opt/haproxy-1.5.19/examples/haproxy.init /etc/init.d/haproxy
9. Assign executable permissions for Haproxy
chmod +x /etc/init.d/haproxy
10. Join the system service
chkconfig --add /etc/init.d/haproxyln -s /usr/local/sbin/haproxy /usr/sbin/haproxy
11. Start Haproxy
service haproxy start
12. Turn off the firewall and SELinux
systemctl stop firewalld.service setenforce 0
13. Test:

Win7 Client: http://192.168.100.25/

Iv. Add Log function

Note: Haproxy default is not to output the file log directly, so we want to use Linux rsyslog to let haproxy output log

1. Edit Haproxy.cfg
vim /etc/haproxy/haproxy.cfg

#将信息提示与告警进行分离
Log/dev/log local0 Info
Log/dev/log local0 Notice

2. Restart Haproxy
service haproxy restart
3. New configuration format
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
&~

4. Restart the System Log service
systemctl restart rsyslog.service
5. After the client accesses, the record is viewed in the log directory of the dispatch server
cat /var/log/haproxy/haproxy-info.log

At this point, the Haproxy build Web cluster is complete.

Haproxy Building a Web cluster

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.