In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-15 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)05/31 Report--
Most people do not understand the knowledge points of this article "how to achieve dual-computer hot standby in Nginx+Keepalived", so the editor summarizes the following content, detailed content, clear steps, and has a certain reference value. I hope you can get something after reading this article. Let's take a look at this "Nginx+Keepalived how to achieve dual-computer hot backup" article.
I. keepalived
Keepalived is the service software that ensures the high availability of the cluster. The high priority node in the network is master, which is responsible for responding to the arp packet of vip, telling other hosts in the network about the address mapping between vip and mac, and sending vrrp advertisements to the network in the form of multicast to tell them their priority. The backup node is only responsible for processing the multicast packets sent by the master. When it is found that the priority of the master is not as high as its own, or when it does not receive a vrrp notification from the master, the backup switches itself to the master state.
two。 Environment building
Environment: qemu-kvm, client debian (9.4.0)
Virtual Machine qemu-kvm installation: introduction to Virtualization Technology qemu-kvm
1. Create two virtual machines using temporary snapshots, both of which need to perform the following operations
Faramita2016@linux-l9e6:~ > qemu-kvm-cpu host-m 512-hda vdisk.img-net nic-net bridge,br=br0-snapshot-nographic
two。 Set virtual machine static ip
Root@debian:~# cat / etc/network/interfaces# the primary network interfaceallow-hotplug ens3#iface ens3 inet dhcpiface ens3 inet staticaddress 10.0.0.3 / / set the ipnetmask 255.0.0.0gateway 10.0.0.1hwaddress ether 52 mac address 5400 mac address
3. Activate the network card ip
Root@debian:~# ip addr del 10.0.0.8 dev ens3 8 dev ens3 / / Delete the original client iproot@debian:~# ifdown ens3root@debian:~# ifup ens3
4. Install nginx, keepalived
Root@debian:~# apt-get install-y nginx keepalived
5. Modify the / var/www/html/index.nginx-debian.html file to add the current virtual machine ip to mark the actual response server
Root@debian:~# vi / var/www/html/index.nginx-debian.html... Welcome to nginx! 10.0.0.3.
three。 Software configuration
Primary node virtual machine (10.0.0.3), standby node virtual machine (10.0.0.4), virtual ip (10.0.0.100)
1. On the master node virtual machine, edit the / etc/keepalived/keepalived.conf file
Root@debian:~# cat / etc/keepalived/keepalived.conf global_defs {router_id ri_1 / / identifies the current keepalived node} vrrp_script chk_nginx {script "/ root/chk_nginx.sh" / / defines the monitoring script interval 2 / / the time between accidents during the execution of the monitoring script} vrrp_instance vi_1 {state master / / sets the node to be the primary node The initial state of the node interface ens3 / / sets the group name of the network interface virtual_router_id 50 / / vrrp bound to the virtual ip, indicating that the node belongs to the same group priority / / node priority, and the primary node should be higher than the standby node advert_int 1 / / Multicast message sending interval # nopreempt / / forbids preemption service, which is valid only for the standby node. The primary node carries out preemption according to priority priority. Not controlled by nopreempty authentication {auth_type pass / / set authentication method auth_pass 123456 / / password} virtual_ipaddress {10.0.0.100lap24 / / set vip} track_script {/ / call monitoring script chk_nginx}}
two。 On the standby node virtual machine, edit the / etc/keepalived/keepalived.conf file, which is the same as the primary node except for the following
State backup / / sets the node as the primary node, and the initial state of the node priority 10 / / node priority
3. Execute on all nodes, create monitoring scripts, edit / root/chk_nginx.sh files
Root@debian:~# vi / root/chk_nginx.sh #! / bin/basha= `ps-c nginx-- no-header | wc-l`if [$a-eq 0] then / etc/init.d/keepalived stopfi
four。 Verification service
1. Master node virtual machine, start nginx and keepalived services
Root@debian:~# / etc/init.d/nginx startroot@debian:~# / etc/init.d/keepalived start
Execute the ip a command, and the primary node network card ens3 is bound to vip (10.0.0.100)
two。 On the standby node virtual machine, start the nginx and keepalived services
Root@debian:~# / etc/init.d/nginx startroot@debian:~# / etc/init.d/keepalived start
Execute the ip a command, the standby node network card ens3 is not bound to vip (10.0.0.100)
3. Host browser accesses http://10.0.0.100
A page of 10.0.0.3 appears, indicating that the keepalived service is in effect and the vip is bound to the master node.
4. At the master node, shut down the nginx service and simulate downtime
Root@debian:~# / etc/init.d/nginx stop
Execute the ip a command, and the primary node network card ens3 is not bound to vip (10.0.0.100)
5. In the standby node virtual machine, query ip
Execute the ip a command, and the standby node network card ens3 is bound to vip (10.0.0.100)
6. Host browser accesses http://10.0.0.100
A page of 10.0.0.4 appears, indicating that the keepalived service is in effect and the vip is bound to the standby node.
The above is about the content of this article on "how to achieve dual-computer hot backup in Nginx+Keepalived". I believe we all have a certain understanding. I hope the content shared by the editor will be helpful to you. If you want to know more about the relevant knowledge, please follow the industry information channel.
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.