zabbix的安装避坑指南

Posted 武云医生

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了zabbix的安装避坑指南相关的知识,希望对你有一定的参考价值。

(1)zabbix的服务端的安装:

①zabbix部署流程规划:

1、centos7不支持yum安装服务端,客户端可以yum安装



2、部署ngx+php环境并测试



3、部署数据库 mariadb 10.5以及上



4、编译安装zabbix-server服务器以及后端配置



5、部署前端代码进行访问



6、web访问




②部署nginx+php:

1、yum -y isntall nginx

[root@zabbix-server conf.d]# cat zabbix.conf

server

listen 80;

server_name localhost;

access_log /var/log/nginx/she-access.log main;

error_log /var/log/nginx/she-error.log notice;

root /app/code/zbx;


#静态

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;


[root@zabbix-server conf.d]#



2、[root@zabbix-server zabbix-6.0.5]# yum install -y php72w-cli php72w-fpm php72w-gd php72w-mbstring php72w-bcmath php72w-xml php72w-ldap php72w-mysqlnd -y



3、修改php的配置:

[root@zabbix-server conf.d]# grep nginx /etc/php-fpm.d/www.conf

user = nginx

group = nginx

[root@zabbix-server conf.d]#



4、启动:

[root@zabbix-server tmp]# systemctl enable php-fpm.service

[root@zabbix-server tmp]# systemctl enable nginx

[root@zabbix-server tmp]# systemctl start php-fpm.service

[root@zabbix-server tmp]# systemctl start nginx



5、测试php:

[root@zabbix-server code]# cat zbx/info.php

<?php

phpinfo();

?>

[root@zabbix-server code]#



6、查看是否出现页面,看php是否配合nginx:

​http://120.48.55.178/info.php​




③部署数据库:

1、zabbix 6.0不支持mariadb5.5要安装mariddb10.0以上



2、配置mariadb yum源:

[root@zabbix-server ~]# cat /etc/yum.repos.d/mariddb.repo

# MariaDB 10.5 CentOS repository list - created 2022-06-24 08:48 UTC

# https://mariadb.org/download/

[mariadb]

name = MariaDB

baseurl = https://tw1.mirror.blendbyte.net/mariadb/yum/10.5/centos7-amd64

gpgkey=https://tw1.mirror.blendbyte.net/mariadb/yum/RPM-GPG-KEY-MariaDB

gpgcheck=0


[root@zabbix-server ~]# yum install -y MariaDB-server MariaDB-client



3、检查是否安装:

[root@zabbix-server code]# rpm -qa |grep -i mariadb

MariaDB-common-10.5.16-1.el7.centos.x86_64

MariaDB-server-10.5.16-1.el7.centos.x86_64

MariaDB-compat-10.5.16-1.el7.centos.x86_64

MariaDB-client-10.5.16-1.el7.centos.x86_64

[root@zabbix-server code]#



4、启动:

[root@zabbix-server code]# systemctl enable mariadb

[root@zabbix-server code]# systemctl start mariadb



5、数据库初始化:{仅一次}

[root@zabbix-server code]# mysql_secure_installation

You already have your root account protected, so you can safely answer n. <新数据库没密码输n>


Switch to unix_socket authentication [Y/n] n <输n>

... skipping.


You already have your root account protected, so you can safely answer n.


Change the root password? [Y/n] y <修改一个数据库root的密码>



Remove anonymous users? [Y/n] y <y>

... Success!



Disallow root login remotely? [Y/n] y <y>

... Success!

e moving into a production environment.


Remove test database and access to it? [Y/n] y <y>



Reload privilege tables now? [Y/n] y <y>

... Success!


[root@zabbix-server code]#



6、创建库:

[root@zabbix-server code]# mysql -uroot -p

MariaDB [(none)]> create database zabbix charset utf8 collate utf8_bin;

Query OK, 1 row affected (0.000 sec)


MariaDB [(none)]> grant all on zabbix.* to zabbix@localhost identified by zabbix;

Query OK, 0 rows affected (0.001 sec)


MariaDB [(none)]>



7、向数据库中导入数据:{注意导入顺序-不能错千万}

1.下载源码包:https://cdn.zabbix.com/zabbix/sources/stable/6.0/zabbix-6.0.5.tar.gz



2.导入:

[root@zabbix-server database]# cd /tmp/zabbix-6.0.5/database/mysql/

