Centos7 compile and install zabbix-5.0 server side (super detailed) and configure and start Agent

One, compile and install zabbix

1. Environment

1. System: Alibaba Cloud Centos7
2. Ensure that the LNMP environment is installed.

LNMP environment: linux+Nginx + Mysql + PHP ①Compile and
install MySQL database 5.7 tutorial:
https://blog.csdn.net/weixin_44901564/article/details/108198348
Set up nginx service
https://blog.csdn.net/weixin_44901564/article/details/108170765
③ A detailed tutorial for installing php7.3 on Alibaba Cloud centos7.6 (super detailed)
https://blog.csdn.net/weixin_44901564/article /details/108167186

Download the zabbix-5.0.7 source package
① Visit the website: https://www.zabbix.com/cn/download
② Select Zabbix Source, as shown in the figure below:
Insert picture description here
③ Select Zabbix 5.0 LTS, and then click to download
Insert picture description here

2. Compile and install process

I plan to install zabbix in the ~/optdirectory and move the source code compressed package to the ~/optdirectory. . . ①Unzip the
source package
[ops@test1 ~/opt]$ tar -zxvf zabbix-5.0.7.tar.gz
[ops@test1 ~/opt]$ cd zabbix-5.0.7/

②安装依赖包
[ops@test1 ~/opt/zabbix-5.0.7]$ sudo yum -y install unixODBC-devel net-snmp-devel libevent-devel libxml2-devel libcurl-devel java-1.6.0-openjdk-devel
如果配置添加了--enable-java,则需要安装依赖包java-1.6.0-openjdk-devel
③编译安装
[ops@test1 ~/opt/zabbix-5.0.7]$ ./configure --prefix=/home/ops/opt/zabbix-server --enable-server --enable-agent --enable-proxy --with-mysql=/home/ops/opt/mysql/bin/mysql_config --with-net-snmp --with-libcurl --with-libxml2 --with-unixodbc --enable-java

--prefix=/home/ops/opt/zabbix-server 				//编译安装路径
--enable-server  									//启动服务端 ,安装部署zabbix服务器端软件
--enable-agent  									//安装部署zabbix被监控端软件
--enable-proxy 										//安装部署zabbix代理相关软件
--with-mysql=/home/ops/opt/mysql/bin/mysql_config   //编译连接mysql相关依赖包,并指定mysql_config的路径
--with-net-snmp 				//启动snmp相关,用于snmp监控设备,允许zabbix通过snmp协议监控其他设备
--with-libcurl 					//安装相关curl库文件,这样zabbix就可以通过curl连接http等服务,测试被监控主机服务的状态
--with-libxml2 					//启动xml相关
--with-unixodbc 				//启动odbc相关,用于监控数据库
--enable-java 					//启动java相关

[ops@test1 ~/opt/zabbix-5.0.7]$ make && make install

④Initialize the database information, create the database, and go online to Zabbix's Web page. The
database file is in the zabbix-5.0.7 directory after decompression, the specific path: zabbix-5.0.2/database/mysql, and import them in order:
schema.sql
images. sql
data.sql

[ops@test1 ~/opt/zabbix-5.0.7]$ mysql -uroot -p'123456'
mysql> create database zabbix_server character set UTF8 collate utf8_bin; //Create database, support Chinese character set, and specify collation utf8_bin

#mysql> grant all on zabbix.* to zabbix@'localhost' identified by'zabbix';
//Create an account and password that can access the database, I am using the root user, so I don’t need this step

[ops@test1 ~/opt/zabbix-5.0.7]$ mysql -uroot -p’123456’ zabbix_server < database/mysql/schema.sql
[ops@test1 ~/opt/zabbix-5.0.7]$ mysql -uroot -p’123456’ zabbix_server < database/mysql/images.sql
[ops@test1 ~/opt/zabbix-5.0.7]$ mysql -uroot -p’123456’ zabbix_server < database/mysql/data.sql

⑤Configure zabbix_server.conf configuration file
[ops@test1 ~/opt/zabbix-5.0.7]$ cd /home/ops/opt/zabbix-server/
[ops@test1 ~/opt/zabbix-server]$ vim etc/ zabbix_server.conf
searches for the following field modifications:

DBHost=localhost
DBName=zabbix_server          //数据库名
DBUser=root                   //连接数据库的用户
DBPassword=123456             //密码
DBSocket=/home/ops/opt/mysql/mysql.sock                //数据库sock文件路径
DBPort=3306                   //端口
LogFile=/home/ops/opt/zabbix_server/zabbix_server.log  //日志文件
PidFile=/home/ops/opt/zabbix_server/zabbix_server.pid  //保存pid的文件
SocketDir=/home/ops/opt/zabbix                         //保存sock文件的目录

⑥Add the mysql lib directory to the lib environment variable
[ops@test1 ~/opt/zabbix-server]$ echo'/home/ops/opt/mysql/lib/'> /etc/ld.so.conf.d/ mysql.conf #Because it is installed by a common user, you need to switch to the root user to do this step by yourself. Otherwise, the echo command does not support sudo
[ops@test1 ~/opt/zabbix-server]$ ldconfig -v


