Haproxy Proxy to build a highly available Web cluster

Source: Internet
Author: User
Tags syslog haproxy rsyslog

Haproxy Proxy to build a highly available Web cluster

Status code for HTTP protocol response:
200:ok
301: Redirect
404:not found
403:forbidden
501:internal Error

HAProxy:
1, it's working principle is proxy agent. After the client sends the request to Haproxy, Haproxy sends the request to the Web server for the user, the Web server responds to the Haproxy, and the page is sent to Haproxy. Haproxy then send the page to the client.
2, the topology and lvs-dr exactly the same. Because the LVS-DR configuration and haproxy have no impact, there is no need to clean up.
3, node4 as the scheduler
[email protected] ~]# Yum install-y haproxy
4. Modify the configuration file
[Email protected] ~]# vim/etc/haproxy/haproxy.cfg
Remove the configuration from main frontend which Proxys to the back of the Backends
Listen stats
Bind 0.0.0.0:1080 # Monitor the port number of the page
Stats Refresh 30s # page Auto Refresh time is 30 seconds
Stats uri/monitor # page URL
Stats Realm Hamanager
Stats Auth admin:admin # user name: password

Listen MyWeb 0.0.0.0:80
Cookie ServerID Rewrite
Balance Roundrobin # scheduling is RR
Server Web1 192.168.4.2:80 Cookie a1i1 check Inter 2 rise 5 #每2000ms检查一次服务器, 2 times success is good, 5 failures indicate failure
Server web2 192.168.4.3:80 Cookie A1i2 check Inter 2 rise 5
5. Start the service
[Email protected] ~]# systemctl start Haproxy

Log
1. Make Up # man 5 rsyslog.conf
Facility.priority is equivalent to a service. Priority
Facility can be these keywords: auth, authpriv, cron, daemon, Kern, LPR, mail, Mark, news, Security, syslog, user, UUCP and local0 to Local7
Local0 to LOCAL7 is a reserved interface for third-party applications to invoke.
Key words to use: Debug, Info,notice, warning, warn, err, Error,crit, Alert,emerg, panic
Debug is the least severe level, and panic is the most severe level. If the logging priority is info, a log is required for logs that are more severe than info.

Configuring Haproxy Logs
1. Configure this machine to accept logs sent over the network
[Email protected] ~]# vim/etc/rsyslog.conf
# provides UDP syslog reception
$ModLoad IMUDP
$UDPServerRun 514
# provides TCP syslog reception
$ModLoad imtcp
$InputTCPServerRun 514
[Email protected] ~]# systemctl restart Rsyslog
2. View Logs
[Email protected] ~]# tail-f/var/log/messages
You can see the log information by accessing the Haproxy scheduler.

VRRP: Virtual redundant routing protocol, IETF public standard
HSRP: Hot-Standby routing protocol, Cisco private

Build a highly available Web cluster
1, Node2 and NODE3 provide Web services. Because there is not too much user access, only one server can work, and the other one is just a backup copy of the role.
2. Installation Services
[email protected] ~]# Yum install-y keepalived
3. Modify the configuration file
[Email protected] ~]# vim/etc/keepalived/keepalived.conf
# vrrp_strict
Vrrp_instance Vi_1 {
State MASTER #辅助写BACKUP
Interface eth0
virtual_router_id Wuyi #虚拟路由器ID号
Priority #优先级
Advert_int 1 # Heartbeat message send interval
Authentication {# cluster member shared password
Auth_type PASS
Auth_pass 1111
}
virtual_ipaddress {
192.168.4.200 # VIP
}
}
Heartbeat: Heartbeat
[Email protected] ~]# systemctl start keepalived
4. View, verify
[[Email protected] ~]# IP address show eth0

Dual master configuration: Two hosts, two services, each host is a service master

Build a highly available, load-balanced Web cluster
1, new NODE5 virtual machine, as an additional LVS server. Although there are two schedulers, it is also the DR mode.
2. Configure the VIP on the lo of the Web server
3, adjust the Web server kernel parameters
4. Do not manually configure VIP for eth0 on the scheduler. Since the VIP is on the active scheduler, the active device is determined by keepalived. The existing scheduler VIP should be removed.
[Email protected] ~]# Ifdown eth0:0
[Email protected] ~]# mv/etc/sysconfig/network-scripts/ifcfg-eth0:0 ~
5, the Node4 on the Haproxy to stop
[Email protected] ~]# Systemctl stop Haproxy
6, the NODE4 on the rules of the LVS to clear out. Because the LVS rule will be specified by the keepalived configuration file.
[Email protected] ~]# ipvsadm-d-t 192.168.4.100:80
7, install the Ipvsadm on the NODE5
[email protected] ~]# Yum install-y ipvsadm
8, install keeaplived in NODE4/5
[email protected] ~]# Yum install-y keepalived
9, configure the keepalived on the NODE4
[Email protected] ~]# vim/etc/keepalived/keepalived.conf
Global_defs {
Notification_email {
[Email protected] # recipient
}
Notification_email_from [email protected] # sender
Smtp_server 127.0.0.1 # Mail server address
Smtp_connect_timeout 30
router_id Lvs_devel
Vrrp_skip_check_adv_addr
# vrrp_strict
Vrrp_garp_interval 0
Vrrp_gna_interval 0
}
Vrrp_instance Vi_1 {
State MASTER
Interface eth0
VIRTUAL_ROUTER_ID 51
Priority 150
Advert_int 1
Authentication {
Auth_type PASS
Auth_pass 1111
}
virtual_ipaddress {
192.168.4.100
}
}
Virtual_server 192.168.4.100 80 {
Delay_loop 6
Lb_algo RR
Lb_kind DR
Persistence_timeout 50
Protocol TCP

real_server 192.168.4.2 80 {    weight 1

Tcp_check {
Connect_timeout 3
Nb_get_retry 3
Delay_before_retry 3
}
}
Real_server 192.168.4.3 80 {
Weight 1
Tcp_check {
Connect_timeout 3
Nb_get_retry 3
Delay_before_retry 3
}
}
}
10. Start Service Verification
[Email protected] ~]# systemctl restart Keepalived.service

Haproxy Proxy to build a highly available 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.