卸载docker
sudo systemctl stop docker
sudo yum remove -y docker-ce docker-ce-cli containerd.io
检查并卸载其他相关组件
使用以下下令查找全部与 Docker 相关的已安装软件包,并卸载它们:
sudo yum list installed | grep docker | awk '{print $1}' | xargs sudo yum remove -y
sudo rm -rf /var/lib/docker
sudo rm -rf /etc/docker
sudo yum clean all
检查docker是否卸载完成:
docker -v
卸载docker的yum堆栈配置:
sudo rm -f /etc/yum.repos.d/docker-ce.repo
删除docker的配置文件和数据目次
sudo rm -rf /etc/docker
sudo rm -rf /var/lib/docker
sudo rm -rf /var/run/docker*
设置IP地址
查看主机名:hostname : techtest9-230
查看IP地址:ifconfig :- [root@techtest9-230 ~]# ifconfig
- docker0: flags=4099<UP,BROADCAST,MULTICAST> mtu 1500
- 网络接口(Docker 默认创建的虚拟网络接口,用于容器之间的网络通信)
- 接口状态 up:接口已启用 broadcast:支持广播 multicast:支持多播 mtu:最大传输单元(字节)
- inet 172.17.0.1 netmask 255.255.0.0 broadcast 172.17.255.255
- 接口ipv4地址 子网掩码 广播地址
-
- ether 02:42:39:69:41:f0 txqueuelen 0 (Ethernet)
- mac地址
-
- RX packets 0 bytes 0 (0.0 B)
- RX errors 0 dropped 0 overruns 0 frame 0
- TX packets 0 bytes 0 (0.0 B)
- TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
- eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
- 网络接口(物理网络接口,通常用于连接到局域网或互联网)
- inet 192.168.9.209 netmask 255.255.255.0 broadcast 192.168.9.255
- inet6 fe80::5054:ff:fefd:b3e0 prefixlen 64 scopeid 0x20<link>
- ether 52:54:00:fd:b3:e0 txqueuelen 1000 (Ethernet)
-
- RX packets 53733238 bytes 19368956068 (18.0 GiB)
- 接受的数据包(个) 总大小(字节)
-
- RX errors 0 dropped 1405846 overruns 0 frame 0
- 丢弃的数据包(个)
-
- TX packets 8484135 bytes 640565302 (610.8 MiB)
- 发送的数据包(个) 总大小(字节)
-
- TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
- lo: flags=73<UP,LOOPBACK,RUNNING> mtu 65536
- lo 是回环接口,用于本地主机之间的通信
- loopback:回环接口
- inet 127.0.0.1 netmask 255.0.0.0
- inet6 ::1 prefixlen 128 scopeid 0x10<host>
- loop txqueuelen 1000 (Local Loopback)
- RX packets 0 bytes 0 (0.0 B)
- RX errors 0 dropped 0 overruns 0 frame 0
- TX packets 0 bytes 0 (0.0 B)
- TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
复制代码 查看操作系统信息:cat /etc/os-release
切换cd /etc/sysconfig/network-scripts/ 进入网络配置文件目次
ll查看目次:ifcfg-eth0

