Os voy a mostrara como instalar un nginx con keepalived para que tengamos un proxy inverso en alta disponibilidad.
Nginx es un sofware usado como proxy inverso, cache de HTTP, y balanceador de carga. Este ultimo, es el que nos interesa pero solo esta disponible en la version de pago.
Como no tenemos presupuesto para la licencia de pago de nginx, voy a hacerlo con keepalived, que es un software de enrutamiento escrito en C, que lo que hace es por medio de una ip flotante hace un equilibrio de carga que facilita una alta disponibilidad. Solo esta disponible para sistemas linux. os dejo un enlace muy interesante.
En este caso, vamos a usar 2 servidores con una ip y una ip flotante que hará de balanceo. Todo esto sera sobre un Centos7/RedHat7:
Nodo 1
Nombre: servidor1
ip: 192.168.1.11
Nodo 2
Nombre: servidor2
ip: 192.168.1.12
IP flotante: 192.168.1.10
Bien lo primero, es dividir la instalación en 2.
servidor1
Vamos a instalar nuestro nginx
[root@servidor01]# yum install -y nginx Loaded plugins: product-id, search-disabled-repos, subscription-manager Resolving Dependencies --> Running transaction check ---> Package nginx.x86_64 1:1.16.1-1.el7 will be installed --> Processing Dependency: nginx-all-modules = 1:1.16.1-1.el7 for package: 1:nginx-1.16.1-1.el7.x86_64 --> Processing Dependency: nginx-filesystem = 1:1.16.1-1.el7 for package: 1:nginx-1.16.1-1.el7.x86_64 --> Processing Dependency: nginx-filesystem for package: 1:nginx-1.16.1-1.el7.x86_64 --> Processing Dependency: redhat-indexhtml for package: 1:nginx-1.16.1-1.el7.x86_64 --> Processing Dependency: libprofiler.so.0()(64bit) for package: 1:nginx-1.16.1-1.el7.x86_64 --> Running transaction check ---> Package gperftools-libs.x86_64 0:2.6.1-1.el7 will be installed ---> Package nginx-all-modules.noarch 1:1.16.1-1.el7 will be installed --> Processing Dependency: nginx-mod-http-image-filter = 1:1.16.1-1.el7 for package: 1:nginx-all-modules-1.16.1-1.el7.noarch --> Processing Dependency: nginx-mod-http-perl = 1:1.16.1-1.el7 for package: 1:nginx-all-modules-1.16.1-1.el7.noarch --> Processing Dependency: nginx-mod-http-xslt-filter = 1:1.16.1-1.el7 for package: 1:nginx-all-modules-1.16.1-1.el7.noarch --> Processing Dependency: nginx-mod-mail = 1:1.16.1-1.el7 for package: 1:nginx-all-modules-1.16.1-1.el7.noarch --> Processing Dependency: nginx-mod-stream = 1:1.16.1-1.el7 for package: 1:nginx-all-modules-1.16.1-1.el7.noarch ---> Package nginx-filesystem.noarch 1:1.16.1-1.el7 will be installed ---> Package redhat-indexhtml.noarch 0:7-13.el7 will be installed --> Running transaction check ---> Package nginx-mod-http-image-filter.x86_64 1:1.16.1-1.el7 will be installed --> Processing Dependency: gd for package: 1:nginx-mod-http-image-filter-1.16.1-1.el7.x86_64 --> Processing Dependency: libgd.so.2()(64bit) for package: 1:nginx-mod-http-image-filter-1.16.1-1.el7.x86_64 ---> Package nginx-mod-http-perl.x86_64 1:1.16.1-1.el7 will be installed ---> Package nginx-mod-http-xslt-filter.x86_64 1:1.16.1-1.el7 will be installed ---> Package nginx-mod-mail.x86_64 1:1.16.1-1.el7 will be installed ---> Package nginx-mod-stream.x86_64 1:1.16.1-1.el7 will be installed --> Running transaction check ---> Package gd.x86_64 0:2.0.35-26.el7 will be installed --> Processing Dependency: libXpm.so.4()(64bit) for package: gd-2.0.35-26.el7.x86_64 --> Running transaction check ---> Package libXpm.x86_64 0:3.5.12-1.el7 will be installed --> Finished Dependency Resolution Dependencies Resolved ======================================================================================================================================================================================================================================= Package Arch Version Repository Size ======================================================================================================================================================================================================================================= Installing: nginx x86_64 1:1.16.1-1.el7 epel 562 k Installing for dependencies: gd x86_64 2.0.35-26.el7 rhel-7-server-rpms 146 k gperftools-libs x86_64 2.6.1-1.el7 rhel-7-server-rpms 272 k libXpm x86_64 3.5.12-1.el7 rhel-7-server-rpms 56 k nginx-all-modules noarch 1:1.16.1-1.el7 epel 19 k nginx-filesystem noarch 1:1.16.1-1.el7 epel 21 k nginx-mod-http-image-filter x86_64 1:1.16.1-1.el7 epel 30 k nginx-mod-http-perl x86_64 1:1.16.1-1.el7 epel 39 k nginx-mod-http-xslt-filter x86_64 1:1.16.1-1.el7 epel 29 k nginx-mod-mail x86_64 1:1.16.1-1.el7 epel 57 k nginx-mod-stream x86_64 1:1.16.1-1.el7 epel 84 k redhat-indexhtml noarch 7-13.el7 rhel-7-server-rpms 270 k Transaction Summary ======================================================================================================================================================================================================================================= Install 1 Package (+11 Dependent packages) Total download size: 1.5 M Installed size: 4.5 M Downloading packages: (1/12): gd-2.0.35-26.el7.x86_64.rpm | 146 kB 00:00:00 (2/12): gperftools-libs-2.6.1-1.el7.x86_64.rpm | 272 kB 00:00:00 (3/12): libXpm-3.5.12-1.el7.x86_64.rpm | 56 kB 00:00:00 (4/12): nginx-all-modules-1.16.1-1.el7.noarch.rpm | 19 kB 00:00:00 (5/12): nginx-1.16.1-1.el7.x86_64.rpm | 562 kB 00:00:00 (6/12): nginx-mod-http-image-filter-1.16.1-1.el7.x86_64.rpm | 30 kB 00:00:00 (7/12): nginx-filesystem-1.16.1-1.el7.noarch.rpm | 21 kB 00:00:00 (8/12): nginx-mod-http-xslt-filter-1.16.1-1.el7.x86_64.rpm | 29 kB 00:00:00 (9/12): nginx-mod-http-perl-1.16.1-1.el7.x86_64.rpm | 39 kB 00:00:00 (10/12): nginx-mod-stream-1.16.1-1.el7.x86_64.rpm | 84 kB 00:00:00 (11/12): nginx-mod-mail-1.16.1-1.el7.x86_64.rpm | 57 kB 00:00:00 (12/12): redhat-indexhtml-7-13.el7.noarch.rpm | 270 kB 00:00:00 --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- Total 917 kB/s | 1.5 MB 00:00:01 Running transaction check Running transaction test Transaction test succeeded Running transaction Installing : redhat-indexhtml-7-13.el7.noarch 1/12 Installing : gperftools-libs-2.6.1-1.el7.x86_64 2/12 Installing : 1:nginx-filesystem-1.16.1-1.el7.noarch 3/12 Installing : libXpm-3.5.12-1.el7.x86_64 4/12 Installing : gd-2.0.35-26.el7.x86_64 5/12 Installing : 1:nginx-mod-stream-1.16.1-1.el7.x86_64 6/12 Installing : 1:nginx-mod-http-perl-1.16.1-1.el7.x86_64 7/12 Installing : 1:nginx-mod-mail-1.16.1-1.el7.x86_64 8/12 Installing : 1:nginx-mod-http-xslt-filter-1.16.1-1.el7.x86_64 9/12 Installing : 1:nginx-1.16.1-1.el7.x86_64 10/12 Installing : 1:nginx-mod-http-image-filter-1.16.1-1.el7.x86_64 11/12 Installing : 1:nginx-all-modules-1.16.1-1.el7.noarch 12/12 Verifying : libXpm-3.5.12-1.el7.x86_64 1/12 Verifying : 1:nginx-mod-stream-1.16.1-1.el7.x86_64 2/12 Verifying : 1:nginx-filesystem-1.16.1-1.el7.noarch 3/12 Verifying : gperftools-libs-2.6.1-1.el7.x86_64 4/12 Verifying : 1:nginx-mod-http-perl-1.16.1-1.el7.x86_64 5/12 Verifying : 1:nginx-1.16.1-1.el7.x86_64 6/12 Verifying : 1:nginx-mod-mail-1.16.1-1.el7.x86_64 7/12 Verifying : 1:nginx-all-modules-1.16.1-1.el7.noarch 8/12 Verifying : gd-2.0.35-26.el7.x86_64 9/12 Verifying : 1:nginx-mod-http-xslt-filter-1.16.1-1.el7.x86_64 10/12 Verifying : redhat-indexhtml-7-13.el7.noarch 11/12 Verifying : 1:nginx-mod-http-image-filter-1.16.1-1.el7.x86_64 12/12 Installed: nginx.x86_64 1:1.16.1-1.el7 Dependency Installed: gd.x86_64 0:2.0.35-26.el7 gperftools-libs.x86_64 0:2.6.1-1.el7 libXpm.x86_64 0:3.5.12-1.el7 nginx-all-modules.noarch 1:1.16.1-1.el7 nginx-filesystem.noarch 1:1.16.1-1.el7 nginx-mod-http-image-filter.x86_64 1:1.16.1-1.el7 nginx-mod-http-perl.x86_64 1:1.16.1-1.el7 nginx-mod-http-xslt-filter.x86_64 1:1.16.1-1.el7 nginx-mod-mail.x86_64 1:1.16.1-1.el7 nginx-mod-stream.x86_64 1:1.16.1-1.el7 redhat-indexhtml.noarch 0:7-13.el7 Complete!
Vamos a la ruta de instalación del nginx /etc/nginx
Dentro del nginx.con comentamos los Listen y Server_name
server { # listen 80 default_server; # listen [::]:80 default_server; # server_name _; root /usr/share/nginx/html; # Load configuration files for the default server block. include /etc/nginx/default.d/*.conf; location / { ......
Ahora en conf.d creamos nuestro fichero .conf donde publicaremos nuestras webs
[root@servidor01 nginx]# cd conf.d/ [root@servidor01 conf.d]# vi prueba.conf
y creamos el fichero.
server { listen 192.168.1.10:80; server_name www.nuestraweb.es; location / { proxy_pass http://www.nuestraweb.es; proxy_set_header host www.nuestraweb.es; } error_log /var/log/nginx/www-error.log; access_log /var/log/nginx/www-access.log; }
Con esto ya tenemos una web publicada en nuestro nginx
apuntar que debemos tener un servidor dns y un apache o similar donde este almacenada la web.
instalamos keepalived
[root@servidor01 ~]# yum install -y keepalived Loaded plugins: product-id, search-disabled-repos, subscription-manager epel/x86_64/metalink | 25 kB 00:00:00 epel | 5.4 kB 00:00:00 vmware-tools | 951 B 00:00:00 (1/2): epel/x86_64/updateinfo | 1.0 MB 00:00:00 (2/2): epel/x86_64/primary_db | 6.8 MB 00:00:01 Resolving Dependencies --> Running transaction check ---> Package keepalived.x86_64 0:1.3.5-16.el7 will be installed --> Processing Dependency: libnetsnmp.so.31()(64bit) for package: keepalived-1.3.5-16.el7.x86_64 --> Processing Dependency: libnetsnmpagent.so.31()(64bit) for package: keepalived-1.3.5-16.el7.x86_64 --> Processing Dependency: libnetsnmpmibs.so.31()(64bit) for package: keepalived-1.3.5-16.el7.x86_64 --> Running transaction check ---> Package net-snmp-agent-libs.x86_64 1:5.7.2-48.el7_8 will be installed ---> Package net-snmp-libs.x86_64 1:5.7.2-48.el7_8 will be installed --> Finished Dependency Resolution Dependencies Resolved ======================================================================================================================================================================================================================================= Package Arch Version Repository Size ======================================================================================================================================================================================================================================= Installing: keepalived x86_64 1.3.5-16.el7 rhel-7-server-rpms 331 k Installing for dependencies: net-snmp-agent-libs x86_64 1:5.7.2-48.el7_8 rhel-7-server-rpms 707 k net-snmp-libs x86_64 1:5.7.2-48.el7_8 rhel-7-server-rpms 751 k Transaction Summary ======================================================================================================================================================================================================================================= Install 1 Package (+2 Dependent packages) Total download size: 1.7 M Installed size: 6.0 M Downloading packages: (1/3): net-snmp-agent-libs-5.7.2-48.el7_8.x86_64.rpm | 707 kB 00:00:00 (2/3): keepalived-1.3.5-16.el7.x86_64.rpm | 331 kB 00:00:00 (3/3): net-snmp-libs-5.7.2-48.el7_8.x86_64.rpm | 751 kB 00:00:00 --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- Total 1.6 MB/s | 1.7 MB 00:00:01 Running transaction check Running transaction test Transaction test succeeded Running transaction Installing : 1:net-snmp-libs-5.7.2-48.el7_8.x86_64 1/3 Installing : 1:net-snmp-agent-libs-5.7.2-48.el7_8.x86_64 2/3 Installing : keepalived-1.3.5-16.el7.x86_64 3/3 Verifying : keepalived-1.3.5-16.el7.x86_64 1/3 Verifying : 1:net-snmp-libs-5.7.2-48.el7_8.x86_64 2/3 Verifying : 1:net-snmp-agent-libs-5.7.2-48.el7_8.x86_64 3/3 Installed: keepalived.x86_64 0:1.3.5-16.el7 Dependency Installed: net-snmp-agent-libs.x86_64 1:5.7.2-48.el7_8 net-snmp-libs.x86_64 1:5.7.2-48.el7_8 Complete!
Necesitamos habilitar en el kernel de linux que podamos usar la ip flotante
[root@servidor01 ~]# echo "net.ipv4.ip_nonlocal_bind = 1" >> /etc/sysctl.conf [root@servidor01 ~]# sysctl -p net.ipv4.ip_nonlocal_bind = 1
Bien, ya tenemos instalado nuestro keepalived y habilitada nuestra ip flotante Ahora vamos a configurarlo todo.
Lo mas sencillo es renombrar el .conf y crear un nuevo.
[root@servidor01 ~]# cd /etc/keepalived/ [root@servidor01 keepalived]# mv keepalived.conf keepalived.conf.org [root@servidor01 keepalived]# vi keepalived.conf
Dentro del keepalived.conf ponemos lo siguiente
! Configuracion de keepalived global_defs { notification_email { root@servidor1 } notification_email_from root@servidor1 smtp_server 127.0.0.1 smtp_connect_timeout 30 router_id LVS_DEVEL } vrrp_instance VI_1 { state MASTER interface NOMBRE_INTERFACE virtual_router_id 51 priority 101 #podemos usar 101 para master y 100 para backup advert_int 1 authentication { auth_type PASS auth_pass 1111 } virtual_ipaddress { 192.168.1.10/24 } }
En la primera parte si necesitamos que nos mande un mail de notificación yo lo tengo que me lo envíe a mi correo, es bastante util. Así puedes controlar el movimiento.
Ahora vamos a arrancar el keepalived y vamos a ponerlo en en arranque de linux.
[root@servidor01 keepalived]# systemctl start keepalived ; systemctl enable keepalived Created symlink from /etc/systemd/system/multi-user.target.wants/keepalived.service to /usr/lib/systemd/system/keepalived.service.
Y vamos a comprobar como han quedado las ips deberíamos ver nuestra ip flotante.
[root@servidor01 keepalived]# ip addr 1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000 link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00 inet 127.0.0.1/8 scope host lo valid_lft forever preferred_lft forever inet6 ::1/128 scope host valid_lft forever preferred_lft forever 2: ens192: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP group default qlen 1000 link/ether 00:50:56:95:13:42 brd ff:ff:ff:ff:ff:ff inet 192.168.1.11/24 brd 172.20.23.255 scope global noprefixroute ens192 valid_lft forever preferred_lft forever inet 192.168.1.10/24 scope global secondary ens192 valid_lft forever preferred_lft forever inet6 fe80::250:56ff:fe95:1342/64 scope link noprefixroute valid_lft forever preferred_lft forever
Como podéis ver, nuestro adaptador tiene 2 ips asignadas.
Una vez hecho todo esto, vamos a repetir todos los pasos en el nodo2.
servidor2
instalamos nginx
[root@servidor02]# yum install -y nginx Loaded plugins: product-id, search-disabled-repos, subscription-manager rhel-7-server-rpms | 3.5 kB 00:00:00 (1/2): rhel-7-server-rpms/7Server/x86_64/updateinfo | 3.7 MB 00:00:00 (2/2): rhel-7-server-rpms/7Server/x86_64/primary_db | 70 MB 00:00:03 Resolving Dependencies --> Running transaction check ---> Package nginx.x86_64 1:1.16.1-1.el7 will be installed --> Processing Dependency: nginx-all-modules = 1:1.16.1-1.el7 for package: 1:nginx-1.16.1-1.el7.x86_64 --> Processing Dependency: nginx-filesystem = 1:1.16.1-1.el7 for package: 1:nginx-1.16.1-1.el7.x86_64 --> Processing Dependency: nginx-filesystem for package: 1:nginx-1.16.1-1.el7.x86_64 --> Processing Dependency: redhat-indexhtml for package: 1:nginx-1.16.1-1.el7.x86_64 --> Processing Dependency: libprofiler.so.0()(64bit) for package: 1:nginx-1.16.1-1.el7.x86_64 --> Running transaction check ---> Package gperftools-libs.x86_64 0:2.6.1-1.el7 will be installed ---> Package nginx-all-modules.noarch 1:1.16.1-1.el7 will be installed --> Processing Dependency: nginx-mod-http-image-filter = 1:1.16.1-1.el7 for package: 1:nginx-all-modules-1.16.1-1.el7.noarch --> Processing Dependency: nginx-mod-http-perl = 1:1.16.1-1.el7 for package: 1:nginx-all-modules-1.16.1-1.el7.noarch --> Processing Dependency: nginx-mod-http-xslt-filter = 1:1.16.1-1.el7 for package: 1:nginx-all-modules-1.16.1-1.el7.noarch --> Processing Dependency: nginx-mod-mail = 1:1.16.1-1.el7 for package: 1:nginx-all-modules-1.16.1-1.el7.noarch --> Processing Dependency: nginx-mod-stream = 1:1.16.1-1.el7 for package: 1:nginx-all-modules-1.16.1-1.el7.noarch ---> Package nginx-filesystem.noarch 1:1.16.1-1.el7 will be installed ---> Package redhat-indexhtml.noarch 0:7-13.el7 will be installed --> Running transaction check ---> Package nginx-mod-http-image-filter.x86_64 1:1.16.1-1.el7 will be installed --> Processing Dependency: gd for package: 1:nginx-mod-http-image-filter-1.16.1-1.el7.x86_64 --> Processing Dependency: libgd.so.2()(64bit) for package: 1:nginx-mod-http-image-filter-1.16.1-1.el7.x86_64 ---> Package nginx-mod-http-perl.x86_64 1:1.16.1-1.el7 will be installed ---> Package nginx-mod-http-xslt-filter.x86_64 1:1.16.1-1.el7 will be installed ---> Package nginx-mod-mail.x86_64 1:1.16.1-1.el7 will be installed ---> Package nginx-mod-stream.x86_64 1:1.16.1-1.el7 will be installed --> Running transaction check ---> Package gd.x86_64 0:2.0.35-26.el7 will be installed --> Processing Dependency: libXpm.so.4()(64bit) for package: gd-2.0.35-26.el7.x86_64 --> Running transaction check ---> Package libXpm.x86_64 0:3.5.12-1.el7 will be installed --> Finished Dependency Resolution Dependencies Resolved ======================================================================================================================================================================================================================================= Package Arch Version Repository Size ======================================================================================================================================================================================================================================= Installing: nginx x86_64 1:1.16.1-1.el7 epel 562 k Installing for dependencies: gd x86_64 2.0.35-26.el7 rhel-7-server-rpms 146 k gperftools-libs x86_64 2.6.1-1.el7 rhel-7-server-rpms 272 k libXpm x86_64 3.5.12-1.el7 rhel-7-server-rpms 56 k nginx-all-modules noarch 1:1.16.1-1.el7 epel 19 k nginx-filesystem noarch 1:1.16.1-1.el7 epel 21 k nginx-mod-http-image-filter x86_64 1:1.16.1-1.el7 epel 30 k nginx-mod-http-perl x86_64 1:1.16.1-1.el7 epel 39 k nginx-mod-http-xslt-filter x86_64 1:1.16.1-1.el7 epel 29 k nginx-mod-mail x86_64 1:1.16.1-1.el7 epel 57 k nginx-mod-stream x86_64 1:1.16.1-1.el7 epel 84 k redhat-indexhtml noarch 7-13.el7 rhel-7-server-rpms 270 k Transaction Summary ======================================================================================================================================================================================================================================= Install 1 Package (+11 Dependent packages) Total download size: 1.5 M Installed size: 4.5 M Downloading packages: (1/12): gd-2.0.35-26.el7.x86_64.rpm | 146 kB 00:00:00 (2/12): gperftools-libs-2.6.1-1.el7.x86_64.rpm | 272 kB 00:00:00 (3/12): libXpm-3.5.12-1.el7.x86_64.rpm | 56 kB 00:00:00 (4/12): nginx-1.16.1-1.el7.x86_64.rpm | 562 kB 00:00:00 (5/12): nginx-all-modules-1.16.1-1.el7.noarch.rpm | 19 kB 00:00:00 (6/12): nginx-filesystem-1.16.1-1.el7.noarch.rpm | 21 kB 00:00:00 (7/12): nginx-mod-http-image-filter-1.16.1-1.el7.x86_64.rpm | 30 kB 00:00:00 (8/12): nginx-mod-http-perl-1.16.1-1.el7.x86_64.rpm | 39 kB 00:00:00 (9/12): nginx-mod-http-xslt-filter-1.16.1-1.el7.x86_64.rpm | 29 kB 00:00:00 (10/12): nginx-mod-mail-1.16.1-1.el7.x86_64.rpm | 57 kB 00:00:00 (11/12): nginx-mod-stream-1.16.1-1.el7.x86_64.rpm | 84 kB 00:00:00 (12/12): redhat-indexhtml-7-13.el7.noarch.rpm | 270 kB 00:00:00 --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- Total 774 kB/s | 1.5 MB 00:00:02 Running transaction check Running transaction test Transaction test succeeded Running transaction Installing : redhat-indexhtml-7-13.el7.noarch 1/12 Installing : gperftools-libs-2.6.1-1.el7.x86_64 2/12 Installing : 1:nginx-filesystem-1.16.1-1.el7.noarch 3/12 Installing : libXpm-3.5.12-1.el7.x86_64 4/12 Installing : gd-2.0.35-26.el7.x86_64 5/12 Installing : 1:nginx-mod-stream-1.16.1-1.el7.x86_64 6/12 Installing : 1:nginx-mod-http-perl-1.16.1-1.el7.x86_64 7/12 Installing : 1:nginx-mod-mail-1.16.1-1.el7.x86_64 8/12 Installing : 1:nginx-mod-http-xslt-filter-1.16.1-1.el7.x86_64 9/12 Installing : 1:nginx-1.16.1-1.el7.x86_64 10/12 Installing : 1:nginx-mod-http-image-filter-1.16.1-1.el7.x86_64 11/12 Installing : 1:nginx-all-modules-1.16.1-1.el7.noarch 12/12 Verifying : libXpm-3.5.12-1.el7.x86_64 1/12 Verifying : 1:nginx-mod-stream-1.16.1-1.el7.x86_64 2/12 Verifying : 1:nginx-filesystem-1.16.1-1.el7.noarch 3/12 Verifying : gperftools-libs-2.6.1-1.el7.x86_64 4/12 Verifying : 1:nginx-mod-http-perl-1.16.1-1.el7.x86_64 5/12 Verifying : 1:nginx-1.16.1-1.el7.x86_64 6/12 Verifying : 1:nginx-mod-mail-1.16.1-1.el7.x86_64 7/12 Verifying : 1:nginx-all-modules-1.16.1-1.el7.noarch 8/12 Verifying : gd-2.0.35-26.el7.x86_64 9/12 Verifying : 1:nginx-mod-http-xslt-filter-1.16.1-1.el7.x86_64 10/12 Verifying : redhat-indexhtml-7-13.el7.noarch 11/12 Verifying : 1:nginx-mod-http-image-filter-1.16.1-1.el7.x86_64 12/12 Installed: nginx.x86_64 1:1.16.1-1.el7 Dependency Installed: gd.x86_64 0:2.0.35-26.el7 gperftools-libs.x86_64 0:2.6.1-1.el7 libXpm.x86_64 0:3.5.12-1.el7 nginx-all-modules.noarch 1:1.16.1-1.el7 nginx-filesystem.noarch 1:1.16.1-1.el7 nginx-mod-http-image-filter.x86_64 1:1.16.1-1.el7 nginx-mod-http-perl.x86_64 1:1.16.1-1.el7 nginx-mod-http-xslt-filter.x86_64 1:1.16.1-1.el7 nginx-mod-mail.x86_64 1:1.16.1-1.el7 nginx-mod-stream.x86_64 1:1.16.1-1.el7 redhat-indexhtml.noarch 0:7-13.el7 Complete!
Y copiamso lo ficheros de nodo1 nginx.conf ubicado en /etc/nginx/ y en prueba.conf dentro de /etc/nginx/conf.d
instalamos el keepalived
[root@servidor02 ~]# yum install -y keepalived Loaded plugins: product-id, search-disabled-repos, subscription-manager epel/x86_64/metalink | 25 kB 00:00:00 epel | 5.4 kB 00:00:00 vmware-tools | 951 B 00:00:00 (1/2): epel/x86_64/updateinfo | 1.0 MB 00:00:00 (2/2): epel/x86_64/primary_db | 6.8 MB 00:00:01 Resolving Dependencies --> Running transaction check ---> Package keepalived.x86_64 0:1.3.5-16.el7 will be installed --> Processing Dependency: libnetsnmp.so.31()(64bit) for package: keepalived-1.3.5-16.el7.x86_64 --> Processing Dependency: libnetsnmpagent.so.31()(64bit) for package: keepalived-1.3.5-16.el7.x86_64 --> Processing Dependency: libnetsnmpmibs.so.31()(64bit) for package: keepalived-1.3.5-16.el7.x86_64 --> Running transaction check ---> Package net-snmp-agent-libs.x86_64 1:5.7.2-48.el7_8 will be installed ---> Package net-snmp-libs.x86_64 1:5.7.2-48.el7_8 will be installed --> Finished Dependency Resolution Dependencies Resolved ======================================================================================================================================================================================================================================= Package Arch Version Repository Size ======================================================================================================================================================================================================================================= Installing: keepalived x86_64 1.3.5-16.el7 rhel-7-server-rpms 331 k Installing for dependencies: net-snmp-agent-libs x86_64 1:5.7.2-48.el7_8 rhel-7-server-rpms 707 k net-snmp-libs x86_64 1:5.7.2-48.el7_8 rhel-7-server-rpms 751 k Transaction Summary ======================================================================================================================================================================================================================================= Install 1 Package (+2 Dependent packages) Total download size: 1.7 M Installed size: 6.0 M Downloading packages: (1/3): net-snmp-agent-libs-5.7.2-48.el7_8.x86_64.rpm | 707 kB 00:00:00 (2/3): keepalived-1.3.5-16.el7.x86_64.rpm | 331 kB 00:00:00 (3/3): net-snmp-libs-5.7.2-48.el7_8.x86_64.rpm | 751 kB 00:00:00 --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- Total 1.6 MB/s | 1.7 MB 00:00:01 Running transaction check Running transaction test Transaction test succeeded Running transaction Installing : 1:net-snmp-libs-5.7.2-48.el7_8.x86_64 1/3 Installing : 1:net-snmp-agent-libs-5.7.2-48.el7_8.x86_64 2/3 Installing : keepalived-1.3.5-16.el7.x86_64 3/3 Verifying : keepalived-1.3.5-16.el7.x86_64 1/3 Verifying : 1:net-snmp-libs-5.7.2-48.el7_8.x86_64 2/3 Verifying : 1:net-snmp-agent-libs-5.7.2-48.el7_8.x86_64 3/3 Installed: keepalived.x86_64 0:1.3.5-16.el7 Dependency Installed: net-snmp-agent-libs.x86_64 1:5.7.2-48.el7_8 net-snmp-libs.x86_64 1:5.7.2-48.el7_8 Complete!
Necesitamos habilitar la ip flotante
[root@servidor02 ~]# echo "net.ipv4.ip_nonlocal_bind = 1" >> /etc/sysctl.conf [root@servidor02 ~]# sysctl -p net.ipv4.ip_nonlocal_bind = 1
Renombrar el .conf y creamos uno nuevo.
[root@servidor02 ~]# cd /etc/keepalived/ [root@servidor02 keepalived]# mv keepalived.conf keepalived.conf.org [root@servidor02 keepalived]# vi keepalived.conf
Dentro del keepalive.conf ponemos lo siguiente
! Configuracion de keepalived global_defs { notification_email { root@servidor1 } notification_email_from root@servidor1 smtp_server 127.0.0.1 smtp_connect_timeout 30 router_id LVS_DEVEL } vrrp_instance VI_1 { state BACKUP interface NOMBRE_INTERFACE virtual_router_id 51 priority 100 advert_int 1 authentication { auth_type PASS auth_pass 1111 } virtual_ipaddress { 192.168.1.10/24 } }
Hemos dejado el state en blanco y cambido la prioridad para que este sea el secundario.
Arrancamos el keepalived y lo ponemos en arranque de linux.
[root@servidor02 keepalived]# systemctl start keepalived ; systemctl enable keepalived Created symlink from /etc/systemd/system/multi-user.target.wants/keepalived.service to /usr/lib/systemd/system/keepalived.service.
Vamos a comprobar como han quedado las ips. Ahora tendríamos nuestra ip flotante en nuestro servidor2 (nodo2)
[root@servidor02 keepalived]# ip addr 1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000 link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00 inet 127.0.0.1/8 scope host lo valid_lft forever preferred_lft forever inet6 ::1/128 scope host valid_lft forever preferred_lft forever 2: ens192: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP group default qlen 1000 link/ether 00:50:56:95:13:42 brd ff:ff:ff:ff:ff:ff inet 192.168.1.12/24 brd 172.20.23.255 scope global noprefixroute ens192 valid_lft forever preferred_lft forever inet 192.168.1.10/24 scope global secondary ens192 valid_lft forever preferred_lft forever inet6 fe80::250:56ff:fe95:1342/64 scope link noprefixroute valid_lft forever preferred_lft forever
Podemos o desactivar al adaptador de nuestra maquina
nmcli c down ens192
O simular un corte
shutdown -r now
Espero que os sirva