1. 更新国内镜像源

备份原有的apt镜像源文件

cp /etc/apt/sources.list /etc/apt/sources.list.bak

删除镜像源文件

rm -rf cp /etc/apt/sources.list

重新创建镜像源文件,在文件中重新写入如下内容,保存后更新源:apt update

vim /etc/apt/sources.list 
    #阿里源
    deb http://mirrors.aliyun.com/ubuntu/ bionic main restricted universe multiverse
    deb http://mirrors.aliyun.com/ubuntu/ bionic-security main restricted universe multiverse
    deb http://mirrors.aliyun.com/ubuntu/ bionic-updates main restricted universe multiverse
    deb http://mirrors.aliyun.com/ubuntu/ bionic-proposed main restricted universe multiverse
    deb http://mirrors.aliyun.com/ubuntu/ bionic-backports main restricted universe multiverse
    deb-src http://mirrors.aliyun.com/ubuntu/ bionic main restricted universe multiverse
    deb-src http://mirrors.aliyun.com/ubuntu/ bionic-security main restricted universe multiverse
    deb-src http://mirrors.aliyun.com/ubuntu/ bionic-updates main restricted universe multiverse
    deb-src http://mirrors.aliyun.com/ubuntu/ bionic-proposed main restricted universe multiverse
    deb-src http://mirrors.aliyun.com/ubuntu/ bionic-backports main restricted universe multiverse

    #网易源
    deb http://mirrors.163.com/ubuntu/ bionic main restricted universe multiverse
    deb http://mirrors.163.com/ubuntu/ bionic-security main restricted universe multiverse
    deb http://mirrors.163.com/ubuntu/ bionic-updates main restricted universe multiverse
    deb http://mirrors.163.com/ubuntu/ bionic-proposed main restricted universe multiverse
    deb http://mirrors.163.com/ubuntu/ bionic-backports main restricted universe multiverse
    deb-src http://mirrors.163.com/ubuntu/ bionic main restricted universe multiverse
    deb-src http://mirrors.163.com/ubuntu/ bionic-security main restricted universe multiverse
    deb-src http://mirrors.163.com/ubuntu/ bionic-updates main restricted universe multiverse
    deb-src http://mirrors.163.com/ubuntu/ bionic-proposed main restricted universe multiverse
    deb-src http://mirrors.163.com/ubuntu/ bionic-backports main restricted universe multiverse

    #清华源
    deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic main restricted universe multiverse
    deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic main restricted universe multiverse
    deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-updates main restricted universe multiverse
    deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-updates main restricted universe multiverse
    deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-backports main restricted universe multiverse
    deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-backports main restricted universe multiverse
    deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-security main restricted universe multiverse
    deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-security main restricted universe multiverse
    deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-proposed main restricted universe multiverse
    deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-proposed main restricted universe multiverse

    ##中科大源
    deb https://mirrors.ustc.edu.cn/ubuntu/ bionic main restricted universe multiverse
    deb-src https://mirrors.ustc.edu.cn/ubuntu/ bionic main restricted universe multiverse
    deb https://mirrors.ustc.edu.cn/ubuntu/ bionic-updates main restricted universe multiverse
    deb-src https://mirrors.ustc.edu.cn/ubuntu/ bionic-updates main restricted universe multiverse
    deb https://mirrors.ustc.edu.cn/ubuntu/ bionic-backports main restricted universe multiverse
    deb-src https://mirrors.ustc.edu.cn/ubuntu/ bionic-backports main restricted universe multiverse
    deb https://mirrors.ustc.edu.cn/ubuntu/ bionic-security main restricted universe multiverse
    deb-src https://mirrors.ustc.edu.cn/ubuntu/ bionic-security main restricted universe multiverse
    deb https://mirrors.ustc.edu.cn/ubuntu/ bionic-proposed main restricted universe multiverse
    deb-src https://mirrors.ustc.edu.cn/ubuntu/ bionic-proposed main restricted universe multiverse

    deb https://mirrors.tuna.tsinghua.edu.cn/mysql/apt/ubuntu bionic mysql-5.7 mysql-8.0 mysql-tools

2. 卸载已有mysql

检查是否存在mysql dpkg --list | grep mysql,如果存在,则大概如下图所示,如果没有输出,表示没有mysql安装。 检查是否存在mysql

