Akemi

Zabbix5.0安装与部署

2024/09/12

zabbix安装与部署分为两个部分,zabbix-server和zabbix-agent的安装与部署

zabbix-server部署

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
环境:
CentOS7.9.2009
zabbix 5.0
MariaDB 5.5.68

#安全相关
systemctl disable firewalld.service --now
setenforce 0
sed -i 's/^SELINUX=.*/SELINUX=disabled/g' /etc/selinux/config

#换阿里云源,因为原本的官方已经不支持了
cp -a /etc/yum.repos.d /etc/yum.repos.d.backup
rm -f /etc/yum.repos.d/*
curl -o /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
cat >/etc/yum.repos.d/Centos7-SCLo.repo<<'EOF'
[centos-sclo-rh]
name=CentOS-7 - SCLo rh
baseurl=http://mirrors.aliyun.com/centos/7/sclo/$basearch/rh/
gpgcheck=1
enabled=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-SIG-SCLo

[centos-sclo-rh-testing]
name=CentOS-7 - SCLo rh Testing
baseurl=http://mirrors.aliyun.com/centos/7/sclo/$basearch/rh/
gpgcheck=0
enabled=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-SIG-SCLo

[centos-sclo-rh-source]
name=CentOS-7 - SCLo rh Sources
baseurl=http://vault.centos.org/centos/7/sclo/Source/rh/
gpgcheck=1
enabled=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-SIG-SCLo

[centos-sclo-rh-debuginfo]
name=CentOS-7 - SCLo rh Debuginfo
baseurl=http://debuginfo.centos.org/centos/7/sclo/$basearch/
gpgcheck=1
enabled=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-SIG-SCLo
EOF
yum clean all
yum makecache

#下载zabbix的repo包
wget https://repo.zabbix.com/zabbix/5.0/rhel/7/x86_64/zabbix-release-5.0-1.el7.noarch.rpm
rpm -Uvh zabbix-release-5.0-1.el7.noarch.rpm
yum -y install zabbix-server-mysql zabbix-agent centos-release-scl
#启用zabbix软件源
sed -i '11s/enabled=0/enabled=1/' /etc/yum.repos.d/zabbix.repo
yum -y install zabbix-web-mysql-scl
yum -y install zabbix-nginx-conf-scl
yum -y install mysql

#安装数据库
#如果使用mysql,导入初始化命令的时候会报错,所以使用Mariadb

CREATE DATABASE zabbix CHARSET utf8mb4 COLLATE utf8mb4_bin;
grant all privileges on zabbix.* to 'zabbix'@'%' identified by 'zabbix';
FLUSH PRIVILEGES;
#导入数据库
zcat /usr/share/doc/zabbix-server-mysql*/create.sql.gz | mysql -uzabbix -pzabbix zabbix
mysql -uroot -proot -e "use zabbix;show tables;"

#修改/etc/zabbix/zabbix_server.conf,使其可以连接上数据库
sed -i 's/^# DBPa.*/DBPassword=zabbix/' /etc/zabbix/zabbix_server.conf

#修改zabbix-nginx的配置/etc/opt/rh/rh-nginx116/nginx/conf.d/zabbix.conf,取消注释
sed -i 's/#\ listen\ 80;/\ listen\ 80;/' /etc/opt/rh/rh-nginx116/nginx/conf.d/zabbix.conf
sed -i 's/#\ server_name\ example.com;/\ server_name\ zabbix.wangsheng.com;/' /etc/opt/rh/rh-nginx116/nginx/conf.d/zabbix.conf

#修改zabbix-php的配置/etc/opt/rh/rh-php72/php-fpm.d/zabbix.conf
sed -i 's/listen.acl_users = apache/listen.acl_users = apache,nginx/' /etc/opt/rh/rh-php72/php-fpm.d/zabbix.conf

#修改nginx发布目录/etc/opt/rh/rh-nginx116/nginx/nginx.conf,修改到/usr/share/zabbix
sed -i 's#\ root\ /opt/rh/rh-nginx116/root/usr/share/nginx/html;#\ root\ /usr/share/zabbix;#' /etc/opt/rh/rh-nginx116/nginx/nginx.conf

#修改时区到上海
sed -i '$iphp_value[date.timezone] = Asia/Shanghai' /etc/opt/rh/rh-php72/php-fpm.d/zabbix.conf

#重启并开机自启
systemctl restart zabbix-server zabbix-agent rh-nginx116-nginx rh-php72-php-fpm
systemctl enable zabbix-server zabbix-agent rh-nginx116-nginx rh-php72-php-fpm --now

zabbix-server网页安装

web登录zabbix.wangsheng.com 我刚刚设置的域名进行安装

输入数据库,一路下一步就可以进入zabbix主界面

默认账户Admin
默认密码zabbix

zabbix-agent部署

zabbix-agent分为两种:
zabbix-agent c语言 独立进程运行
zabbix-agent2(常用) c语言 go语言 多线程、承受高并发

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
环境
CentOS7.9.2009
zabbix 5.0

zabbix-server 192.168.10.171
zabbix-agent 192.168.10.172

#换源
cp -a /etc/yum.repos.d /etc/yum.repos.d.backup
rm -f /etc/yum.repos.d/*
curl -o /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
wget https://repo.zabbix.com/zabbix/5.0/rhel/7/x86_64/zabbix-release-5.0-1.el7.noarch.rpm
rpm -Uvh zabbix-release-5.0-1.el7.noarch.rpm

yum clean all
yum makecache

yum -y install zabbix-agent2
systemctl enable zabbix-agent2 --now

#配置文件修改
cat >/etc/zabbix/zabbix_agent2.conf<<EOF
PidFile=/var/run/zabbix/zabbix_agent2.pid
LogFile=/var/log/zabbix/zabbix_agent2.log
LogFileSize=0
Server=192.168.10.171
ServerActive=192.168.10.171
Hostname=zabbix-agent
Include=/etc/zabbix/zabbix_agent2.d/*.conf
ControlSocket=/tmp/agent.sock
EOF
systemctl restart zabbix-agent2.service

#服务器端重启
systemctl restart rh-nginx116-nginx

1.web端添加新建主机
2.为新建主机添加模板,搞个模板比如Template OS Linux by Zabbix agent
3.重启systemctl restart zabbix-server.service
4.新建主机正常监控中(可用),模板对应的图形也可以查看
5.图形中文字体乱码问题:
yum -y install wqy-microhei-fonts.noarch
\cp /usr/share/fonts/wqy-microhei/wqy-microhei.ttc /usr/share/fonts/dejavu/DejaVuSans.ttf
此时问题已解决

CATALOG
  1. 1. zabbix-server部署
    1. 1.1. zabbix-server网页安装
  2. 2. zabbix-agent部署