doina

一个小菜鸟运维工程师.

zabbix 5.0 安装初体验

1. zabbix安装

1.1. 安装依赖

yum -y install nginx 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 nginx mysqld php-fpm

1.2. 编译安装

cd /usr/local/src
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

1.3. 创建数据库及数据库用户

create database zabbix character set utf8 collate utf8_bin;
create user zabbix@localhost identified by 'Zabbix@Passw0rd';
grant all privileges on zabbix.* to zabbix@localhost;
quit

1.4. 还原数据库

mysql -uzabbix -pZabbix@Passw0rd zabbix < /usr/local/src/zabbix-5.0.0/database/mysql/schema.sql
mysql -uzabbix -pZabbix@Passw0rd zabbix < /usr/local/src/zabbix-5.0.0/database/mysql/images.sql
mysql -uzabbix -pZabbix@Passw0rd zabbix < /usr/local/src/zabbix-5.0.0/database/mysql/data.sql

修改 zabbix server 配置文件/usr/local/zabbix/etc/zabbix_server.conf,修改数据库密码

vi /usr/local/zabbix/etc/zabbix_server.conf
...
DBPassword=Zabbix@Passw0rd
...

1.5. 服务文件

为 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

2. 前端安装

这里nginx是编译安装好的, yum安装需要根据实际位置来调整

cp -r /usr/local/src/zabbix-5.0.0/ui/* /usr/local/nginx/html/zabbix
chown -R zabbix.zabbix /usr/local/nginx/html/zabbix/
chmod -R 777 /var/lib/php/session/ #否则会报: PHP Fatal error:  Uncaught Exception: Cannot start session.

配置 nginx

# cat /usr/local/nginx/conf/vhost/zabbix.baiyongjie.com.conf 
server {
    listen 80;
    server_name zabbix.baiyongjie.com;

    index  index.html index.php;
    root /usr/local/nginx/html;

    allow 61.148.212.141/32;
    deny all;

    access_log logs/zabbix.log;

    location ~ \.php$ {
        include fastcgi_params;
        fastcgi_pass 127.0.0.1:9000;
        fastcgi_index index.php;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    }
}

配置 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

3. 配置zabbix

配置后使用浏览器访问http://ip/zabbix 就可以访问 zabbix 页面了

《zabbix 5.0 安装初体验》

登录账号为 Admin,密码:zabbix

《zabbix 5.0 安装初体验》

《zabbix 5.0 安装初体验》

点赞

发表评论

电子邮件地址不会被公开。

此站点使用Akismet来减少垃圾评论。了解我们如何处理您的评论数据