vim ifcfg-eth0编辑配置文件- TYPE=Ethernet 网络接口的类型:以太网
- BOOTPROTO=none 接口的启动协议
- none:不使用任何启动协议,即不通过 DHCP 自动获取 IP 地址。
- 其他可能的值包括 dhcp(使用 DHCP 获取 IP 地址)和 static(通常与手动配置的 IP 地址 一起使用,但 static 本身不是标准值,而是通过其他配置项如 IPADDR 指定静态 IP)。
- DEFROUTE=yes 指定是否将此接口设置为默认路由,意味着通过此接口发送默认流量
- IPV4_FAILURE_FATAL=no 指定当 IPv4 配置失败时,是否将启动过程视为失败,no:即使 IPv4 配置失败,系 统也会继续启动
- NAME=eth0 指定网络接口的逻辑名称
- DEVICE=eth0 指定网络接口的设备名称,通常与 NAME 相同,但在某些配置中可能不同。DEVICE 指定了内核中 的实际设备名称
- ONBOOT=yes 指定系统启动时是否自动启动此接口
- IPADDR=192.168.9.209 指定接口的静态 IP 地址
- PREFIX=24 指定子网掩码的前缀长度,前 24 位是网络部分,后 8 位是主机部分
- GATEWAY=192.168.9.254 指定默认网关的 IP 地址,用于路由到其他网络的网关地址
复制代码- DNS1=8.8.8.8 设置主DNS(谷歌公共DNS服务器) 不要使用谷歌的DNS,使用阿里云的dns:223.6.6.6
- DNS2=8.8.4.4 设置备用DNS
- BOOTPROTO=static 启用静态IP地址 静态IP地址是固定分配,不会因为设备重启或网络变化而改变,适用场景:服 务器(如网站、数据库)、打印机、网络存储设备(NAS)、监控摄像头等需要持续稳定访问的 设备。固定 IP 地址使得管理员可以通过 IP 直接访问设备,无需动态查询当前 IP。
复制代码 配置完成,重启网络:service network restart
测试网络是否正常: ping www.baidu.com ping下令 的计划初衷是用于实时监控网络连通性,因此它会持续发送数据包并表现结果,直到用户手动停止(ctrl+c)可以指定发送的数据包个数:ping -c 4 www.baidu.com指定发送4个数据包。
查看IP地址: ip addr
关闭selinux
为什么要关闭selinux?
SELinux 是 Linux 系统的一种安全机制,可以限制系统资源(如文件、网络等)的访问,提高系统的安全性。在 docker运行过程中,必要访问系统资源,但 SElinux 可能会限制访问,从而影响 docker的运行。
sed -i 's/SELINUX=enforcing/SELINUX=disabled/g' /etc/selinux/config
备注:修改selinux配置文件之后,重启linux机器,selinux配置才气永久见效,重启之后,登录到机器,执行如下下令:
getenforce
假如表现Disabled说明selinux已经关闭
安装基础包
备注:centos7目前默认的yum源大部分人无法用,可以使用阿里云的源:
mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup
wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
yum clean all && yum makecache
yum install -y device-mapper-persistent-data lvm2 wget net-tools nfs-utils lrzsz gcc gcc-c++ make cmake libxml2-devel openssl-devel curl curl-devel unzip sudo ntp libaio-devel wget vim ncurses-devel autoconf automake zlib-devel python-devel epel-release openssh-server socat ipvsadm conntrack telnet ipvsadm- 1.device-mapper-persistent-data:设备映射器持久数据,用于设备映射器的持久化存储。
- 2.lvm2:逻辑卷管理器,用于管理逻辑卷。
- 3.wget:用于从网络下载文件的命令行工具。
- 4.net-tools:包含了一系列网络工具,如ifconfig和netstat,用于配置和管理网络。
- 5.nfs-utils:NFS(Network File System)工具,用于搭建和管理NFS网络文件系统。
- 6.lrzsz:提供了用于在UNIX系统和计算机终端之间传输文件的工具。 rz -y sz -y
- 7.gcc:GNU编译器集合,用于编译C语言和C++程序。
- 8.gcc-c++:GNU编译器集合的C++编译器。
- 9.make:用于自动化编译和安装程序的工具。
- 10.cmake:用于跨平台软件构建的工具。
- 11.libxml2-devel:libxml2的开发库,用于开发基于XML的应用程序。
- 12.openssl-devel:OpenSSL的开发库,用于在应用程序中使用加密和安全功能。
- 13.curl:用于从命令行或脚本中进行URL数据传输的工具。
- 14.curl-devel:libcurl的开发库,用于在应用程序中使用libcurl进行URL数据传输。
- 15.unzip:用于解压缩ZIP文件的命令行工具。
- 16.sudo:用于以其他用户的身份执行命令的工具,通常用于提升权限。
- 17.ntp:网络时间协议客户端,用于同步系统时钟。
- 18.libaio-devel:异步I/O(AIO)的开发库,用于开发异步I/O应用程序。
- 19.vim:文本编辑器,通常用于在命令行中编辑文本文件。
- 20.ncurses-devel:ncurses的开发库,用于在文本终端上显示复杂的图形界面。
- 21.autoconf:用于自动配置软件包的工具。
- 22.automake:用于自动生成Makefile文件的工具。
- 23.zlib-devel:zlib的开发库,用于在应用程序中进行数据压缩和解压缩。
- 24.python-devel:Python的开发库,用于在应用程序中使用Python编程语言。
- 25.epel-release:Extra Packages for Enterprise Linux (EPEL)软件源的发布包,用于安装额外的软件包。
- 26.openssh-server:OpenSSH服务器,用于远程访问和管理服务器。
- 27.socat:多功能的网络工具,用于在不同类型的网络连接之间传输数据。
- 28.ipvsadm:IPVS管理工具,用于配置Linux内核中的IPVS(IP Virtual Server)负载均衡。
- 29.conntrack:用于查看和管理Linux内核连接跟踪表的工具。
- 30.telnet:用于通过Telnet协议连接到远程主机的工具。
复制代码 设置主机名
hostnamectl set-hostname test-abc && bash
配置主机hosts文件,相互之间通过主机名互相访问
修改每台机器的/etc/hosts文件vim /etc/hosts,文件末了增加如下内容:
192.168.9.209 test-abc
如下所示:- 127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
- ::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
- 192.168.9.209 test-abc
复制代码 备注:Linux机器配置主机名的用处:
- 标识主机:主机名是用来标识盘算机或网络设备的名称。通过配置主机名,可以使得其他盘算机或网络服务更容易地识别和定位该主机。在网络环境中,主机名是在进行网络通讯时进行标识的重要信息之一。
- 管理网络服务:一些网络服务和应用程序可能必要知道主机的名称才气正常运行。通过配置主机名,可以确保这些服务能够正确地识别和绑定到正确的主机上。
- 方便管理:在管理多台服务器或设备时,通过为每台设备配置唯一的主机名可以更轻松地进行识别和管理。这在进行系统日志分析、长途管理以及配置文件管理时特别有用。
- 日志记录:主机名通常会出如今系统日志中,以标识生成日志的主机。通过主机名,可以更容易地跟踪和管理日志,特别是在分布式系统中。
- 安全性:在一些情况下,主机名也用于识别访问权限。例如,通过配置防火墙规则或访问控制列表(ACL)时,可以基于主机名来限制对特定主机的访问。
关闭firewalld防火墙
systemctl stop firewalld
systemctl disable firewalld
配置yum源
查看当前源:yum repolist
配置国内安装docker的阿里云在线源- [root@test-abc ~]#yum install yum-utils -y
- [root@test-abc~]#yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
- [root@test-abc ~]# yum clean all && yum makecache
复制代码 修改机器内核参数- [root@test-abc ~]#modprobe br_netfilter
- [root@test-abc ~]#vim /etc/sysctl.d/docker.conf
复制代码 输入如下内容:- net.bridge.bridge-nf-call-ip6tables = 1
- net.bridge.bridge-nf-call-iptables = 1
- net.ipv4.ip_forward = 1
复制代码 [root@test-abc~]#sysctl -p /etc/sysctl.d/docker.conf :sysctl 将读取 /etc/sysctl.d/docker.conf文件中的参数,并将其应用到当前系统。
这些参数的含义是:
- net.bridge.bridge-nf-call-ip6tables = 1:
这个参数启用了 IPv6 的iptables netfilter hook,允许 Linux 内核在网络层面上进行 IPv6 数据包的过滤和处理。在 Kubernetes 中,这个参数通常必要启用,因为 Kubernetes 网络通常是基于 iptables 实现的,而且在一些网络插件中可能会使用到 IPv6。这个参数的启用确保了 Linux 内核在处理 IPv6 数据包时会经过 iptables 过滤,从而确保网络功能的正常运行。
- net.bridge.bridge-nf-call-iptables = 1:
这个参数启用了 IPv4 的iptables netfilter hook,雷同于前一个参数,但是针对 IPv4 数据包。它允许 Linux 内核在网络层面上进行 IPv4 数据包的过滤和处理。在 Kubernetes 中,这个参数通常必要启用,因为 Kubernetes 网络通常是基于 iptables 实现的,而且在一些网络插件中可能会使用到 Ipv4。这个参数的启用确保了 Linux 内核在处理 Ipv4 数据包时会经过 iptables 过滤,从而确保网络功能的正常运行。
这个参数启用了 Linux 内核的 IP 转发功能,允许 Linux 主机将收到的数据包从一个网络接口转发到另一个网络接口。在 Kubernetes 中,Pod 可能会超过多个节点进行通讯。例如,当一个 Pod 必要访问另一个 Pod 或外部服务时,网络流量可能必要通过差异的节点进行路由。启用 IP 转发功能允许 Linux 主机将收到的数据包从一个网络接口转发到另一个网络接口,从而实现跨节点通讯。
安装docker
Docker 镜像
o Docker 镜像用于创建容器,这些容器可以运行特定的应用程序及其依赖。它们专注于应用程序的打包和部署。
o Docker 镜像包罗操作系统、应用程序代码、运行时环境、库、依赖项和配置文件等。每个镜像层都是只读的,容器在运行时会添加一个可写层。
o Docker 镜像是分层的,每一层都是一个增量更改。镜像层通过团结文件系统(如 OverlayFS)组合在一起。
o Docker 镜像通过 Docker 引擎来管理和运行,使用 docker run 下令启动容器。
o Docker 镜像可以非常小,只包罗运行特定应用程序所需的最小环境,非常适合微服务架构。
o 镜像可以存储在 Docker Hub 或私有的 Docker 堆栈中,通过版本控制进行管理。- [root@test-abc~]# sudo yum install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
- [root@test-abc~]# sudo mkdir -p /etc/docker
- [root@test-abc~]# sudo tee /etc/docker/daemon.json <<-'EOF'
- {
- "registry-mirrors": [ "https://docker.1ms.run",
- "https://docker.xuanyuan.me"] 阿里云的镜像加速器经常被封,无法使用!!!
- }
- EOF
- [root@xianchaomaster1 ~]# sudo systemctl daemon-reload
- [root@xianchaomaster1 ~]# sudo systemctl restart docker
复制代码 导入初始架构和数据,系统将提示您输入新创建的密码- 启动docker服务:systemctl start docker
- 停止docker服务:systemctl stop docker
- 重启docker服务:systemctl restart docker
- 查看docker服务状态:systemctl status docker
- 开机启动docker服务:systemctl enable docker
复制代码 密码:123456
更改Zabbix配置文件- 查看镜像:docker images
- 搜索镜像:docker search redis
- 拉取镜像:docker pull redis
- 删除镜像:docker rmi IMAGE ID
- 显示全部的镜像:docker images -q
- 删除全部的镜像:docker rmi`docker images -q`
复制代码- 查看容器 docker ps查看正在运行的容器 docker ps -a查看所有的容器 docker ps -aq查看所有容器的id
- 创建容器 docker run -it --name=c1 centos:7 /bin/bash
- -i参数:容器若没有和客户端连接,就会关闭掉,-i参数可以保持容器一直运行
- -t参数:给容器分配一个尾的终端,可以来输入一些命令,可以合并写成-it
- -d参数:后台运行创建容器,可以合并写成-id
- 以-it方式创建容器,一创建则立马进入容器,一退出则立刻关闭容器,交互式容器
- 以-id方式创建容器,不会立刻进入容器,要通过命令才能进入容器,退出后,容器不会自动关闭,守护式容器
- --name:容器的名字,可以使用=连接,或者空格连接容器名字
- /bin/bash:初始化脚本指令,相当于打开一个shell窗口
- 进入容器 docker exec -it c2 /bin/bash 以-id方式创建容器
- 启动容器 docker start 容器名
- 停止容器 docker stop 容器名
- 删除容器 docker rm 容器名
- 查看容器信息 docker inspect 容器名
复制代码被监控端的配置
参考资料:https://blog.csdn.net/lerp020321/article/details/142318503?fromshare=blogdetail&sharetype=blogdetail&sharerId=142318503&sharerefer=PC&sharesource=2301_76820728&sharefrom=from_link
安装zabbix源- # rpm -Uvh https://repo.zabbix.com/zabbix/5.2/rhel/7/x86_64/zabbix-release-5.2-1.el7.noarch.rpm
- # rpm -Uvh https://repo.zabbix.com/zabbix/5.0/rhel/7/x86_64/zabbix-release-5.0-1.el7.noarch.rpm ----用这个5.0的版本,后续的bug会少很多
- # yum clean all
复制代码 修改配置文件- # yum install zabbix-server-mysql zabbix-agent
复制代码 启动服务- [root@test-abc ~]# yum install zabbix-server-mysql zabbix-agent
- Loaded plugins: fastestmirror
- Loading mirror speeds from cached hostfile
- Could not retrieve mirrorlist http://mirrorlist.centos.org?arch=x86_64&release=7&repo=sclo-rh error was
- 14: curl#6 - "Could not resolve host: mirrorlist.centos.org; Unknown error"
- One of the configured repositories failed (Unknown),
- and yum doesn't have enough cached data to continue. At this point the only
- safe thing yum can do is fail. There are a few ways to work "fix" this:
- 1. Contact the upstream for the repository and get them to fix the problem.
- 2. Reconfigure the baseurl/etc. for the repository, to point to a working
- upstream. This is most often useful if you are using a newer
- distribution release than is supported by the repository (and the
- packages for the previous distribution release still work).
- 3. Run the command with the repository temporarily disabled
- yum --disablerepo=<repoid> ...
- 4. Disable the repository permanently, so yum won't use it by default. Yum
- will then just ignore the repository until you permanently enable it
- again or use --enablerepo for temporary usage:
- yum-config-manager --disable <repoid>
- or
- subscription-manager repos --disable=<repoid>
- 5. Configure the failing repository to be skipped, if it is unavailable.
- Note that yum will try to contact the repo. when it runs most commands,
- so will have to try and fail each time (and thus. yum will be be much
- slower). If it is a very temporary problem though, this is often a nice
- compromise:
- yum-config-manager --save --setopt=<repoid>.skip_if_unavailable=true
- Cannot find a valid baseurl for repo: centos-sclo-rh/x86_64
复制代码 192.168.9.208/zabbix访问
默认用户名:Admin
默认密码:zabbix
创建主机群组


