一、安装过程
1、查看docker版本(已安装docker)
命令
docker version
打印返回
Client: Docker Engine - Community
Version: 24.0.7
API version: 1.43
Go version: go1.20.10
Git commit: afdd53b
Built: Thu Oct 26 09:08:01 2023
OS/Arch: linux/amd64
Context: default
Server: Docker Engine - Community
Engine:
Version: 24.0.7
API version: 1.43 (minimum version 1.12)
Go version: go1.20.10
Git commit: 311b9ff
Built: Thu Oct 26 09:08:01 2023
OS/Arch: linux/amd64
Experimental: false
containerd:
Version: 1.6.25
GitCommit: d8f198a4ed8892c764191ef7b3b06d8a2eeb5c7f
runc:
Version: 1.1.10
GitCommit: v1.1.10-0-g18a0cb0
docker-init:
Version: 0.19.0
GitCommit: de40ad0
2、安装centos默认最新版(latest)
2.1 拉取镜像
docker pull centos
2.2 查看镜像
命令
docker images
打印返回
REPOSITORY TAG IMAGE ID CREATED SIZE
centos latest 5d0da3dc9764 2 years ago 231MB
3、启动centos镜像
docker run --name centos-1 -p 10080:80 -v /home/cc/centos:/mnt/software -itd --privileged centos bash
上述命令含义: --name docker启动一个自定义命名为:centos-1 -p 为绑定端口80映射到宿主机10080端口 -v 为挂载到宿主机/home/cc/centos文件目录下共享文件 -i 打开STDIN,用于控制台交互 -t 分配tty设备,该可以支持终端登录,默认为false -d 让容器在后台运行(如需进入容器命令行可以不加) --privileged 能够让容器中的进程获取到主机的完整权限,包括root权限 bash 在命令中运行 |
4、进入容器
docker exec -it centos-1 bash
5、安装依赖工具
# 安装make编译命令
yum -y install cmake
# 安装ifconfig命令
yum -y install net-tools
# 安装wget命令
yum -y install wget
6、安装依赖库
yum -y install openssl-devel gcc gcc-c++ wget make
7、下载并安装keepalived
#下载安装包
wget http://www.keepalived.org/software/keepalived-2.2.7.tar.gz
# 解压缩
tar xvf keepalived-2.2.7.tar.gz
cd keepalived-2.2.7
# 设置编译位置
./configure --prefix=/usr/local/keepalived --sysconf=/etc
# 编译安装
make && make install
# 将keepalived主程序加入到环境变量
cp /usr/local/keepalived/sbin/keepalived /usr/sbin/keepalived
# keepalived启动脚本(源码目录下),放到/etc/init.d/目录下就可以使用service命令便捷调用
cp /usr/local/keepalived-2.2.7/keepalived/etc/init.d/keepalived /etc/init.d/keepalived
8、配置keepalived.conf
vi /etc/keepalived/keepalived.conf
内容如下
! Configuration File for keepalived
global_defs {
#路由id:当前安装keepalived节点主机的标识符,全局唯一
router_id keep_130
}
vrrp_instance VI_1 {
# 表示的状态,当前的130服务器为nginx的主节点,MASTER/BACKUP
state MASTER
# 当前实例绑定的网卡(根据自己实际网卡配置)
interface eth0
# 保证主备节点一致
virtual_router_id 51
# 优先级/权重,谁的优先级高,在MASTER挂掉以后,就能成为MASTER
priority 100
# 主备之间同步检查的时间间隔,默认1s
advert_int 1
# 认证授权的密码,防止非法节点的进入
authentication {
auth_type PASS
auth_pass 1111
}
# 虚ip地址(vip),实现ip漂移的地址(根据自己需求配置)
virtual_ipaddress {
192.168.10.100
}
}
9、启动keepalived服务
service keepalived start
或
systemctl start keepalived.service
或
keepalived -l -f /etc/keepalived/keepalived.conf
10、查看keepalived服务
10.1 查看运行状态
systemctl管理查看
systemctl status keepalived.service
或直接查看进程
ps -ef|grep keepalived
打印返回如下:
root 1319 1 0 Nov28 ? 00:00:00 keepalived -l -f /etc/keepalived/keepalived.conf
root 1320 1319 0 Nov28 ? 00:00:18 keepalived -l -f /etc/keepalived/keepalived.conf
root 1806 1 0 05:50 pts/0 00:00:00 grep --color=auto keepalived
10.2 查看ip挂载情况
命令
ip addr
打印返回,可以看到192.168.10.100的IP已经成功挂载
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
10: eth0@if11: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP group default
link/ether 02:42:ac:11:00:03 brd ff:ff:ff:ff:ff:ff link-netnsid 0
inet 172.17.0.3/16 brd 172.17.255.255 scope global eth0
valid_lft forever preferred_lft forever
inet 192.168.10.100/32 scope global eth0
valid_lft forever preferred_lft forever
11、关闭keepalived服务
service keepalived stop
或杀死keepalived相关进程
pkill keepalived
二、一些问题
1、无法下载?
问题提示
CentOS Linux 8 - AppStream 75 B/s | 38 B 00:00 Error: Failed to download metadata for repo 'appstream': Cannot prepare internal mirrorlist: No URLs in mirrorlist |
解决方法
首先,进入到 yum 的 repos 目录
cd /etc/yum.repos.d/
• 🔔其次,修改 centos 文件内容
sed -i 's/mirrorlist/#mirrorlist/g' /etc/yum.repos.d/CentOS-*
sed -i 's|#baseurl=http://mirror.centos.org|baseurl=http://vault.centos.org|g' /etc/yum.repos.d/CentOS-*
• 🔔 然后,生成缓存更新(第一次更新,速度稍微有点慢,耐心等待两分钟左右)
yum makecache
• 🔔 最后,运行 yum update (过程较慢,看到 Complete! 就成功了)
yum update -y
• 🔔 重新执行安装 cmake、net-tools、openssl-devel gcc gcc-c++ wget make等
yum -y install cmake
以上部分参考链接: ReadThroughLife
2、编译时报错,需要安装libnl
问题提示
*** WARNING - this build will not support IPVS with IPv6. Please install libnl/libnl-3 dev libraries to support IPv6 with IPVS. |
解决方法
网上给出的解决办法是
yum -y install libnl libnl-devel
若此时依旧无法安装,可参考下面手动下载
wget http://mirror.centos.org/centos/7/os/x86\_64/Packages/libnl-1.1.4-3.el7.x86\_64.rpm
wget http://mirror.centos.org/centos/7/os/x86\_64/Packages/libnl-devel-1.1.4-3.el7.x86\_64.rpm
rpm -ivh libnl-1.1.4-3.el7.x86_64.rpm
rpm -ivh libnl-devel-1.1.4-3.el7.x86_64.rpm