文章目录
- 一、suse系统安装keepalived
- 1.1、准备环境
- 1.2、修改主机名
- 1.3、关闭防火墙
- 1.4、配置网络
- 1.5、配置 yum 源
- 1.6、安装 mysql
- 1.7、安装 keepalived
- 报错信息:
- 使用 wget 下载keepalived 报错
- 解决 使用 wget 下载 keepalived的报错
一、suse系统安装keepalived
1.1、准备环境
操作系统 | IP | 应用软件 | VIP |
---|---|---|---|
SUSE | 192.168.192.150 | mysql keepalived | 192.168.192.100 |
1.2、修改主机名
linux-40pb:~ # hostnamectl set-hostname suse # 修改主机名为:suse
linux-40pb:~ #
linux-40pb:~ # bash
suse:~ #
suse:~ # cat /etc/os-release # 查看系统版本信息
NAME="SLES"
VERSION="12-SP5"
VERSION_ID="12.5"
PRETTY_NAME="SUSE Linux Enterprise Server 12 SP5"
ID="sles"
ANSI_COLOR="0;32"
CPE_NAME="cpe:/o:suse:sles:12:sp5"
suse:~ #
suse:~ # uname -m # 输出主机的硬件架构名称
x86_64
suse:~ #
1.3、关闭防火墙
suse:~ # systemctl status SuSEfirewall2 # 查看防火墙状态
● SuSEfirewall2.service - SuSEfirewall2 phase 2Loaded: loaded (/usr/lib/systemd/system/SuSEfirewall2.service; enabled; vendor preset: disabled)Active: active (exited) since Sat 2023-07-08 08:28:07 CST; 3s agoProcess: 2374 ExecStart=/usr/sbin/SuSEfirewall2 boot_setup (code=exited, status=0/SUCCESS)Main PID: 2374 (code=exited, status=0/SUCCESS)Jul 08 08:28:06 suse systemd[1]: Starting SuSEfirewall2 phase 2...
Jul 08 08:28:06 suse SuSEfirewall2[2374]: Setting up rules from /etc/sysconfig/SuSEfirewall2 ...
Jul 08 08:28:06 suse SuSEfirewall2[2374]: using default zone 'ext' for interface eth0
Jul 08 08:28:07 suse SuSEfirewall2[2374]: Firewall rules successfully set
Jul 08 08:28:07 suse systemd[1]: Started SuSEfirewall2 phase 2.
suse:~ # suse:~ # systemctl disable --now SuSEfirewall2 # 关闭防火墙,并关闭开机自启功能
Removed symlink /etc/systemd/system/multi-user.target.wants/SuSEfirewall2.service.
Removed symlink /etc/systemd/system/multi-user.target.wants/SuSEfirewall2_init.service.
Removed symlink /etc/systemd/system/SuSEfirewall2_setup.service.
Failed to stop SuSEfirewall2_setup.service: Unit SuSEfirewall2_setup.service not loaded.
suse:~ #
suse:~ # systemctl status SuSEfirewall2 # 查看防火墙状态
● SuSEfirewall2.service - SuSEfirewall2 phase 2Loaded: loaded (/usr/lib/systemd/system/SuSEfirewall2.service; disabled; vendor preset: disabled)Active: inactive (dead)Jul 08 08:28:06 suse systemd[1]: Starting SuSEfirewall2 phase 2...
Jul 08 08:28:06 suse SuSEfirewall2[2374]: Setting up rules from /etc/sysconfig/SuSEfirewall2 ...
Jul 08 08:28:06 suse SuSEfirewall2[2374]: using default zone 'ext' for interface eth0
Jul 08 08:28:07 suse SuSEfirewall2[2374]: Firewall rules successfully set
Jul 08 08:28:07 suse systemd[1]: Started SuSEfirewall2 phase 2.
Jul 08 08:29:04 suse systemd[1]: Stopping SuSEfirewall2 phase 2...
Jul 08 08:29:04 suse systemd[1]: Stopped SuSEfirewall2 phase 2.
suse:~ #
1.4、配置网络
suse:~ # ip a
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00inet 127.0.0.1/8 scope host lovalid_lft forever preferred_lft foreverinet6 ::1/128 scope host valid_lft forever preferred_lft forever
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000link/ether 00:0c:29:70:2e:ec brd ff:ff:ff:ff:ff:ffinet 192.168.192.150/24 brd 192.168.192.255 scope global eth0valid_lft forever preferred_lft foreverinet6 fe80::20c:29ff:fe70:2eec/64 scope link valid_lft forever preferred_lft forever
suse:~ #
suse:~ # cd /etc/sysconfig/network/
suse:/etc/sysconfig/network # ll
total 68
-rw-r--r-- 1 root root 9692 Apr 17 02:24 config
-rw-r--r-- 1 root root 14432 Apr 17 02:24 dhcp
drwxr-xr-x 1 root root 40 Apr 17 02:23 if-down.d
drwxr-xr-x 1 root root 66 Apr 17 02:23 if-up.d
-rw-r--r-- 1 root root 149 Jul 8 09:38 ifcfg-eth0
-rw------- 1 root root 147 Apr 17 02:24 ifcfg-lo
-rw-r--r-- 1 root root 21738 Oct 14 2016 ifcfg.template
drwx------ 1 root root 0 Jun 27 2017 providers
-rw-r--r-- 1 root root 29 Jul 8 09:35 routes
drwxr-xr-x 1 root root 206 Apr 17 02:23 scripts
suse:/etc/sysconfig/network #
suse:/etc/sysconfig/network # cp ifcfg-eth0 ifcfg-eth0_bak # 备份
suse:/etc/sysconfig/network # vi ifcfg-eth0
BOOTPROTO='static' # 静态IP
BROADCAST='192.168.192.255' # 广播地址
IPADDR='192.168.192.150' # IP地址
NAME='eth0' # 网卡名
NETMASK='255.255.255.0' # 子网掩码
NETWORK='192.168.192.0' # 网络地址
STARTMODE='auto' # 开机启动网络
suse:/etc/sysconfig/network #
suse:/etc/sysconfig/network # cp routes routes_bak # 备份
suse:/etc/sysconfig/network # vi routes # 配置网关
default 192.168.192.2 - eth0
suse:/etc/sysconfig/network #
suse:~ # tail -5 /etc/resolv.conf
# file and in case of a "netconfig update -f" call.
#
### Please remove (at least) this line when you modify the file!
nameserver 8.8.8.8 # 配置 DNS
nameserver 8.8.4.4 # 配置 DNS
suse:~ #
suse:~ # ping www.baidu.com -w 3 # 测试能否 ping 通外网
PING www.a.shifen.com (180.101.50.242) 56(84) bytes of data.
64 bytes from 180.101.50.242: icmp_seq=1 ttl=128 time=15.7 ms
64 bytes from 180.101.50.242: icmp_seq=2 ttl=128 time=15.6 ms
64 bytes from 180.101.50.242: icmp_seq=3 ttl=128 time=15.9 ms--- www.a.shifen.com ping statistics ---
3 packets transmitted, 3 received, 0% packet loss, time 2003ms
rtt min/avg/max/mdev = 15.683/15.780/15.936/0.182 ms
suse:~ #
# 如果 ping 不通外网排查一下网关问题
1.5、配置 yum 源
suse:~ # cd /etc/zypp/repos.d/
suse:/etc/zypp/repos.d #
suse:/etc/zypp/repos.d # ls
SLES12-SP5-12.5-0.repo
suse:/etc/zypp/repos.d # mv SLES12-SP5-12.5-0.repo{,_bak}
suse:/etc/zypp/repos.d #
suse:/etc/zypp/repos.d # ls
SLES12-SP5-12.5-0.repo_bak
suse:/etc/zypp/repos.d # vim xxx.repo # 添加一下内容
[suse]
name=suse
baseurl=file:///mnt
gpgcheck=0
enabled=1
suse:/etc/zypp/repos.d #
suse:/etc/zypp/repos.d # mount /dev/cdrom /mnt/ # 挂载磁盘
mount: /mnt: WARNING: device write-protected, mounted read-only.
suse:/etc/zypp/repos.d #
suse:/etc/zypp/repos.d # df -h | grep /mnt
/dev/sr0 3.9G 3.9G 0 100% /mnt
suse:/etc/zypp/repos.d #
suse:~ # zypper lr # 列出本地源
Repository priorities are without effect. All enabled repositories share the same priority.# | Alias | Name | Enabled | GPG Check | Refresh
--+-------+------+---------+-----------+--------
1 | suse | suse | Yes | ( ) No | No
suse:~ # # 测试是否已配置好 yum 源,下载 wget 命令是否能下载下来。
suse:~ # rpm -qa | grep wget
suse:~ #
suse:~ # rpm -qa | grep wget # 查看是否已安装 wget
suse:~ #
suse:~ # zypper se wget # 搜索软件包名为:wget
Loading repository data...
Reading installed packages...S | Name | Summary | Type
--+------+-------------------------------------------+-----------| wget | A Tool for Mirroring FTP and HTTP Servers | package | wget | A Tool for Mirroring FTP and HTTP Servers | srcpackage
suse:~ #
suse:~ # zypper in wget # 安装 wget 命令
Loading repository data...
Reading installed packages...
Resolving package dependencies...The following NEW package is going to be installed:wget1 new package to install.
Overall download size: 494.3 KiB. Already cached: 0 B. After the operation, additional 2.0 MiB will be used.
Continue? [y/n/...? shows all options] (y): y # 输入 y
Retrieving package wget-1.14-21.10.1.x86_64 (1/1), 494.3 KiB ( 2.0 MiB unpacked)
Checking for file conflicts: ..................................................................................................................[done]
(1/1) Installing: wget-1.14-21.10.1.x86_64 ....................................................................................................[done]
suse:~ #
suse:~ # rpm -qa | grep wget # 查看是否已安装 wget
wget-1.14-21.10.1.x86_64
suse:~ #
1.6、安装 mysql
suse:~ # cd /opt/
suse:/opt # ls
mysql-community-common-8.0.25-1.el7.x86_64.rpm
mysql-community-devel-8.0.25-1.el7.x86_64.rpm
mysql-community-client-8.0.25-1.el7.x86_64.rpm
mysql-community-libs-8.0.25-1.el7.x86_64.rpm
mysql-community-client-plugins-8.0.25-1.el7.x86_64.rpm
mysql-community-server-8.0.25-1.el7.x86_64.rpm
suse:/opt #
suse:/opt # rpm -ivh mysql-community-common-8.0.25-1.el7.x86_64.rpm
warning: mysql-community-common-8.0.25-1.el7.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
Preparing... ################################# [100%]
Updating / installing...1:mysql-community-common-8.0.25-1.e################################# [100%]
suse:/opt # suse:/opt # rpm -ivh mysql-community-client-plugins-8.0.25-1.el7.x86_64.rpm
warning: mysql-community-client-plugins-8.0.25-1.el7.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
Preparing... ################################# [100%]
Updating / installing...1:mysql-community-client-plugins-8.################################# [100%]
suse:/opt # rpm -ivh mysql-community-libs-8.0.25-1.el7.x86_64.rpm
warning: mysql-community-libs-8.0.25-1.el7.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
Preparing... ################################# [100%]
Updating / installing...1:mysql-community-libs-8.0.25-1.el7################################# [100%]
suse:/opt # rpm -ivh mysql-community-client-8.0.25-1.el7.x86_64.rpm
warning: mysql-community-client-8.0.25-1.el7.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
Preparing... ################################# [100%]
Updating / installing...1:mysql-community-client-8.0.25-1.e################################# [100%]suse:/opt # rpm -ivh mysql-community-devel-8.0.25-1.el7.x86_64.rpm
warning: mysql-community-devel-8.0.25-1.el7.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
Preparing... ################################# [100%]
Updating / installing...1:mysql-community-devel-8.0.25-1.el################################# [100%]suse:/opt # rpm -ivh mysql-community-server-8.0.25-1.el7.x86_64.rpm
warning: mysql-community-server-8.0.25-1.el7.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
Preparing... ################################# [100%]
Updating / installing...1:mysql-community-server-8.0.25-1.e################################# [100%]
suse:/opt # suse:/opt # systemctl status mysqld // 查看状态
● mysqld.service - MySQL ServerLoaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled; vendor preset: disabled)Active: inactive (dead)Docs: man:mysqld(8)http://dev.mysql.com/doc/refman/en/using-systemd.html
suse:/opt #suse:/opt # systemctl start mysqld // 启动MySQL
suse:/opt # systemctl status mysqld // 查看状态
● mysqld.service - MySQL ServerLoaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled; vendor preset: disabled)Active: active (running) since Fri 2023-07-08 11:09:12 CST; 12s agoDocs: man:mysqld(8)http://dev.mysql.com/doc/refman/en/using-systemd.htmlProcess: 2949 ExecStartPre=/usr/bin/mysqld_pre_systemd (code=exited, status=0/SUCCESS)Main PID: 3019 (mysqld)Status: "Server is operational"Tasks: 38 (limit: 512)CGroup: /system.slice/mysqld.service└─3019 /usr/sbin/mysqld
suse:/opt #
1.7、安装 keepalived
# 这里我使用wget 命令下载软件包。或者你下载好之后可以使用xftp传到主机里
suse:/opt # wget https://keepalived.org/software/keepalived-2.2.4.tar.gz
...省略下载过程Nsuse:/opt # ll
total 1176
-rw-r--r-- 1 root root 1202602 May 31 18:37 keepalived-2.2.4.tar.gz
suse:/opt # # 下载依赖包
suse:~ # zypper in gcc gcc-c++ make openssl kernel-devel
Loading repository data...
Reading installed packages...
'openssl' is already installed.
No update candidate for 'openssl-1.0.2p-1.13.noarch'. The highest available version is already installed.
'make' is already installed.
No update candidate for 'make-4.0-4.1.x86_64'. The highest available version is already installed.The following 19 NEW packages are going to be installed:gcc gcc-c++ gcc48 gcc48-c++ glibc-devel kernel-default-devel kernel-devel kernel-macros libasan0 libatomic1 libelf-devel libgomp1 libitm1libopenssl-1_0_0-devel libopenssl-devel libstdc++48-devel libtsan0 linux-glibc-devel zlib-devel19 new packages to install.
Overall download size: 50.8 MiB. Already cached: 0 B. After the operation, additional 147.0 MiB will be used.
Continue? [y/n/...? shows all options] (y): y # 输入 y
···省略下载过程suse:~ # cd /opt/
suse:/opt # ll
total 1176
-rw-r--r-- 1 root root 1202602 May 31 18:37 keepalived-2.2.4.tar.gz
suse:/opt # tar xf keepalived-2.2.4.tar.gz # 解压软件包
suse:/opt # ll
total 1176
drwxrwxr-x 1 1000 1000 412 May 31 18:35 keepalived-2.2.4
-rw-r--r-- 1 root root 1202602 May 31 18:37 keepalived-2.2.4.tar.gz
suse:/opt #
suse:/opt # cd keepalived-2.2.4/
suse:/opt/keepalived-2.2.4 #
suse:/opt/keepalived-2.2.4 # ls
AUTHOR COPYING Dockerfile.in Makefile.am README.md aclocal.m4 bin_install build_setup configure.ac keepalived lib snap
CONTRIBUTORS ChangeLog INSTALL Makefile.in TODO autogen.sh build-aux configure doc keepalived.spec.in m4 tools
suse:/opt/keepalived-2.2.4 # ./configure --prefix=/usr/local/keepalived # 指定安装路径/usr/local/keepalived
···省略Nsuse:/opt/keepalived-2.2.4 # make 执行make命令进行编译
···省略Nsuse:/opt/keepalived-2.2.4 # make install # 按Makefile定义好的路径拷贝至安装目录中
···省略Nsuse:~ # mkdir -p /etc/keepalived # 在 /etc/下创建目录名为: keepalived
suse:~ # ll -d /etc/keepalived/
drwxr-xr-x 1 root root 0 Jul 8 10:58 /etc/keepalived/
suse:~ # # 复制keepalived.conf 到/etc/keepalived/目录下
suse:~ # cp -r /usr/local/keepalived/etc/keepalived/keepalived.conf /etc/keepalived/
suse:~ #
suse:~ # ll /etc/keepalived/keepalived.conf -d
-rw-r--r-- 1 root root 3550 Jul 8 10:59 /etc/keepalived/keepalived.conf
suse:~ # suse:~ # cd /usr/local/keepalived/
suse:/usr/local/keepalived # ll
total 0
drwxr-xr-x 1 root root 14 Jul 8 10:55 bin
drwxr-xr-x 1 root root 38 Jul 8 10:55 etc
drwxr-xr-x 1 root root 20 Jul 8 10:55 sbin
drwxr-xr-x 1 root root 20 Jul 8 10:55 share
suse:/usr/local/keepalived # # 配置 keepalived.conf 文件
suse:~ # cd /etc/keepalived/
suse:/etc/keepalived # cat keepalived.conf
! Configuration File for keepalivedglobal_defs {router_id test-1
}vrrp_instance VI_1 {state MASTERinterface eth0virtual_router_id 51priority 100advert_int 1authentication {auth_type PASSauth_pass 1111}virtual_ipaddress {192.168.192.100}
}
virtual_server 192.168.192.100 3306 {delay_loop 6lb_algo rrlb_kind NATpersistence_timeout 50protocol TCPreal_server 192.168.192.150 3306 {weight 1TCP_CHECK {connect_timeout 3nb_get_retry 3delay_before_retry 3connect_port 3306}}
# real_server 192.168.192.151 3306 { # 如果有多个数据库就把注释取消掉
# weight 1
# TCP_CHECK {
# connect_timeout 3
# nb_get_retry 3
# delay_before_retry 3
# connect_port 3306
# }
# }
}
suse:/etc/keepalived # suse:~ # systemctl daemon-reload # 重新加载
suse:~ #
suse:~ # systemctl status keepalived.service # 查看状态
● keepalived.service - LVS and VRRP High Availability MonitorLoaded: loaded (/usr/lib/systemd/system/keepalived.service; disabled; vendor preset: disabled)Active: inactive (dead)Docs: man:keepalived(8)man:keepalived.conf(5)man:genhash(1)https://keepalived.org
suse:~ #
suse:~ # systemctl start keepalived.service # 启动keepalived
suse:~ #
suse:~ # systemctl status keepalived.service
● keepalived.service - LVS and VRRP High Availability MonitorLoaded: loaded (/usr/lib/systemd/system/keepalived.service; disabled; vendor preset: disabled)Active: active (running) since Sat 2023-07-08 11:09:56 CST; 4s agoDocs: man:keepalived(8)man:keepalived.conf(5)man:genhash(1)https://keepalived.orgProcess: 44880 ExecStart=/usr/local/keepalived/sbin/keepalived $KEEPALIVED_OPTIONS (code=exited, status=0/SUCCESS)Main PID: 44881 (keepalived)Tasks: 2 (limit: 512)CGroup: /system.slice/keepalived.service├─44881 /usr/local/keepalived/sbin/keepalived -D└─44882 /usr/local/keepalived/sbin/keepalived -D
···省略Nsuse:~ # ip addr show eth0
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000link/ether 00:0c:29:70:2e:ec brd ff:ff:ff:ff:ff:ffinet 192.168.192.150/24 brd 192.168.192.255 scope global eth0valid_lft forever preferred_lft foreverinet 192.168.192.100/32 scope global eth0 # VIPvalid_lft forever preferred_lft foreverinet6 fe80::20c:29ff:fe70:2eec/64 scope link valid_lft forever preferred_lft forever
suse:~ #
报错信息:
使用 wget 下载keepalived 报错
# 下载keepalived 报错
suse:/opt # wget https://keepalived.org/software/keepalived-2.2.4.tar.gz
--2023-07-08 10:04:06-- https://keepalived.org/software/keepalived-2.2.4.tar.gz
Resolving keepalived.org (keepalived.org)... 91.121.30.175
Connecting to keepalived.org (keepalived.org)|91.121.30.175|:443... connected.
ERROR: cannot verify keepalived.org's certificate, issued by ‘/C=US/O=Let's Encrypt/CN=R3’:Issued certificate has expired.
To connect to keepalived.org insecurely, use `--no-check-certificate'.
解决 使用 wget 下载 keepalived的报错
suse:/opt # wget https://keepalived.org/software/keepalived-2.2.4.tar.gz --no-check-certificate