Configuración del entorno
Dado que rhel8 aún no es popular en las empresas, necesitamos instalar máquinas virtuales rhel7.6 para completar el proyecto.
En este experimento necesitamos tres máquinas virtuales:
Casa anfitriona: 172.25.19.10
servidor1: 172.25.19.1
servidor2: 172.25.19.2
Empaquetado de máquinas virtuales
1. Modificación del nombre de host
[root@localhost ~]$ hostnamectl set-hostname home
[root@localhost ~]$ hostname
home
2. Configuración de archivos de red
[root@localhost network-scripts]$ vim ifcfg-eth0
[root@localhost network-scripts]$ cat ifcfg-eth0
BOOTPROTO=none
DEVICE=eth0
ONBOOT=yes
IPADDR=172.25.19.10
PREFIX=24
3. Configure la resolución del host
[root@localhost network-scripts]$ vim /etc/hosts
[root@localhost network-scripts]$ cat /etc/hosts
4. Deshabilitar elementos
systemctl disable --now NetworkManager
systemctl disable --now firewalld
vim /etc/sysconfig/selinux
5. Configurar la fuente de yum
mount /iso/rhel-server-7.6-x86_64-dvd.iso /var/www/html/rhel7.6/
vim /etc/yum.repos.d/westos.repo
Implementación de clúster de alta disponibilidad
1. Configuración del entorno
Clonar la máquina virtual encapsulada dos veces, renombrar server1, server2 y cambiar la ip a 172.25.19.1 y 172.25.19.2 respectivamente
2. Actualizar la configuración del almacén de software para el clúster de alta disponibilidad
[root@server1 yum.repos.d]# cat westos.repo
[rhel7]
name=rhel7
baseurl=http://172.25.19.250/rhel7.6/
gpgcheck=0
[addons]
name=HighAvailability
baseurl=http://172.25.19.250/rhel7.6/addons/HighAvailability
gpgcheck=0
3. Conexión sin secretos
在server1中:
ssh-keygen
ssh-copy-id server2
4. Realización de hormigón de alta disponibilidad
在server1中:
yum install -y pacemaker pcs psmisc policycoreutils-python 安装集群插件
ssh server2 yum install pacemaker corosync -y
ssh server2 yum install -y pacemaker pcs psmisc policycoreutils-python
systemctl enable --now pcsd
systemctl start pcsd.service
systemctl status pcsd.service
ssh server2 systemctl enable --now pcsd
ssh server2 systemctl start pcsd.service
echo westos | passwd --stdin hacluster
ssh server2 echo westos | passwd --stdin hacluster
yum install bash-* -y
pcs cluster auth server1 server2 配置corosync
#在同一个节点上使用pc集群设置来生成和同步corosync
pcs cluster setup --name mycluster server1 server2
pcs cluster start --all 开启集群
corosync-cfgtool -s 检查群通信是否通畅
pcs cluster status
5. Agregue recursos al clúster de alta disponibilidad
[root@server1 yum.repos.d]# pcs property set stonith-enabled=false
[root@server1 yum.repos.d]# crm_verify -LV
pcs resource create vip ocf:heartbeat:IPaddr2 ip=172.25.254.100 op monitor interval=30s
pcs status
yum install httpd
ssh server2 yum install httpd -y
systemctl enble --now httpd
systemctl enable --now httpd
systemctl restart httpd
ssh server2 systemctl enable --now httpd
ssh server2 systemctl restart httpd
pcs resource create apache systemd:httpd op monitor interval=1min
pcs resource group add webgroup vip apache
Efecto completo:
Si server1 está inactivo, los recursos flotarán automáticamente al server2 para realizar la agrupación