In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/01 Report--
The purpose of this article is to share with you how to configure keepalived dual-computer hot backup nginx. The editor thinks it is very practical, so share it with you as a reference and follow the editor to have a look.
Nginx is currently my most commonly used reverse proxy service. In order to better cope with emergencies, online environments generally use keepalived hot backup nginx or docker to run nginx clusters. Keepalived is a more traditional way. Although it is more convenient to run nginx clusters with docker, the traditional way always has its merits, and it is also good to learn more. In the future, I will also write how to run nginx clusters using docker.
Environmental preparation:
2 centos: 192.168.0.105 and 192.168.0.118, virtual IP (VIP) is 192.168.0.119
Configure keepavlived
Install keepalived on 105and 118, respectively
Yum install keepalived
Prepare for the heartbeat.
The configuration of keepalived is quite flexible, and you can execute the script command regularly for heartbeat check. For example, when we visit nginx and find that nginx is not accessible, we close keepalived and switch to uninterrupted service support from nginx.
Vi / etc/keepalived/keepalived.conf
#! / bin/bashcount=0for ((kryp0; k state BACKUP,priority 100-> priority 90) mcastcastsrckeeper IP 192.168.0.118-> mcast_src_ip 192.168.0.105. It's not easy to keep everything else the same.
! Configuration File for keepalivedvrrp_script chk_nginx {script "/ etc/keepalived/check_nginx.sh" interval 2 weight-5} vrrp_instance VI_1 {state BACKUP # Modification interface eth0 mcast_src_ip 192.168.0.105 # modified to Native IP virtual_router_id 51 priority 90 # Digital smaller advert_int 2 authentication {auth_type PASS auth_pass 1111} virtual_ipaddress {192.168.0.119} track_script {chk_nginx}}
Service keepalived start
Install Nginx
Check whether the dependent library of nginx is complete
Rpm-qa zlibrpm-qa zlib-develrpm-qa opensslrpm-qa openssl-develrpm-qa pcrerpm-qa pcre-develrpm-qa gcc
If not, install it.
Yum-y install gcc zlib zlib-devel openssl openssl-devel pcre-devel
Download and extract nginx
Mkdir nginxsrccd nginxsrc/
Wget http://nginx.org/download/nginx-1.13.9.tar.gztar zxvf nginx-1.13.9.tar.gzcd nginx-1.13.9/
. / configure-prefix=/usr/local/nginx-with-http_ssl_module-with-http_stub_status_module-with-http_realip_module
Installed in the / usr/local/nginx/sbin/nginx directory
Make&&make install
Leaving directory will be displayed after successful execution
Start
/ usr/local/nginx/sbin/nginx
Check
Ps aux | grep nginx
Boot up
Vi / etc/rc.local
Add a row
/ usr/local/nginx/sbin/nginx
Because port 80 on my machine is occupied by other applications, I modify the nginx.conf of 105and 118 to change port 80 to 81
Vi / usr/local/nginx/conf/nginx.conf
Add an ip to the index.html on personality 105and 119so that we can identify which ip index.html is opened.
Vi / usr/local/nginx/html/index.html
Nginx reloads configuration
/ usr/local/nginx/sbin/nginx-s reload
All right, let's have an interview.
Curl 192.168.0.119:81
The returned html is index.html on machine 118.
Now let's stop the nginx of 118.
/ usr/local/nginx/sbin/nginx-s stop
At this time, the heartbeat check corner of the keepalived on 118 found that the nginx could not be accessed, so it turned off the keepalived and then turned to the slave node.
Let's visit 119 again.
Curl 192.168.0.119:81
Restart nginx and keepalived on 118
The URL returned from the visit is index.html on 118,
Thank you for reading! This is the end of the article on "how to configure keepalived dual-computer hot backup nginx". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, you can share it for more people to see!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.