CentOS Linux release 8.1.1911 (Core) x86_64
最小化安装
安装好操作系统后,关闭防火墙和 selinux 并重启
sed -i 's/SELINUX=enforcing/SELINUX=disabled/' /etc/selinux/config
systemctl disable --now firewalld
reboot
使用 dnf 安装 lnmp 等基础环境包
dnf install httpd php php-gd php-ldap php-mysqlnd php-json php-bcmath php-mbstring php-xml mysql mysql-server mysql-devel libevent-devel pcre-devel gcc gcc-c++ make libcurl-devel curl-* net-snmp* libxml2-* wget tar -y
useradd zabbix
启动相关组件并配置开机启动
systemctl enable --now httpd mysqld php-fpm
安装配置
安装好启动 http,mysql 等服务,并使用 mysql_secure_installation 命令初始化 mysql 下载 zabbix5.0 源码,解压并编译
cd /opt
wget https://cdn.zabbix.com/zabbix/sources/stable/5.0/zabbix-5.0.0.tar.gz
tar zxvf zabbix-5.0.0.tar.gz
cd zabbix-5.0.0
./configure --prefix=/usr/local/zabbix --enable-server --enable-agent \
--with-mysql --with-net-snmp --with-libcurl --with-libxml2
make
make install
使用 mysql 的 root 用户登录 mysql 数据库,建立 zabbix 数据库用户等相关信息
create database zabbix character set utf8 collate utf8_bin;
create user zabbix@localhost identified by 'password';
grant all privileges on zabbix.* to zabbix@localhost;
quit
按照顺序,依次导入 sql
mysql -uzabbix -p zabbix < /opt/zabbix-5.0.0/database/mysql/schema.sql
mysql -uzabbix -p zabbix < /opt/zabbix-5.0.0/database/mysql/images.sql
mysql -uzabbix -p zabbix < /opt/zabbix-5.0.0/database/mysql/data.sql
修改 zabbix server 配置文件/usr/local/zabbix/etc/zabbix_server.conf,修改数据库密码
...
DBPassword=password
...
为 zabibx server 添加 systemd 启动文件
vi /lib/systemd/system/zabbix-server.service
内容如下
[Unit]
Description=Zabbix Server
After=syslog.target
After=network.target
After=mysql.service
After=mysqld.service
After=mariadb.service
After=postgresql.service
[Service]
Environment="CONFFILE=/usr/local/zabbix/etc/zabbix_server.conf"
EnvironmentFile=-/etc/sysconfig/zabbix-server
Type=forking
Restart=on-failure
PIDFile=/tmp/zabbix_server.pid
KillMode=control-group
ExecStart=/usr/local/zabbix/sbin/zabbix_server -c $CONFFILE
ExecStop=/bin/kill -SIGTERM $MAINPID
RestartSec=10s
TimeoutSec=0
[Install]
WantedBy=multi-user.target
为 zabbix agent 添加 systemd 启动文件
vi /lib/systemd/system/zabbix-agent.service
内容如下
[Unit]
Description=Zabbix Agent
After=syslog.target
After=network.target
[Service]
Environment="CONFFILE=/usr/local/zabbix/etc/zabbix_agentd.conf"
EnvironmentFile=-/etc/sysconfig/zabbix-agent
Type=forking
Restart=on-failure
PIDFile=/tmp/zabbix_agentd.pid
KillMode=control-group
ExecStart=/usr/local/zabbix/sbin/zabbix_agentd -c $CONFFILE
ExecStop=/bin/kill -SIGTERM $MAINPID
RestartSec=10s
User=zabbix
Group=zabbix
[Install]
WantedBy=multi-user.target
启动 zabbix server 和 zabbix agent,并配置开机启动
systemctl enable --now zabbix-server
systemctl enable --now zabbix-agent
前端安装
拷贝 zabbix 前端文件到 apache 默认 web 目录
cp -r /opt/zabbix-5.0.0/ui/* /var/www/html/
chown -R apache:apache /var/www/html/
配置 php 参数
sed -i 's#post_max_size = 8M#post_max_size = 16M#' /etc/php.ini
sed -i 's#max_execution_time = 30#max_execution_time = 300#' /etc/php.ini
sed -i 's#max_input_time = 60#max_input_time = 300#' /etc/php.ini
sed -i 's#;date.timezone =#date.timezone = Asia/Shanghai#' /etc/php.ini
systemctl restart php-fpm
配置后使用浏览器访问http://ip/ 就可以访问 zabbix 页面了.
WEB 初始化
检查各个组件配置是否正常
输入配置数据库 zabbix 用户的密码
登录账号为 Admin,密码:zabbix