[root@zabbix-server mysql]# ls -lh

total 33M

-rw-r--r-- 1 1000 1000 31M May 30 14:23 data.sql

-rw-r--r-- 1 1000 1000 282 May 30 14:22 double.sql

-rw-r--r-- 1 1000 1000 1.5K May 30 14:22 history_pk_prepare.sql

-rw-r--r-- 1 1000 1000 1.9M May 2 16:26 images.sql

-rw-r--r-- 1 1000 1000 508 May 30 14:22 Makefile.am

-rw-r--r-- 1 1000 1000 16K May 30 14:22 Makefile.in

-rw-r--r-- 1 1000 1000 161K May 30 14:23 schema.sql

[root@zabbix-server mysql]#

[root@zabbix-server mysql]# pwd

/tmp/zabbix-6.0.5/database/mysql

[root@zabbix-server mysql]# mysql -uroot -pmima zabbix < schema.sql

[root@zabbix-server mysql]# mysql -uroot -pmima zabbix < images.sql

[root@zabbix-server mysql]# mysql -uroot -pmima zabbix < data.sql

[root@zabbix-server mysql]# mysql -uroot -pmima zabbix < double.sql

[root@zabbix-server mysql]# mysql -uroot -pmima zabbix < history_pk_prepare.sql




④编译安装zabbix:

1、安装依赖:

[root@zabbix-server zabbix-6.0.5]# 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



2、进行配置:

[root@zabbix-server zabbix-6.0.5]# ./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


编译成功的提示:

Configuration file: /etc/zabbix/zabbix_server.conf

External scripts: /usr/local/share/zabbix/externalscripts

Alert scripts: /usr/local/share/zabbix/alertscripts

Modules: /usr/local/lib/modules



3、编译:

[root@zabbix-server zabbix-6.0.5]# make install



4、检查:

root@zabbix-server zabbix-6.0.5]# zabbix_server --version

zabbix_server (Zabbix) 6.0.5

Revision 8da3e1f8419 30 May 2022, compilation time: Jun 24 2022 20:31:28


Copyright (C) 2022 Zabbix SIA

License GPLv2+: GNU GPL version 2 or later <http://gnu.org/licenses/gpl.html>.

This is free software: you are free to change and redistribute it according to

the license. There is NO WARRANTY, to the extent permitted by law.


This product includes software developed by the OpenSSL Project