创建主机


查看是否监控到:- CentOS7的SCL源在2024年6月30日停止维护了。 当scl源里面默认使用了centos官方的地址,无法连接,需要替换为其他的云。
- 1.重命名原来的文件:
- cd /etc/yum.repos.d/
- mv CentOS-SCLo-scl.repo CentOS-SCLo-scl.repo.bak
- mv CentOS-SCLo-scl-rh.repo CentOS-SCLo-scl-rh.repo.bak
- vim CentOS-SCLo-scl-rh.repo
- 2. 粘贴以下内容:
- [centos-sclo-rh]
- name=CentOS-7 - SCLo rh
- baseurl=https://mirrors.aliyun.com/centos/7/sclo/x86_64/rh/
- gpgcheck=1
- enabled=1
- gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-SIG-SCLo
- 3.重新执行安装命令:
- yum install zabbix-server-mysql zabbix-agent
复制代码 问题!!!!!!! 监控的到,但是有警告
判断不了那边存在问题:
参考资料:https://blog.csdn.net/hbhe0316/article/details/122701217?fromshare=blogdetail&sharetype=blogdetail&sharerId=122701217&sharerefer=PC&sharesource=2301_76820728&sharefrom=from_link
CSDN:hbhe0316 zabbix_server无法启动
查看zabbix server详细日志- # yum install centos-release-scl
复制代码 报错:数据库的问题- [root@zabbix-server ~]# # yum install centos-release-scl 9567:20250411:165254.175 [Z3001] connection to database 'zabbix' failed: [2005] Unknown MySQL server host '192.168.9.208 #数据库地址' (2) 9567:20250411:165254.175 database is down: reconnecting in 10 seconds 9567:20250411:165304.176 [Z3001] connection to database 'zabbix' failed: [2005] Unknown MySQL server host '192.168.9.208 #数据库地址' (2) 9567:20250411:165304.176 database is down: reconnecting in 10 secondszabbix无法连接到数据库日志中表现尝试连接的主机是 192.168.9.208 #数据库地址,其中 #数据库地址 看起来是解释或配置错误。查看修改/etc/zabbix/zabbix_server.conf配置文件去掉背面的汉字解释内容进入数据库:mysql -u root -p给zabbix用户授权ALTER USER 'zabbix'@'localhost' IDENTIFIED BY 'wwwwww';flush privileges;重启服务sudo systemctl restart zabbix-server乐成了!!!!!
复制代码
zabbix的使用
自界说监控项模板- # yum install zabbix-web-mysql-scl zabbix-apache-conf-scl
复制代码 免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!更多信息从访问主页:qidao123.com:ToB企服之家,中国第一个企服评测及商务社交产业平台。 |