Zabbix Server 采用源码包部署,数据库采用 MySQL8.0 版本,zabbix-web 使用 nginx+php 来实现。具体信息如下:
软件名 | 版本 | 安装方式 |
Zabbix Server | 6.0.3 | 源码安装 |
Zabbix Agent | 6.0.3 | 源码安装 |
MySQL | 8.0.28 | yum安装 |
Nginx | 1.20.1 | yum安装 |
Php | 7.4.29 | yum安装 |
官网参考文档:3 Installation from sources
1. 安装nginx
1.添加CentOS 7 Nginx yum资源库
yum -y install http://nginx.org/packages/centos/7/noarch/RPMS/nginx-release-centos-7-0.el7.ngx.noarch.rpm
2、安装nginx
[root@localhost ~]# yum -y install nginx //安装nginx
3.启动并设置开机自启
systemctl enable nginx
systemctl start nginx
4.检查端口和进程
ss -tuanlp|grep nginx
ps -ef|grep nginx
2. 安装php-fpm
1.安装源
yum install -y epel-release
yum install -y http://rpms.remirepo.net/enterprise/remi-release-7.rpm
2.安装YUM管理工具
yum -y install yum-utils
3. 查看PHP(可忽略此步骤)
yum search php74
4.安装PHP
yum install -y php74-php-gd php74-php-pdo php74-php-mbstring php74-php-cli php74-php-fpm php74-php-mysqlnd php74-php-pecl-redis6 php74-php-bcmath php74-php-xml php74-php-ldap
5.查询配置文件路径
# rpm -ql php74-php-fpm |grep www.conf
/etc/opt/remi/php74/php-fpm.d/www.conf
6.修改/etc/opt/remi/php74/php-fpm.d/www.conf中user和group为nginx
sed -i 's#user = apache#user = nginx#g' /etc/opt/remi/php74/php-fpm.d/www.conf
sed -i 's#group = apache#group = nginx#g' /etc/opt/remi/php74/php-fpm.d/www.conf
7.启动FPM
systemctl enable php74-php-fpm
systemctl start php74-php-fpm
3. 安装MySQL
3.1. 下载mysql源,安装,并修改密码
wget https://repo.mysql.com//mysql80-community-release-el7-7.noarch.rpm
rpm -ivh mysql80-community-release-el7-7.noarch.rpm
#修改为不校验
sed -i 's/gpgcheck=1/gpgcheck=0/g' /etc/yum.repos.d/mysql-community.repo
yum -y install mysql-community-server
mysql -V
systemctl restart mysqld
pass=`grep "temporary password" /var/log/mysqld.log|awk '{print $NF}'`
mysql -uroot -p$pass
mysql>alter user root@localhost identified by 'Mysql123...';
3.2. 创建zabbix需要的数据库
mysql> create database zabbix character set utf8 collate utf8_bin;
mysql> create user 'zabbix'@'%' identified by 'Zabbix123...';
mysql> grant all privileges on zabbix.* to 'zabbix'@'%' with grant option;
4. 安装Zabbix-server
下载软件包:Download Zabbix sources
4.1. 解压软件包
tar -zxvf zabbix-6.0.3.tar.gz
4.2. 创建 zabbix 用户
useradd zabbix -s /sbin/nologin
4.3. 初始化数据(进入解压目录下的 database 目录下)
cd zabbix-6.0.3/database/mysql
mysql -uzabbix -pZabbix123... zabbix < schema.sql
mysql -uzabbix -pZabbix123... zabbix < images.sql
mysql -uzabbix -pZabbix123... zabbix < data.sql
4.4. 安装编译所需的依赖,这里根据启用的模块不一样,所需要的依赖也不一样
yum install gcc mysql-devel libevent-devel libcurl-devel libxml2-devel libssh2-devel OpenIPMI-devel net-snmp-devel go java-devel -y
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
4.5. 进行编译安装
cd /app/tools/zabbix-6.0.31
./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-libcurl --with-libpcre
make install
4.6. 修改配置文件
]# egrep -v '^$|^#' /etc/zabbix/zabbix_server.conf
ListenPort=10051
LogFile=/tmp/zabbix_server.log
DBName=zabbix
DBUser=zabbix
DBPassword=Zabbix123...
Timeout=4
LogSlowQueries=3000
StatsAllowedIP=127.0.0.1
4.7. 配置systemd启动
cat <<EOF > /etc/systemd/system/zabbix-server.service
[Unit]
Description=Zabbix Server
After=syslog.target network.target network-online.target
[Service]
Type=simple
User=zabbix
ExecStart=/usr/local/sbin/zabbix_server -c /etc/zabbix/zabbix_server.conf
RemainAfterExit=yes
[Install]
WantedBy=multi-user.target
EOF
4.8. 加入开机启动并启动
systemctl daemon-reload
systemctl enable zabbix-server --now
systemctl status zabbix-server
ps -ef|grep zabbix-server
5. 安装zabbix-web
5.1. 修改zabbix依赖php的相关配置,/etc/opt/remi/php74/php.ini
]# egrep -n '^(max_.*_time|post_max)' /etc/opt/remi/php74/php.ini
388:max_execution_time = 300
398:max_input_time = 600
694:post_max_size = 80M
systemctl restart php74-php-fpm.service
5.2. 添加nginx的zabbix域名相关
]# cat /etc/nginx/conf.d/zabbix.conf
server {
listen 80;
server_name zabbix.tom.cn;
root /app/code/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;
fastcgi_param SCRIPT_NAME $fastcgi_script_name;
include fastcgi_params;
}
}
5.3. 将 Zabbix 源码包中的 PHP 文件复制到 Nginx 的根目录下。
mkdir -p /app/code/zabbix
cp -r /app/tools/zabbix-6.0.31/ui/* /app/code/zabbix
chown -R nginx.nginx /app/code/zabbix/
5.4. 重启nginx
nginx -t
systemctl restart nginx
6. Web界面配置
6.1. 访问Web界面,如下图,并选择自己所使用的语言
6.2. 基础环境检测
6.3. 配置数据库连接信息
6.4. 配置主机名称和时区
6.5. 检查配置
6.6. 配置完成后如下图所示,点击完成。
6.7. 进入登陆界面(默认账号/密码:Admin/zabbix)
7. 启用zabbix-agent
rpm -ivh https://mirrors.tuna.tsinghua.edu.cn/zabbix/zabbix/6.0/rhel/7/x86_64/zabbix-release-6.0-4.el7.noarch.rpm
sed -i 's#https://repo.zabbix.com/zabbix#https://mirrors.tuna.tsinghua.edu.cn/zabbix/zabbix/#g' /etc/yum.repos.d/zabbix.repo
yum install -y zabbix-agent2
]# egrep '^Server' /etc/zabbix/zabbix_agent2.conf
Server=127.0.0.1
ServerActive=127.0.0.1
systemctl enable zabbix-agent2.service
systemctl start zabbix-agent2.service
systemctl status zabbix-agent2.service