zabbix6.和mysql安装
系统环境:rockylinux8.10
zabbix版本:zabbix-6.0.30 LTS版本
php版本:php7.2
nginx版本:1.26
mysql版本:mysql8
#下载软件包 wget https://cdn.zabbix.com/zabbix/sources/stable/6.0/zabbix-6.0.30.tar.gz tar xvf zabbix-6.0.30.tar.gz ln -s /tools/zabbix-6.0.30 zabbix #创建zabbix用户和用户组 groupadd --system zabbix useradd --system -g zabbix -d /usr/lib/zabbix -s /sbin/nologin -c "Zabbix Monitoring System" zabbix #编译安装mysql #下载二进制版本mysql8 wget https://downloads.mysql.com/archives/get/p/23/file/mysql-8.0.27-linux-glibc2.12-x86_64.tar.xz tar xvf mysql-8.0.27-linux-glibc2.12-x86_64.tar.xz ln -s /tools/mysql-8.0.27-linux-glibc2.12-x86_64 /usr/local/mysql useradd mysql #配置环境变量 vim /etc/profile export PATH=$PATH:/usr/local/mysql/bin source /etc/profile #配置mysql的配置文件 vim /etc/my.cnf [client] socket=/data/mysql/3306/data/mysql.sock [mysqld] #server configuration user=mysql datadir=/data/mysql/3306/data basedir=/usr/local/mysql port=3306 socket=/data/mysql/3306/data/mysql.sock log_timestamps=system log_error=/data/mysql/3306/data/mysqld.err skip_name_resolve #Replication Framework server_id=1 master_info_repository=TABLE relay_log_info_repository=TABLE log_slave_updates=ON log_bin=mysql-bin binlog_format=ROW 创建数据目录,初始化实例,启动实例 mkdir -p /data/mysql/3306/data/ /usr/local/mysql/bin/mysqld --defaults-file=/etc/my.cnf --initialize-insecure /usr/local/mysql/bin/mysqld_safe --defaults-file=/etc/my.cnf & #检查mysql端口 [root@mb tools]# netstat -lntup Active Internet connections (only servers) Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name tcp 0 0 0.0.0.0:111 0.0.0.0:* LISTEN 1/systemd tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 863/sshd tcp6 0 0 :::33060 :::* LISTEN 1923/mysqld tcp6 0 0 :::3306 :::* LISTEN 1923/mysqld tcp6 0 0 :::111 :::* LISTEN 1/systemd tcp6 0 0 :::22 :::* LISTEN 863/sshd udp 0 0 0.0.0.0:111 0.0.0.0:* 1/systemd udp 0 0 127.0.0.1:323 0.0.0.0:* 852/chronyd udp6 0 0 :::111 :::* 1/systemd udp6 0 0 ::1:323 :::* 852/chronyd #检查mysql进程 [root@mb tools]# ps -ef|grep mysql root 1677 1545 0 09:53 pts/0 00:00:00 /bin/sh /usr/local/mysql/bin/mysqld_safe --defaults-file=/etc/my.cnf mysql 1923 1677 1 09:53 pts/0 00:00:00 /usr/local/mysql/bin/mysqld --defaults-file=/etc/my.cnf --basedir=/usr/local/mysql --datadir=/data/mysql/3306/data --plugin-dir=/usr/local/mysql/lib/plugin --user=mysql --log-error=/data/mysql/3306/data/mysqld.err --pid-file=mb.pid --socket=/data/mysql/3306/data/mysql.sock --port=3306 #如登录报错,此时root密码默认为空 [root@mb mysql]# mysql -uroot -p mysql: error while loading shared libraries: libtinfo.so.5: cannot open shared object file: No such file or directory [root@mb mysql]# ln -s /usr/lib64/libtinfo.so.6.1 /usr/lib64/libtinfo.so.5 [root@mb mysql]# mysql -uroot -p Enter password: Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 8 mysql> #创建zabbix数据库和用户。 create database zabbix character set utf8mb4 collate utf8mb4_bin; create user zabbix@localhost identified by '123456'; grant all privileges on zabbix.* to zabbix@localhost; set global log_bin_trust_function_creators = 1; #导入zabbix的表和库 [root@mb mysql]# ls -l /tools/zabbix-6.0.30/database/mysql/ total 42464 -rw-r--r-- 1 mysql mysql 41302133 May 21 14:58 data.sql -rw-r--r-- 1 mysql mysql 282 May 21 14:57 double.sql -rw-r--r-- 1 mysql mysql 1527 May 21 14:58 history_pk_prepare.sql -rw-r--r-- 1 mysql mysql 1978341 May 20 18:30 images.sql -rw-r--r-- 1 mysql mysql 716 May 21 14:57 Makefile.am -rw-r--r-- 1 mysql mysql 16706 May 21 14:58 Makefile.in -rw-r--r-- 1 mysql mysql 166156 May 21 14:58 schema.sql #执行导入 cd /tools/zabbix-6.0.30/database/mysql/ mysql -uzabbix -p123456 zabbix < schema.sql mysql -uzabbix -p123456 zabbix < images.sql mysql -uzabbix -p123456 zabbix < data.sql mysql -uzabbix -p123456 zabbix < double.sql mysql -uzabbix -p123456 zabbix < history_pk_prepare.sql #======================================= [root@mb mysql]# mysql -uzabbix -p123456 zabbix < schema.sql mysql: [Warning] Using a password on the command line interface can be insecure. [root@mb mysql]# mysql -uzabbix -p123456 zabbix < images.sql mysql: [Warning] Using a password on the command line interface can be insecure. [root@mb mysql]# mysql -uzabbix -p123456 zabbix < data.sql mysql: [Warning] Using a password on the command line interface can be insecure. [root@mb mysql]# mysql -uzabbix -p123456 zabbix < double.sql mysql: [Warning] Using a password on the command line interface can be insecure. [root@mb mysql]# mysql -uzabbix -p123456 zabbix < history_pk_prepare.sql mysql: [Warning] Using a password on the command line interface can be insecure. #打开mysql的二进制日志 [root@mb ~]# mysql -uroot -p Enter password: mysql> set global log_bin_trust_function_creators = 1; ok #安装zabbix编译所需依赖yum install -y gcc mysql-devel libevent-devel libcurl-devel libxml2-devel net-snmp-devel cd /tools/zabbix ./configure --prefix=/usr/local/zabbix --enable-server --enable-agent --with-mysql=/usr/local/mysql/bin/mysql_config --enable-ipv6 --with-net-snmp --with-libcurl --with-libxml2 make install 编译时注意: 1. configure 命令中的 --prefix 是安装目录,如果不设置,则默认是 /usr/local。 2. 在 make install 的过程中,如果出现如下错误: /bin/ld: warning: libcrypto.so.1.1, needed by /usr/local/mysql/lib/libmysqlclient.so, not found (try using -rpath or -rpath-link) /bin/ld: warning: libssl.so.1.1, needed by /usr/local/mysql/lib/libmysqlclient.so, not found (try using -rpath or -rpath-link) 则需要对依赖的两个库做个软链接。具体命令如下: # find / -name libssl.so.1.1 /usr/local/mysql-8.0.27-linux-glibc2.12-x86_64/lib/private/libssl.so.1.1 # ln -s /usr/local/mysql-8.0.27-linux-glibc2.12-x86_64/lib/private/libssl.so.1.1 /usr/lib64 # ln -s /usr/local/mysql-8.0.27-linux-glibc2.12-x86_64/lib/private/libcrypto.so.1.1 /usr/lib64 #编译参数的说 ./configure 默认安装到/usr/local/下面 #查看/usr/local/zabbix/目录的内容 [root@mb zabbix]# tree /usr/local/zabbix /usr/local/zabbix ├── bin │ ├── zabbix_get │ ├── zabbix_js │ └── zabbix_sender ├── etc#etc 是配置文件目录 │ ├── zabbix_agentd.conf │ ├── zabbix_agentd.conf.d │ ├── zabbix_server.conf │ └── zabbix_server.conf.d ├── lib │ └── modules ├── sbin │ ├── zabbix_agentd │ └── zabbix_server └── share ├── man │ ├── man1 │ │ ├── zabbix_get.1 │ │ └── zabbix_sender.1 │ └── man8 │ ├── zabbix_agentd.8 │ └── zabbix_server.8 └── zabbix ├── alertscripts#alertscripts 是告警脚本目录 └── externalscripts#externalscripts 是外部脚本目录 14 directories, 11 files #修改zabbix-server的配置文件 [root@mb ~]# grep -Ev '^$|^#' /usr/local/zabbix/etc/zabbix_server.conf LogFile=/tmp/zabbix_server.log DBHost=localhost DBName=zabbix DBUser=zabbix DBPassword=123456 DBSocket=/data/mysql/3306/data/mysql.sock #注意socket文件需要单独指定 DBPort=3306 Timeout=4 LogSlowQueries=3000 StatsAllowedIP=127.0.0.1 #查看zabbix-agent的配置文件 [root@mb zabbix]# grep -Ev '^$|^#' /usr/local/zabbix/etc/zabbix_agentd.conf LogFile=/tmp/zabbix_agentd.log Server=127.0.0.1 ServerActive=127.0.0.1 Hostname=Zabbix server #编写systemctl启动文件 vim /usr/lib/systemd/system/zabbix-server.service [Unit] Description=Zabbix Server with MySQL DB After=syslog.target network.target [Service] Type=simple ExecStart=/usr/local/zabbix/sbin/zabbix_server -f User=zabbix [Install] WantedBy=multi-user.target #加载配置文件 systemctl daemon-reload #启动和自启动设置检查 systemctl enable zabbix-server systemctl start zabbix-server systemctl status zabbix-server #配置zabbix-agent的配置文件 [root@mb tools]# vim /usr/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=/run/zabbix/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 #加载配置文件 systemctl daemon-reload systemctl enable zabbix-agent systemctl start zabbix-agent systemctl status zabbix-agent #查看日志 tail -F /tmp/zabbix_server.log tail -F /tmp/zabbix_agentd.log #启动报错信息,因为mysql是二进制安装需要单独在/usr/local/zabbix/etc/zabbix_server.conf文件指定socket文件所在目录 27411:20240611:111419.973 [Z3001] connection to database 'zabbix' failed: [2002] Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2) 27411:20240611:111419.973 database is down: reconnecting in 10 seconds #启动 Zabbix Server 的过程中,如果提示以下错误, Starting Zabbix Server: /usr/local/zabbix/sbin/zabbix_server: error while loading shared libraries: libmysqlclient.so.21: cannot open shared object file: No such file or directory 可通过设置软链接来解决。 # ln -s /usr/local/mysql/lib/libmysqlclient.so.21 /usr/lib64 #检查端口 [root@mb ~]# netstat -lntup Active Internet connections (only servers) Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name tcp 0 0 0.0.0.0:10050 0.0.0.0:* LISTEN 27430/zabbix_agentd tcp 0 0 0.0.0.0:10051 0.0.0.0:* LISTEN 27440/zabbix_server #检查进程 ps -ef|grep zabbix
php7.2和nginx1.16安装
#Zabbix从5.0开始,要求PHP的版本不低于7.2 #安装php7。2 yum install php-fpm php-json php-mysqlnd php-gd php-pecl-zip php-xml -y #查看版本 [root@mb data]# php-fpm -v PHP 7.2.24 (fpm-fcgi) (built: Oct 22 2019 08:28:36) Copyright (c) 1997-2018 The PHP Group Zend Engine v3.2.0, Copyright (c) 1998-2018 Zend Technologies #安装nginx yum install -y nginx #检查版本 [root@mb data]# nginx -v nginx version: nginx/1.26.1 #修改php的配置 [root@mb php-fpm.d]# cat /etc/php-fpm.d/www.conf [www] user = nginx group = nginx listen = 9000 listen.acl_users = nginx,nginx pm = dynamic pm.max_children = 100 pm.start_servers = 10 pm.min_spare_servers = 10 pm.max_spare_servers = 70 pm.status_path = /php_status ping.path = /ping ping.response = pong pm.max_requests = 2048 rlimit_files = 51200 slowlog = /var/log/php-fpm/www-slow.log php_admin_value[error_log] = /var/log/php-fpm/www-error.log php_admin_flag[log_errors] = on #检查配置 [root@mb php-fpm.d]# php-fpm -t [11-Jun-2024 14:32:52] NOTICE: configuration file /etc/php-fpm.conf test is successful #修改nginx的配置实现链接php [root@mb conf.d]# cat zabbix.conf server { listen 80; server_name www.zabbix.cn; index index.php index.html; root /zabbix.; 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; fastcgi_param HTTPS $https if_not_empty; } location ~ ^/(ping|php_status)$ { fastcgi_pass 127.0.0.1:9000; fastcgi_param PATH_TRANSLATED $document_root$fastcgi_script_name; include fastcgi_params; } } #检查nginx的配置 [root@mb php-fpm.d]# nginx -t nginx: the configuration file /etc/nginx/nginx.conf syntax is ok nginx: configuration file /etc/nginx/nginx.conf test is successful #修改php.ini的配置,zabbix要求的配置 vim /etc/php.ini max_execution_time = 300 max_input_time = 300 memory_limit = 128M post_max_size = 16M upload_max_filesize = 2M date.timezone = Asia/Shanghai #启动nginx和php [root@mb php-fpm.d]# systemctl restart nginx php-fpm #端口检查 [root@mb php-fpm.d]# netstat -lntup Active Internet connections (only servers) Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name tcp 0 0 0.0.0.0:10051 0.0.0.0:* LISTEN 27440/zabbix_server tcp 0 0 0.0.0.0:111 0.0.0.0:* LISTEN 1/systemd tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 31230/nginx: master tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 863/sshd tcp6 0 0 :::10051 :::* LISTEN 27440/zabbix_server tcp6 0 0 :::33060 :::* LISTEN 1923/mysqld tcp6 0 0 :::9000 :::* LISTEN 31236/php-fpm: mast tcp6 0 0 :::3306 :::* LISTEN 1923/mysqld tcp6 0 0 :::111 :::* LISTEN 1/systemd tcp6 0 0 :::22 :::* LISTEN 863/sshd udp 0 0 0.0.0.0:111 0.0.0.0:* 1/systemd udp 0 0 127.0.0.1:323 0.0.0.0:* 852/chronyd udp6 0 0 :::111 :::* 1/systemd udp6 0 0 ::1:323 :::* 852/chronyd #创建首页进行测试 mkdir -p /zabbix cat >/zabbix/index.php<<'EOF' <?php echo phpinfo(); ?> EOF #配置hosts解析 172.168.10.22 www.zabbix.cn #访问测试 [root@mb conf.d]# curl www.zabbix.cn/ping pong #删除测试首页 rm -f /zabbix/index.php #拷贝zabbix的代码到首页目录/zabbix/ [root@mb conf.d]# cp -r /tools/zabbix-6.0.30/ui/* /zabbix/ [root@mb conf.d]# chown nginx.nginx -R /zabbix/
zabbix-agent2安装
[root@mb tools]# rpm -Uvh https://repo.zabbix.com/zabbix/6.0/rhel/8/x86_64/zabbix-release-6.0-1.el8.noarch.rpm Retrieving https://repo.zabbix.com/zabbix/6.0/rhel/8/x86_64/zabbix-release-6.0-1.el8.noarch.rpm warning: /var/tmp/rpm-tmp.Yd14jA: Header V4 RSA/SHA512 Signature, key ID a14fe591: NOKEY Verifying... ################################# [100%] Preparing... ################################# [100%] Updating / installing... 1:zabbix-release-6.0-1.el8 ################################# [100%] #安装完成以后自动配置zabbix的yum源 [root@mb yum.repos.d]# cat /etc/yum.repos.d/zabbix.repo [zabbix] name=Zabbix Official Repository - $basearch baseurl=https://repo.zabbix.com/zabbix/6.0/rhel/8/$basearch/ enabled=1 gpgcheck=1 gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-ZABBIX-A14FE591 [zabbix-non-supported] name=Zabbix Official Repository non-supported - $basearch baseurl=https://repo.zabbix.com/non-supported/rhel/8/$basearch/ enabled=1 gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-ZABBIX gpgcheck=1 #安装zabbix-agent2 dnf install -y zabbix-agent2 #修改配置文件 #Server=172.168.10.21和ServerActive=172.168.10.21配置完成后zabbix-agent将变成主动模式 [root@mb yum.repos.d]# grep -n '^[a-Z]' /etc/zabbix/zabbix_agent2.conf 13:PidFile=/run/zabbix/zabbix_agent2.pid 32:LogFile=/var/log/zabbix/zabbix_agent2.log 43:LogFileSize=0 80:Server=172.168.10.21 133:ServerActive=172.168.10.21 144:Hostname=Zabbix server 281:Include=/etc/zabbix/zabbix_agent2.d/*.conf 302:PluginSocket=/run/zabbix/agent.plugin.sock 345:ControlSocket=/run/zabbix/agent.sock 490:Include=./zabbix_agent2.d/plugins.d/*.conf #启动 systemctl restart zabbix-agent2
web页面配置
#访问www.zabbix.cn测试
标签:LTS,rockylinux8,--,zabbix6.0,mysql,zabbix,usr,0.0,root From: https://www.cnblogs.com/yeyouqing/p/18242055