移除mysql-common:apt remove mysql-common
可以卸载并清除mysql5.7:apt autoremove --purge mysql-server-5.7
清除残留数据:dpkg -l | grep ^rc| awk '{print$2}'| sudo xargs dpkg -P 如果显示如下或者没有输出表示已清除干净 再次检查是否还有mysql信息:dpkg --list | grep mysql如果不为空,继续执行下面代码: apt autoremove --purge mysql-apt-config

3. 安装mysql8.0

下载存储库软件包:wget -c https://dev.mysql.com/get/mysql-apt-config_0.8.10-1_all.deb
安装软件包:dpkg -i mysql-apt-config_0.8.10-1_all.deb
更新软件包:sudo apt-get update,如果存在如下错误,需要更新key 解决方案:
查看签名列表:apt-key list
删除过期的签名(基本都一样):sudo apt-key del dsa1024
重新添加新的签名:

apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 467B942D3A79BD29

这里的key需要填写报错部分的内容
继续执行更新命令:apt update 安装mysql,看看版本是不是8.0,如果是,按Y继续执行,否则重复上面的步骤
apt-get install mysql-server
安装完成后查看是否安装成功,可以登录到mysql看看mysql -uroot -p,输入安装时候填的密码即可

4. 安装zabbix-6.0

参考:zabbix官网安装教程

5. 卸载zabbix

卸载zabbix组件

apt-get --purge remove zabbix-server-mysql
apt-get autoremove zabbix-server-mysql

apt-get --purge remove zabbix-frontend-php
apt-get autoremove zabbix-frontend-php

apt-get --purge remove abbix-apache-conf
apt-get autoremove abbix-apache-conf

apt-get --purge remove zabbix-agent      删除软件其配置
apt-get autoremove zabbix-agent          删除软件依赖包

清理数据
dpkg -l |grep ^rc|awk '{print $2}' |sudo xargs dpkg -P 删除apt-get上下载的软件包
apt-get autoclean
删除缓存的所有软件包
apt-get clean

6. 修改mysql8允许远程登录

允许用户远程登录
update user set host='%' where user='zabbix'; 修改密码策略,mysql8默认的密码策略是:caching_sha2_password
alter user 'zabbix'@'%' identified with mysql_native_pasword by 'zabbix'
允许用户远程访问数据库,如果把zabbix.换为.*则表示可以访问所有数据库;
grant all privileges on zabbix.* to 'zabbix'@'%';
刷新权限
flush privileges;

7. centos安装zabbix-agent

7.1 rpm安装

# 1.下载rpm包
wget https://mirrors.aliyun.com/zabbix/zabbix/6.0/rhel/7/x86_64/zabbix-agent-6.0.12-release1.el7.x86_64.rpm?spm=a2c6h.25603864.0.0.4a7e7a10yQa5Nh

# 2.安装rpm包
rpm -ivh zabbix-agent-6.0.12-release1.el7.x86_64.rpm

# 3.配置zabbix-agent允许root启动
vim /etc/zabbix/zabbix_agent.conf
 Allowroot=1 
 Server=127.0.0.1,x.x.x.x    # 服务端的IP地址
 ServerActive=127.0.0.1       # 服务端IP地址
 Hostname=controller          # hostname,每台机器配置自己的hostname     

# 4.修改用户为root
vim /usr/lib/systemd/system/zabbix-agent.service
user=root
group=root

# 5.重新加载守护进程并启动
systemctl daemon-reload 
systemctl restart zabbix-agent

# TIPS:这种方式安装可能会缺少依赖

7.2 yum源安装

# 1.创建zabbix.repo镜像源
vim /etc/yum.repos.d/zabbix.repo
[zabbix]
name=Zabbix Official Repository
baseurl=http://repo.zabbix.com/zabbix/6.0/rhel/7/x86_64/
enabled=1
gpgcheck=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-ZABBIX-A14FE591

# 2.更新镜像源
 yum clean all
 yum makecache
 
 # 3.安装zabbix-agent
 yum install -y zabbix-agent
 
 # 4.修改配置
 vim /etc/zabbix/zabbix_agentd.conf
 Allowroot=1 
 Server=127.0.0.1,x.x.x.x    # 服务端的IP地址
 ServerActive=127.0.0.1       # 服务端IP地址
 Hostname=controller          # hostname,每台机器配置自己的hostname
 
 # 5.修改用户为root
vim /usr/lib/systemd/system/zabbix-agent.service
user=root
group=root

# 6.启动服务
systemctl start zabbix-agent
systemctl enable zabbix-agent
 systemctl status zabbix-agent