zabbix6.0 LTS安装部署
一、安装环境
主机应用 | ip地址 | 部署环境 和版本 |
---|---|---|
zabbix app | 10.0.100.110 | centos-7.9,zabbix-6.0LTS,nginx-1.20.4,php-7.4.10, |
zabbix mysql数据库 | 10.0.100.120 | centos-7.9,mysql-8.0.28 |
二、安装nginx
# 关闭selinux
$ sed -i 's/enforcing/disabled/' /etc/selinux/config #永久
$ setenforce 0 # 临时
# 创建nginx用户和用户组:
$ groupadd -f nginx
$ useradd -g nginx nginx
# 配置好系统yum源,安装如下依赖包:
$ yum install gcc pcre-devel openssl-devel
# 下载上传 nginx-1.20.2.tar.gz至服务器,解压文件包命令如下:
$ tar -xvf nginx-1.20.2.tar.gz
# 安装编译nginx命令如下:
$ ./configure --group=nginx --user=nginx --prefix=/app/nginx --conf-path=/app/nginx/etc/nginx/nginx.conf --error-log-path=/app/nginx/logs/error.log --http-log-path=/app/nginx/logs/access.log --http-client-body-temp-path=/app/nginx/tmp/nginx/client_body --http-proxy-temp-path=/app/nginx/tmp/nginx/proxy --http-fastcgi-temp-path=/app/nginx/tmp/nginx/fastcgi --pid-path=/app/nginx/logs/nginx.pid --lock-path=/app/nginx/lock/nginx --with-http_stub_status_module --with-http_ssl_module --with-http_gzip_static_module --with-pcre
$ make && make install
# 配置nginx.conf,修改如下内容
**************************************************************************
location / {
root /app/nginx/html/zabbix;
try_files $uri $uri/ /index.php?query_string;
index index.php index.html index.htm;
}
location ~ \.php$ {
root /app/nginx/html/zabbix;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
**************************************************************************
# 配置nginx开机自启动服务
# 1、创建/usr/lib/systemd/system/nginx.service文件,输入如下内容:
$ vi /usr/lib/systemd/system/nginx.service
**************************************************************************
[Unit]
Description=nginx - high performance web server
Documentation=http://nginx.org/en/docs/
After=network.target remote-fs.target nss-lookup.target
[Service]
Type=forking
PIDFile=/app/nginx/logs/nginx.pid
ExecStartPre=/app/nginx/sbin/nginx -t -c /app/nginx/etc/nginx/nginx.conf
ExecStart=/app/nginx/sbin/nginx -c /app/nginx/etc/nginx/nginx.conf
ExecReload=/bin/kill -s HUP $MAINPID
ExecStop=/bin/kill -s QUIT $MAINPID
PrivateTmp=true
[Install]
WantedBy=multi-user.target
**************************************************************************
# 2、重载系统服务:
$ systemctl daemon-reload
# 3、设置开机启动:
$ mkdir -p /app/nginx/tmp/nginx/client_body
$ systemctl enable nginx.service
$ systemctl start nginx.service
三、安装php
# 下载安装如下依赖包
$ yum install libxml2-devel sqlite-devel libcurl-devel libpng-devel libjpeg-turbo-devel libXpm-devel freetype-devel libicu-devel gcc-c++ libxslt-devel oniguruma-devel libsodium-devel openldap-devel net-snmp-devel libwebp-devel
# 如果yum源没有oniguruma oniguruma-devel libsodium libsodium-devel libwebp-devel安装包,则需要从网上下载安装。
$ rpm -ivh oniguruma-6.7.0-1.el7.x86_64.rpm oniguruma-devel-6.7.0-1.el7.x86_64.rpm
$ rpm -ivh libsodium-1.0.18-2.el7.x86_64.rpm libsodium-devel-1.0.18-2.el7.x86_64.rpm
$ cp -frp /usr/lib64/libldap* /usr/lib/
# centos7.9系统自带libzip-0.10.1-8版本太低,PHP不支持,所以源码安装libzip-1.2.0
$ ./configure
$ make && make install
$ export PKG_CONFIG_PATH="/usr/local/lib/pkgconfig/"
# 源码安装php,需要在root环境下编译,否则会提示libzip错误
$ tar -xvf php-7.4.10.tar.gz
$ ./configure --prefix=/usr/local/php --with-config-file-path=/usr/local/php/etc --with-config-file-scan-dir=/usr/local/php/conf.d --enable-fpm --with-fpm-user=nginx --with-fpm-group=nginx --enable-mysqlnd --with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd --with-iconv-dir=/usr/local/php --with-freetype --with-jpeg --with-zlib --enable-xml --disable-rpath --enable-bcmath --enable-shmop --enable-sysvsem --enable-inline-optimization --with-curl --enable-mbregex --enable-mbstring --enable-intl --enable-ftp --enable-gd --with-openssl --with-mhash --enable-pcntl --enable-sockets --with-xmlrpc --with-zip --enable-soap --with-gettext --enable-opcache --with-xsl --with-webp --with-xpm --with-snmp --with-ldap
$ vim MakeFile # 开头是‘EXTRA_LIBS’,结尾加上‘-llber’
$ make && make install
# 配置php-fpm
$ cp php.ini-production /usr/local/php/etc/php.ini
# 修改php.ini文件,将对应参数做如下修改。
max_execution_time = 300
max_input_time = 300
post_max_size = 16M
date.timezone =Asia/Shanghai
$ cd sapi/fpm && cp php-fpm.conf /usr/local/php/etc/php-fpm.conf
$ cp /usr/local/php/etc/php-fpm.d/www.conf.default /usr/local/php/etc/php-fpm.d/www.conf
# 测试php-fpm配置
$ /usr/local/php/sbin/php-fpm -t -c /usr/local/php/etc/php.ini -y /usr/local/php/etc/php-fpm.conf
$ chown -R nginx:nginx /usr/local/php/var
# php启动命令
$ /usr/local/php/sbin/php-fpm -c /usr/local/php/etc/php.ini -y /usr/local/php/etc/php-fpm.conf
# 配置php-fpm开机自启动
$ vi /usr/lib/systemd/system/php-fpm.service
***********************************************
[Unit]
Description=PHP-FPM
After=network.target syslog.target2
[Install]
WantedBy=default.target
Alias=php-fpm.service
[Service]
User=nginx
Group=nginx
#User and Group can be set in the php-fpm configure file
Type=forking
#PIDFile=/usr/local/php/var/run/php-fpm.pid
#不需要在这里指定pid文件位置,需要到php-fpm.conf文件中指定
ExecStart=/usr/local/php/sbin/php-fpm -c /usr/local/php/etc/php.ini -y /usr/local/php/etc/php-fpm.conf
ExecStop=/bin/kill -INT $MAINPID
ExecReload=/bin/kill -USR2 $MAINPID
****************************************************************************
$ cp ./sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
$ systemctl daemon-reload
$ systemctl enable php-fpm.service
$ systemctl start php-fpm.service
四、安装mysql数据库
1、下载安装mysql
参考链接:https://www.cnblogs.com/yanglang/p/10782941.html
# 从官网地址https://dev.mysql.com/downloads/mysql/下载mysql-8.0.28-1.el7.x86_64.rpm-bundle.tar
# 上传至10.0.100.120主机并解压
# 删除mariadb相关lib库文件
[root@dbserver mysql]# rpm -e mariadb-libs --nodeps
[root@dbserver mysql]# rpm -ivh mysql-community-common-8.0.28-1.el7.x86_64.rpm --nodeps --force
[root@dbserver mysql]# rpm -ivh mysql-community-libs-8.0.28-1.el7.x86_64.rpm --nodeps --force
[root@dbserver mysql]# rpm -ivh mysql-community-client-8.0.28-1.el7.x86_64.rpm --nodeps --force
[root@dbserver mysql]# rpm -ivh mysql-community-server-8.0.28-1.el7.x86_64.rpm --nodeps --force
[root@dbserver mysql]# rpm -qa | grep mysql
mysql-community-common-8.0.28-1.el7.x86_64
mysql-community-client-8.0.28-1.el7.x86_64
mysql-community-libs-8.0.28-1.el7.x86_64
mysql-community-server-8.0.28-1.el7.x86_64
# 通过以下命令,完成对 mysql 数据库的初始化和相关配置
[root@dbserver mysql]# mysqld --initialize
[root@dbserver mysql]# chown mysql:mysql /var/lib/mysql -R
[root@dbserver mysql]# systemctl start mysqld.service
[root@dbserver mysql]# systemctl enable mysqld
# 通过 cat /var/log/mysqld.log | grep password 命令查看数据库的密码
[root@dbserver mysql]# cat /var/log/mysqld.log | grep password
2022-02-27T13:53:50.656860Z 6 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: srEGdFL&l0eu
# 通过如下命令敲回车键进入数据库登陆界面
[root@dbserver mysql]# mysql -uroot -p
# 第一次登陆,通过如下命令来修改密码
mysql> ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY '********';
2、创建zabbix数据库和账户
# 上传zabbix-6.0.0.tar.gz安装包并解压,进入到如下mysql目录找到创建数据库表sql文件
[root@dbserver mysql]# pwd
/root/software/zabbix/zabbix-6.0.0/database/mysql
[root@dbserver mysql]# ll
总用量 32064
-rw-r--r--. 1 1000 1000 30651987 2月 14 17:55 data.sql
-rw-r--r--. 1 1000 1000 282 2月 14 17:54 double.sql
-rw-r--r--. 1 1000 1000 1526 2月 14 17:54 history_pk_prepare.sql
-rw-r--r--. 1 1000 1000 1978341 2月 14 17:54 images.sql
-rw-r--r--. 1 1000 1000 508 2月 14 17:54 Makefile.am
-rw-r--r--. 1 1000 1000 16389 2月 14 17:55 Makefile.in
-rw-r--r--. 1 1000 1000 163854 2月 14 17:55 schema.sql
[root@dbserver mysql]# mysql -uzabbix -p
mysql> create database zabbix character set utf8 collate utf8_bin;
mysql> create user 'zabbix'@'%' identified by 'zab@2022';
mysql> grant all privileges on zabbix.* to 'zabbix'@'%';
mysql> flush privileges;
mysql> source schema.sql;
mysql> source images.sql;
mysql> source data.sql;
mysql> quit
五、安装zabbix
1、下载安装zabbix
# 安装mysql客户端,上传安装包至10.0.100.110主机并解压, 删除mariadb相关lib库文件
$ rpm -e mariadb-libs --nodeps
$ rpm -ivh mysql-community-common-8.0.28-1.el7.x86_64.rpm --nodeps --force
$ rpm -ivh mysql-community-libs-8.0.28-1.el7.x86_64.rpm --nodeps --force
$ rpm -ivh mysql-community-client-8.0.28-1.el7.x86_64.rpm --nodeps --force
$ rpm -ivh mysql-community-devel-8.0.28-1.el7.x86_64.rpm --nodeps --force
$ rpm -qa | grep mysql
mysql-community-client-8.0.28-1.el7.x86_64
mysql-community-common-8.0.28-1.el7.x86_64
mysql-community-libs-8.0.28-1.el7.x86_64
mysql-community-devel-8.0.28-1.el7.x86_64
# 安装如下依赖包:
$ yum install -y libssh2-devel unixODBC-devel ncurses-devel OpenIPMI-devel libevent-devel java-1.8.0-openjdk-devel openldap-devel gnutls-devel
$ rpm -ivh mysql-community-devel-8.0.28-1.el7.x86_64.rpm --nodeps --force
# 下载上传zabbix-6.0.0.tar.gz源码包并解压
$ tar -xvf zabbix-6.0.0.tar.gz
$ groupadd --system zabbix
$ useradd --system -g zabbix -d /app/zabbix -s /sbin/nologin -c "Zabbix Monitoring System" zabbix
$ ./configure --prefix=/app/zabbix --enable-server --enable-agent --enable-ipv6 --with-mysql=/usr/bin/mysql_config --with-net-snmp --with-libcurl --with-libxml2 --with-openipmi --with-unixodbc --with-jabber --with-ssh2 --with-zlib --with-libpcre --enable-java --with-ldap --with-gnutls
$ cd zabbix-6.0.6
$ cp -r ui/ /app/nginx/html/zabbix
$ chmod 777 /app/nginx/html/zabbix/conf
$ cd /app/zabbix
$ mkdir logs
$ chown -R zabbix:zabbix /app/zabbix
$ systemctl restart nginx.service
# 修改/app/zabbix/etc/zabbix_server.conf文件,将对应参数修改如下。
LogFile=/app/zabbix/logs/zabbix_server.log
PidFile=/app/zabbix/logs/zabbix_server.pid
DBHost=10.0.100.120
DBName=zabbix
DBUser=zabbix
DBPassword=******
DBPort=3306
2、进入web安装配置界面
打开浏览器输入地址:http://10.0.100.110/setup.php
选择中文,点击下一步;
如果没有错误提示,继续点击下一步;
输入MySQL数据库连接信息,然后点击下一步;
如果出现如上信息,说明zabbix已经安装配置完成!
3、配置开机自启动
# 创建/etc/systemd/system/zabbix-server.service文件,并输入如下内容:
[Unit]
Description=Zabbix Server
After=syslog.target
After=network.target
[Service]
Environment="CONFFILE=/app/zabbix/etc/zabbix_server.conf"
EnvironmentFile=-/app/zabbix/sbin/zabbix_server
Type=forking
Restart=on-failure
PIDFile=/app/zabbix/logs/zabbix_server.pid
KillMode=control-group
ExecStart=/app/zabbix/sbin/zabbix_server -c $CONFFILE
ExecStop=/bin/kill -SIGTERM $MAINPID
RestartSec=10s
[Install]
WantedBy=multi-user.target
# 重载系统服务:
$ systemctl daemon-reload
# 设置开机启动:
$ systemctl enable zabbix-server.service
#启动服务
$ systemctl start zabbix0server.service
[root@zabbix logs]# tail -200f /app/zabbix/logs/zabbix_server.log
65035:20220228:190614.625 Starting Zabbix Server. Zabbix 6.0.0 (revision 5203d2ea7d).
65035:20220228:190614.625 ****** Enabled features ******
65035:20220228:190614.625 SNMP monitoring: YES
65035:20220228:190614.625 IPMI monitoring: YES
65035:20220228:190614.625 Web monitoring: YES
65035:20220228:190614.625 VMware monitoring: YES
65035:20220228:190614.625 SMTP authentication: YES
65035:20220228:190614.625 ODBC: YES
65035:20220228:190614.625 SSH support: YES
65035:20220228:190614.625 IPv6 support: YES
65035:20220228:190614.625 TLS support: YES
65035:20220228:190614.625 ******************************
65035:20220228:190614.625 using configuration file: /app/zabbix/etc/zabbix_server.conf
65035:20220228:190614.758 current database version (mandatory/optional): 06000000/06000000
65035:20220228:190614.758 required mandatory version: 06000000
65036:20220228:190614.892 starting HA manager
65036:20220228:190614.946 HA manager started in active mode
65035:20220228:190614.949 server #0 started [main process]
65037:20220228:190614.950 server #1 started [service manager #1]
65038:20220228:190614.951 server #2 started [configuration syncer #1]
65039:20220228:190615.128 server #3 started [alert manager #1]
65041:20220228:190615.131 server #5 started [alerter #2]
65042:20220228:190615.133 server #6 started [alerter #3]
65047:20220228:190615.144 server #11 started [lld manager #1]
4、配置agent开机自启动
# 创建/etc/systemd/system/zabbix-agentd.service文件,并输入如下内容:
[Unit]
Description=Zabbix monitor agent
After=syslog.target
After=network.target
[Service]
Environment="CONFFILE=/app/zabbix/etc/zabbix_agentd.conf"
EnvironmentFile=-/app/zabbix/sbin/zabbix_agentd
Type=forking
Restart=on-failure
PIDFile=/app/zabbix/logs/zabbix_agentd.pid
KillMode=control-group
ExecStart=/app/zabbix/sbin/zabbix_agentd -c $CONFFILE
ExecStop=/bin/kill -SIGTERM $MAINPID
RestartSec=10s
[Install]
WantedBy=multi-user.target
# 重载系统服务:
$ systemctl daemon-reload
# 设置开机启动:
$ systemctl enable zabbix-agentd.service
#启动服务
$ systemctl start zabbix-agentd.service
5、登录
打开浏览器,输入http://10.0.100.110/zabbix;
输入用户名Admin,密码:zabbix,点击登录;