版本6.0支持年限:
#关闭防火墙
[root@zabbix ~]# systemctl stop firewalld
[root@zabbix ~]# systemctl disable firewalld
#改为宽容模式
[root@zabbix ~]# sed -ri '/^SELINUX/s#enforcing#permissive#' /etc/selinux/config
一、部署nginx、PHP
1、安装nginx
#Nginx的yum源
[root@zabbix ~]# vim /etc/yum.repos.d/nginx.repo
[nginx-stable]
name=nginx stable repo
baseurl=http://nginx.org/packages/centos/$releasever/$basearch/
gpgcheck=1
gpgkey=https://nginx.org/keys/nginx_signing.key
module_hotfixes=true
#安装Nginx
[root@zabbix ~]# yum install nginx -y
2、安装PHP
#把阿里云的base源覆盖到本地的base源
[root@zabbix ~]# curl -o /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
#安装第三方epel-release源
[root@zabbix ~]# yum install epel-release.noarch -y
#把阿里云的epel源覆盖到本地的base源
[root@zabbix ~]# curl -o /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo
#第三方webtatic源
[root@zabbix ~]# rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm
#安装PHP
[root@zabbix ~]# yum install php72w-cli php72w-fpm php72w-gd php72w-mbstring php72w-bcmath php72w-xml php72w-ldap php72w-mysqlnd -y
3、配置nginx
[root@zabbix ~]# vim /etc/nginx/conf.d/conn.conf
server {
listen 80;
server_name www.zabbix-test.com;
root /app/www/zabbix;
location / {
index index.php;
}
location ~ \.php$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
4、配置PHP
#把www.conf配置文件里的user和group的Apache值改为Nginx
[root@zabbix ~]# sed -ri '/^(user|group)/s#apache#nginx#g' /etc/php-fpm.d/www.conf
5、测试
[root@zabbix ~]# mkdir -p /app/www/zabbix
[root@zabbix ~]# vim /app/www/zabbix/info.php
<?php
phpinfo();
?>
[root@zabbix ~]# systemctl enable nginx php-fpm --now
[root@zabbix ~]# curl 127.0.0.1/info.php
二、安装数据库mariadb
1、安装mariadb
#配置mariadb的yum源
[root@zabbix ~]# vim /etc/yum.repos.d/mariadb.repo
[mariadb]
name=Mariadb
baseurl=http://mirrors.aliyun.com/mariadb/yum/10.5/centos7-amd64/
gpgkey=http://mirrors.aliyun.com/mariadb/yum/RPM-GPG-KEY-MariaDB
gpgcheck=1
enabled=1
#安装mariadb
[root@zabbix ~]# yum install mariadb-server -y
#启动并开机自启
[root@zabbix ~]# systemctl enable mariadb --now
2、初始化
#数据库的初始化
[root@zabbix ~]# mysql_secure_installation
Enter current password for root (enter for none): 直接回车,新用户没密码
Switch to unix_socket authentication [Y/n] 输入n
Change the root password? [Y/n] 输入Y,改root密码
Remove anonymous users? [Y/n] 输入Y
Disallow root login remotely? [Y/n] 输入Y
Remove test database and access to it? [Y/n] 输入Y
Reload privilege tables now? [Y/n] 输入Y
3、创建库和用户
[root@zabbix ~]# mysql -uroot -p
#创建数据库zabbix,字符集为utf8
MariaDB [(none)]> create database zabbix charset utf8 collate utf8_bin;
#创建用户zabbix,密码zabbix,并授权,只能在本地登录
MariaDB [(none)]> grant all on zabbix.* to 'zabbix'@'localhost' identified by 'zabbix';
4、导入数据
#下载包
[root@zabbix ~]# wget -c https://cdn.zabbix.com/zabbix/sources/stable/6.0/zabbix-6.0.25.tar.gz
[root@zabbix ~]# tar -xzvf zabbix-6.0.25.tar.gz
[root@zabbix ~]# cd zabbix-6.0.25/database/mysql/
#导入数据,注意顺序
#-p是密码
[root@zabbix mysql]# mysql -uroot -predhat zabbix <schema.sql
[root@zabbix mysql]# mysql -uroot -predhat zabbix <images.sql
[root@zabbix mysql]# mysql -uroot -predhat zabbix <data.sql
[root@zabbix mysql]# mysql -uroot -predhat zabbix <double.sql
[root@zabbix mysql]# mysql -uroot -predhat zabbix <history_pk_prepare.sql
三、编译安装zabbix-server?
[root@zabbix ~]# yum install -y mysql-devel pcre-devel openssl-devel zlib-devel libxml2-devel net-snmp-devel net-snmp libssh2-devel OpenIPMI-devel libevent-devel openldap-devel libcurl-devel gcc gcc-c++
[root@zabbix ~]# cd zabbix-6.0.25
[root@zabbix zabbix-6.0.14]# ./configure --sysconfdir=/etc/zabbix --enable-server --with-mysql --with-net-snmp --with-libxml2 --with-ssh2 --with-openipmi --with-zlib --with-libpthread --with-libevent --with-openssl --with-ldap --with-libcurl --with-libpcre
[root@zabbix zabbix-6.0.14]# make install
--sysconfdir=/etc/zabbix ?#指定配置文件路径
--enable-server ? ? ? ?#安装服务端
--with-mysql ? ? ? ?#开启数据库mysql的支持
#安装依赖与功能
--with-net-snmp --with-libxml2 --with-ssh2 --with-openipmi --with-zlib --with-libpthread --with-libevent --with-openssl --with-ldap --with-libcurl --with-libpcre?
2、修改配置文件
[root@zabbix zabbix-6.0.25]# vim /etc/zabbix/zabbix_server.conf
把DBHost=localhost和DBPassword=和ListenPort=10051前面的注释删掉,并且设置为DBPassword=zabbix。
注意:DBName为你的数据库名,DBUser为你的用户名,DBPassword为你的密码
启动zabbix-server
#由于编译安装zabbix服务端,需要添加虚拟用户
[root@zabbix zabbix-6.0.25]# useradd -s /usr/sbin/nologin -M zabbix
#启动zabbix
[root@zabbix zabbix-6.0.25]# zabbix_server
#检查zabbix进程
[root@zabbix zabbix-6.0.25]# ps -ef | grep zabbix
#检查zabbix端口
[root@zabbix zabbix-6.0.25]# ss -lntup | grep 10051
加自启动
[root@zabbix zabbix-6.0.25]# vim /usr/lib/systemd/system/zabbix-server.service
[Unit]
Description=Zabbix Server with Mysql DB
After=syslog.target network.target mysqld.service
[Service]
Type=simple
ExecStart=/usr/local/sbin/zabbix_server -f
User=zabbix
[Install]
WantedBy=multi-user.target
[root@zabbix zabbix-6.0.25]# systemctl reload
#需要先把手动的关闭,在systemctl
[root@zabbix zabbix-6.0.25]# pkill zabbix
[root@zabbix zabbix-6.0.25]# systemctl enable zabbix-server --now
#检查zabbix-server是否启动
[root@zabbix zabbix-6.0.25]# systemctl status zabbix-server
配置页面访问
[root@zabbix ~]# cp -r zabbix-6.0.25/ui/* /app/www/zabbix/
[root@zabbix ~]# chown -R nginx.nginx /app/www/zabbix/
修改配置
#修改比要求大的即可
[root@zabbix ~]# vim /etc/php.ini
post_max_size = 16M
max_input_time = 300
max_execution_time = 300
[root@zabbix ~]# systemctl restart php-fpm
四、安装zabbix-agent客户端
#从清华镜像下载zabbix源
[root@zabbix ~]# yum install -y https://mirrors.tuna.tsinghua.edu.cn/zabbix/zabbix/6.0/rhel/7/x86_64/zabbix-release-6.0-1.el7.noarch.rpm
#更换为清华的镜像
[root@zabbix ~]# sed -i 's#https://repo.zabbix.com/zabbix#https://mirrors.tuna.tsinghua.edu.cn/zabbix/zabbix#g' /etc/yum.repos.d/zabbix.repo
[root@zabbix ~]# yum install zabbix-agent2 -y
#修改配置文件,自我监控就不用,server为zabbix的服务端地址
[root@zabbix ~]# vim /etc/zabbix/zabbix_agent2.conf
Server=127.0.0.1
[root@zabbix ~]# systemctl enable zabbix-agent2 --now
再次查看页面,告警消失了
五、解决中文乱码问题
上传一个中文的ttf字体替换zabbix的即可,windows的字体路径C:\Windows\Fonts
[root@zabbix ~]# cd /app/www/zabbix/assets/fonts/
[root@zabbix fonts]# cp DejaVuSans.ttf{,.bak}
#用xftp上传字体,名字也要跟这个一样,我用的是微软雅黑
[root@zabbix fonts]# mv msyh.ttc DejaVuSans.ttf
mv: overwrite ‘DejaVuSans.ttf’? y
#重新刷新一下页面即可,不用重启
六、添加客户端主机
1、安装zabbix客户端
#安装依赖
[root@zabbix-2 ~]# yum install pcre2 pcre2-devel -y
#只需要安装个客户端即可
[root@zabbix-2 ~]# rpm -ivh https://mirrors.tuna.tsinghua.edu.cn/zabbix/zabbix/6.0/rhel/7/x86_64/zabbix-agent2-6.0.7-1.el7.x86_64.rpm
#配置zabbix服务端地址
[root@zabbix-2 ~]# sed -i '/^Server/s#127.0.0.1#10.4.7.10#g' /etc/zabbix/zabbix_agent2.conf
#启动并开机
[root@zabbix-2 ~]# systemctl enable zabbix-agent2 --now
2、web页面添加主机
[root@zabbix ~]# systemctl restart zabbix-server