⑦Start zabbix -server [ops@test1 ~/opt/zabbix-server]$ /home/ops/opt/zabbix-server/sbin/zabbix_server -c /home/ops/opt/zabbix-server/etc/zabbix_server.conf
If you encounter an error: it /home/ops/opt/zabbix/sbin/zabbix_server: error while loading shared libraries: libmysqlclient.so.20: cannot open shared object file: No such file or directory
is because there was a problem with the command input when the mysql lib directory was added to the lib environment variable. Pay attention to the Chinese and English characters'/home/ops/opt/mysql/lib/', and the single quotes are English symbols. That's right
⑧Configure the front-end interface of zabbix-server. The front-
end interface is in the ui directory under the zabbix source package. Copy the front-end files to the html of nginx
[ops@test1 ~/opt/zabbix-server]$ cd /home/ops/opt /zabbix-5.0.7/ui
[ops@test1 ~/opt/zabbix-5.0.7/ui]$ cp -r * /home/ops/opt/nginx/html/

⑨Configure nginx to
enable php support of nginx service
[ops@test1 ~/opt/zabbix-server]$ vim /home/ops/opt/nginx/conf/nginx.conf

上面配置已省略:
     location / {
    
    
            root   html;
            index  index.php index.htm;
        }
        location ~ \.php$ {
    
    
            root           html;
            fastcgi_pass   127.0.0.1:9000;
            fastcgi_index  index.php;
            fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
            include        fastcgi.conf;
        }

⑩ Start nginx
[ops@test1 ~/opt/zabbix-server]$ /home/ops/opt/nginx/sbin/nginx
Of course, if you have made a soft link, you can start it directly with the soft link.

11. Configure php-fpm to
edit the php.ini file, this file is specified when installing php, for example, my php.ini file path is /home/ops/opt/php/lib/php.ini
[ops@test1 ~/opt/zabbix-server]$ vim /home/ops/opt/php/lib/php.ini
modify the following parameters:

post_max_size = 16M
max_execution_time = 300
max_input_time = 300
date.timezone =Asia/Shanghai
mysqli.default_socket = /home/ops/opt/mysql/mysql.sock     #此sock文件按mysql实际运行生成的sock文件为准
pdo_mysql.default_socket= /home/ops/opt/mysql/mysql.sock   #此sock文件按mysql实际运行生成的sock文件为准

12. Restart php-fpm
[ops@test1 ~/opt/zabbix-server]$ sudo systemctl restart php-fpm

13. Open a browser and access zabbix
Insert picture description here
direct point Next step to
display a red font Fail said correctly, you can click on Next step can be, but if the red font Fail appears, as shown below:
Insert picture description here
this illustrates the configuration file php.ini If there is a problem, you need to modify the wrong field post_max_size = 16M
max_execution_time = 300
max_input_time = 300 date.timezone
=Asia/Shanghai (this can also be written for other, generally use this)

After the error processing is completed, click Next step and I
Insert picture description here
also encounter a pit here. Click Next step to report the error and cannot skip to the next step. The error screenshot is as follows:
Insert picture description here
Reason: This is because of the character set when creating the zabbix database (zabbix_server library created above) The
solution caused by the encoding problem : delete the zabbix_server database from mysql, recreate the zabbix_server database, pay attention to the use of the command:
create database zabbix_server character set UTF8 collate
utf8_bin ; reimport the schema.sql, images.sql, data.sql files after creating the zabbix_server database
After processing, click Next step to proceed to the next step

Fill in the database connection information correctly here, and click Next step after filling in
Insert picture description here

Fill in the Name by yourself, optional.
Click Next step.
Insert picture description here
Click Next step. After
Insert picture description here
processing, click Finish.
Insert picture description here
Click Finish.
Insert picture description here
Account: Admin
Password: zabbix
Fill in the information to log in
[Insert picture description here](https://img-blog.csdnimg.cn/20210114160651191.png

2. Modify the agent configuration file and start the agent

① Modify the configuration
[ops@test1 ~/opt/zabbix-server]$ cd /home/ops/opt/zabbix/etc
[ops@test1 ~/opt/zabbix-server/etc]$ vim zabbix_agentd.conf
Modify the following configuration:

Server=127.0.0.1             //谁可以监控本机(被动监控模式),如果有多个主机可以监控本机,则填写ip使用逗号隔开,例如:127.0.0.1,192.168.2.5 
ServerActive=127.0.0.1       //谁可以监控本机(主动监控模式)
Hostname=web1   //被监控端自己的主机名,在zabbix web页面Monitoring->Configuration->Hosts 页面更改Host name和zabbix_agentd.conf里面的Hostname一样
#EnableRemoteCommands=1       //监控异常后,是否允许服务器远程过来执行命令,如重启某个服务
UnsafeUserParameters=1       //是否允许自定义key监控

②启动Agent
[ops@test1 ~/opt/zabbix-server/etc]$ /home/ops/opt/zabbix/sbin/zabbix_agentd -c /home/ops/opt/zabbix/etc/zabbix_agentd.conf

③ view the process
Insert picture description here
④ view the boot log
Insert picture description here
error, normal
if there is an error in the following figure:
Insert picture description here
Reason: zabbix web page Monitoring-> Configuration-> Hosts page to change the Host name and zabbix_agentd.conf inside Hostname to differ

Solution: Modify the Hostname on both sides to be consistent, and restart the Agent.

Guess you like

Origin blog.csdn.net/weixin_44901564/article/details/112577130