for use in the OpenSSL Toolkit (http://www.openssl.org/).


Compiled with OpenSSL 1.0.2k-fips 26 Jan 2017

Running with OpenSSL 1.0.2k-fips 26 Jan 2017

[root@zabbix-server zabbix-6.0.5]#




⑤修改zabbix的配置文件:

1、修改配置文件:

[root@zabbix-server ~]# grep -n ^[a-Z] /etc/zabbix/zabbix_server.conf

12:ListenPort=10051

38:LogFile=/tmp/zabbix_server.log

99:DBName=zabbix

115:DBUser=zabbix

123:DBPassword=zabbix

507:Timeout=4

593:LogSlowQueries=3000

708:StatsAllowedIP=127.0.0.1

[root@zabbix-server ~]#



2、添加zabbix的用户:

[root@zabbix-server ~]# useradd -s /sbin/nolging -M zabbix

[root@zabbix-server ~]#



3、检查zabbix:

[root@zabbix-server ~]# ps -ef|grep zabbix

[root@zabbix-server ~]# netstat -tulnp|grep zabbix

tcp 0 0 0.0.0.0:10051 0.0.0.0:* LISTEN 30417/zabbix_server

[root@zabbix-server ~]#




⑥给zabbix增加systemcctl的管理:

1、管理的书写:

[root@zabbix-server ~]# cat /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-server ~]# systemctl daemon-reload

[root@zabbix-server ~]#



2、 重启进程:

[root@zabbix-server ~]# pkill zabbix

[root@zabbix-server ~]# ps -ef|grep zabbix

root 31302 29428 0 22:59 pts/3 00:00:00 grep --color=auto zabbix

[root@zabbix-server ~]# systemctl enable zabbix-server.service

Created symlink from /etc/systemd/system/multi-user.target.wants/zabbix-server.service to /usr/lib/systemd/system/zabbix-server.service.


[root@zabbix-server ~]# systemctl start zabbix-server.service

[root@zabbix-server ~]#




⑦zabbix前端代码的部署:

[root@zabbix-server zabbix-6.0.5]# pwd

/root/zabbix-6.0.5

[root@zabbix-server zabbix-6.0.5]# cp -a ui/* /app/code/zbx/

[root@zabbix-server zabbix-6.0.5]# chown -R nginx.nginx /app/code/zbx/

[root@zabbix-server zabbix-6.0.5]#




⑧安装zabbix:

1、安装:

​http://120.48.55.178/setup.php​



2、报错:{第四个是由于依赖没安装,步骤已经补在前面了}

zabbix的安装避坑指南_nginx



3、去修改php的配置:

[root@zabbix-server /]# grep -E -n ^(max_.*_time|post_max) /etc/php.ini

368:max_execution_time = 600

378:max_input_time = 600

656:post_max_size = 80M

[root@zabbix-server /]#

[root@zabbix-server /]# systemctl restart nginx

[root@zabbix-server /]# systemctl restart php-fpm.service

[root@zabbix-server /]#



4、配置php连接数据库:{zabbix连接数据库是配置文件中定义的}

zabbix的安装避坑指南_mysql_02



5、给你的zabbix起一个名字:

zabbix的安装避坑指南_php_03




6、最终确认:




⑨登录:{账户Admin密码zabbix}

​http://120.48.55.178/zabbix.php?action=dashboard.view​





(2)安装zabbix客户端:

①安装一个agine的客户端:

1、先安装一个源:

[root@zabbix-server zabbix-6.0.5]# rpm -ivh https://mirrors.tuna.tsinghua.edu.cn/zabbix/zabbix/6.0/rhel/7/x86_64/zabbix-release-6.0-1.el7.noarch.rpm



2、查看这个源里有没有zabbix-agent2:

[root@zabbix-server zabbix-6.0.5]# yum list|grep zabbix-agent2

zabbix-agent2.x86_64 6.0.5-1.el7 zabbix

[root@zabbix-server zabbix-6.0.5]#



3、安装:{在线安装}太XX慢了

[root@zabbix-server zabbix-6.0.5]# yum -y install zabbix-agent2


更换源:

[root@zabbix-server ~]# sed -i s#https://repo.zabbix.com/zabbix#https://mirrors.tuna.tsinghua.edu.cn/zabbix/zabbix#g /etc/yum.repos.d/zabbix.repo



4:{或者离线安装}

[root@zabbix-server ~]# wget https://mirrors.tuna.tsinghua.edu.cn/zabbix/zabbix/6.0/rhel/7/x86_64/zabbix-agent2-6.0.5-1.el7.x86_64.rpm --no-check-certificate


[root@zabbix-server ~]# rpm -ivh zabbix-agent2-6.0.5-1.el7.x86_64.rpm



7、修改客户端:{地址修改为服务器的ip,现在是在一起所以不用改}

[root@zabbix-server ~]# grep -E ^[Server] /etc/zabbix/zabbix_agent2.conf

Server=127.0.0.1

ServerActive=127.0.0.1

[root@zabbix-server ~]#



8、启动zabbix客户端:

[root@zabbix-server ~]# systemctl start zabbix-agent2.service


[root@zabbix-server ~]# systemctl enable zabbix-agent2.service

Created symlink from /etc/systemd/system/multi-user.target.wants/zabbix-agent2.service to /usr/lib/systemd/system/zabbix-agent2.service.

[root@zabbix-server ~]#



9、检查:

[root@zabbix-server ~]# ps -ef|grep agent2

zabbix 5556 1 0 01:07 ? 00:00:00 /usr/sbin/zabbix_agent2 -c /etc/zabbix/zabbix_agent2.conf

root 5577 29428 0 01:07 pts/3 00:00:00 grep --color=auto agent2

[root@zabbix-server ~]# netstat -tulpn|grep agent2

tcp6 0 0 :::10050 :::* LISTEN 5556/zabbix_agent2



10、查看结果:

zabbix的安装避坑指南_mysql_04

以上是关于zabbix的安装避坑指南的主要内容,如果未能解决你的问题,请参考以下文章

Ubuntu安装ssh服务(避坑指南)

2019 MySQL 8 安全安装避坑指南

吐血经验在 windows 上安装 spark 遇到的一些坑 | 避坑指南

安装Seafile Server 7.1.3 不完全避坑指南

Nginx常用配置,避坑指南!

Windows 下安装 tensorflow & keras & opencv 的避坑指南!