环境说明#
这里使用为 CentOS 7.6 版本进行测试验证, Zabbix Server 采用源码包部署,数据库采用
MySQL8.0 版本, zabbix-web 使用 nginx+php 来实现。具体信息如下:
官网参考文档:https://www.zabbix.com/documentation/6.0/en/manual/installation/install
安装MySQL#
1、下载软件包
cat << EOF >download.sh #!/bin/bash wget https://mirrors.cloud.tencent.com/mysql/downloads/MySQL-8.0/mysql-communityclient-8.0.28-1.el7.x86_64.rpm wget https://mirrors.cloud.tencent.com/mysql/downloads/MySQL-8.0/mysql-communitydevel-8.0.28-1.el7.x86_64.rpm wget https://mirrors.cloud.tencent.com/mysql/downloads/MySQL-8.0/mysql-communityembedded-compat-8.0.28-1.el7.x86_64.rpm wget https://mirrors.cloud.tencent.com/mysql/downloads/MySQL-8.0/mysql-communitylibs-8.0.28-1.el7.x86_64.rpm wget https://mirrors.cloud.tencent.com/mysql/downloads/MySQL-8.0/mysql-communitylibs-compat-8.0.28-1.el7.x86_64.rpm wget https://mirrors.cloud.tencent.com/mysql/downloads/MySQL-8.0/mysql-communityserver-8.0.28-1.el7.x86_64.rpm wget https://mirrors.cloud.tencent.com/mysql/downloads/MySQL-8.0/mysql-communitycommon-8.0.28-1.el7.x86_64.rpm wget https://mirrors.cloud.tencent.com/mysql/downloads/MySQL-8.0/mysql-communityclient-plugins-8.0.28-1.el7.x86_64.rpm wget https://mirrors.cloud.tencent.com/mysql/downloads/MySQL-8.0/mysql-communityicu-data-files-8.0.28-1.el7.x86_64.rpm EOF bash download.sh
2、安装
yum localinstall ./mysql-community-* -y
3、修改配置文件(更改数据存放路径)
mkdir /data/mysql -p # grep -v -E '^#|^$' /etc/my.cnf [mysqld] port=3306 default-storage-engine=InnoDB max_connections=1200 datadir=/data/mysql socket=/var/lib/mysql/mysql.sock log-error=/var/log/mysqld.log pid-file=/var/run/mysqld/mysqld.pid log_slave_updates=ON log_bin=mysql-bin binlog_format=ROW
4、启动并加入开机自启
systemctl enable --now mysqld
5、修改密码
# grep password /var/log/mysqld.log 2022-04-13T07:31:54.168545Z 6 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: RP-u?qo.,4hD # mysql -uroot -p Enter password: ...... mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY "Yjs1234."; Query OK, 0 rows affected (0.01 sec)
6、创建初始数据库及用户
mysql> create database zabbix character set utf8 collate utf8_bin; mysql> create user 'zabbix'@'%' identified by 'Zabbix1234.'; mysql> grant all privileges on zabbix.* to 'zabbix'@'%' with grant option; mysql> alter user 'zabbix'@'%' identified with mysql_native_password by 'Zabbix1234.'; mysql> select user,host,plugin from mysql.user; +------------------+-----------+-----------------------+ | user | host | plugin | +------------------+-----------+-----------------------+ | zabbix | % | mysql_native_password | | mysql.infoschema | localhost | caching_sha2_password | | mysql.session | localhost | caching_sha2_password | | mysql.sys | localhost | caching_sha2_password | | root | localhost | caching_sha2_password | +------------------+-----------+-----------------------+ 5 rows in set (0.00 sec)
安装Zabbix#
下载软件包:https://cdn.zabbix.com/zabbix/sources/stable/6.2/zabbix-6.2.7.tar.gz
1、解压软件包
tar -zxvf zabbix-6.2.7.tar.gz
2、创建 zabbix 用户
cd zabbix-6.2.7/database/mysql mysql -uzabbix -pZabbix1234. zabbix < schema.sql mysql -uzabbix -pZabbix1234. zabbix < images.sql mysql -uzabbix -pZabbix1234. zabbix < data.sql
报错
ERROR 1419 (HY000) at line 2123: You do not have the SUPER privilege and binary logging is
enabled (you might want to use the less safe log_bin_trust_function_creators variable)
解决办法
有几种解决方法:
您需要为运行导入数据库的用户指定SUPER特权,并应用CREATE ROUTINE,ALTER
ROUTINE,CREATE TRIGGER,ALTER TRIGGER,CREATE FUNCTION和ALTER FUNCTION特权;
如果要允许具有CREATE ROUTINE特权的MySQL服务器上的所有用户都可以创建此类功能,则
可以通过两种方式指定log_bin_trust_function_creators选项:
通过在服务器启动时指定它,例如:-- log-bin-trust-function-creators = 1
通过SET GLOBAL语句将其设置为1 ,例如:
mysql> SET GLOBAL log_bin_trust_function_creators = 1;
如果您不打算使用MySQL服务器进行复制,请考虑通过从启动MySQL服务器的mysqld实用程
序的命令选项中删除选项--log-bin来关闭二进制日志记录。
4、安装编译所需的依赖,这里根据启用的模块不一样,所需要的依赖也不一样
yum install gcc mysql-devel libevent-devel libcurl-devel libxml2-devel libssh2- devel OpenIPMI-devel net-snmp-devel go java-devel -y
5、进行编译安装,去到软件包解压目录 zabbix-6.2.7 中
cd zabbix-6.2.7 ./configure --prefix=/usr/local/zabbix --enable-server --enable-agent --withmysql --enable-ipv6 --with-net-snmp --with-libcurl --with-libxml2 --withopenipmi --with-ssh2 --enable-java
配置完成如下图所示,这里可以看到我们启用了 java gateway 、 agent 等等
接着进行安装
make install
安装完成后,可以看下所安装的目录的内容
# tree /usr/local/zabbix/ /usr/local/zabbix/ ├── bin │ ├── zabbix_get │ ├── zabbix_js │ └── zabbix_sender ├── etc │ ├── zabbix_agent2.conf │ ├── zabbix_agentd.conf │ ├── zabbix_agentd.conf.d │ ├── zabbix_server.conf │ └── zabbix_server.conf.d ├── lib │ └── modules ├── sbin │ ├── zabbix_agentd │ ├── zabbix_java │ │ ├── bin │ │ │ └── zabbix-java-gateway-6.0.3.jar │ │ ├── lib │ │ │ ├── android-json-4.3_r3.1.jar │ │ │ ├── logback-classic-1.2.9.jar │ │ │ ├── logback-console.xml │ │ │ ├── logback-core-1.2.9.jar │ │ │ ├── logback.xml │ │ │ └── slf4j-api-1.7.32.jar │ │ ├── settings.sh │ │ ├── shutdown.sh │ │ └── startup.sh │ └── zabbix_server └── share ├── man │ ├── man1 │ │ ├── zabbix_get.1 │ │ └── zabbix_sender.1 │ └── man8 │ ├── zabbix_agentd.8 │ └── zabbix_server.8 └── zabbix ├── alertscripts └── externalscripts 17 directories, 22 files
6、修改配置文件
cp /usr/local/zabbix/etc/zabbix_server.conf{,.bak} # grep -v -E "^#|^$" /usr/local/zabbix/etc/zabbix_server.conf LogFile=/usr/local/zabbix/log/zabbix_server.log LogFileSize=0 PidFile=/var/run/zabbix/zabbix_server.pid SocketDir=/var/run/zabbix DBHost=127.0.0.1 DBPort=3306 DBName=zabbix DBUser=zabbix DBPassword=Zabbix StartPollers=12 StartTrappers=30 StartDiscoverers=50 StartHTTPPollers=100 SNMPTrapperFile=/var/log/snmptrap/snmptrap.log CacheSize=4G CacheUpdateFrequency=1200 ValueCacheSize=12G Timeout=4 AlertScriptsPath=/usr/local/zabbix/alertscripts ExternalScripts=/usr/local/zabbix/externalscripts FpingLocation=/sbin/fping LogSlowQueries=3000 StatsAllowedIP=127.0.0.1
7、创建相关配置目录及权限设置
mkdir -p /usr/local/zabbix/{alertscripts,externalscripts,log} mkdir /var/run/zabbix chown zabbix.zabbix /var/run/zabbix/ chown zabbix.zabbix /usr/local/zabbix/ -R
8、配置systemd启动
cat <<EOF > /etc/systemd/system/zabbix-server.service [Unit] Description=Zabbix Server After=syslog.target network.target network-online.target Wants=network.target network-online.target [Service] Type=simple User=root ExecStart=/usr/local/zabbix/sbin/zabbix_server -c /usr/local/zabbix/etc/zabbix_server.conf RemainAfterExit=yes PIDFile=/var/run/zabbix/zabbix_server.pid [Install] WantedBy=multi-user.target EOF
9、加入开机启动并启动
systemctl daemon-reload systemctl enable zabbix-server --now
安装zabbix-web#
这里采用 nginx+php 部署来支撑 zabbix-web ,这样在后期如果有漏洞,也方便对应升级维护,
如 nginx 有漏洞,可以直接把 nginx 升级即可。
安装php#
1、配置 yum ,这里使用华为的 yum 源
yum install https://repo.huaweicloud.com/remi/enterprise/remi-release-7.rpm -y
2、安装 php
yum-config-manager --enable remi-php74 yum install php php-fpm php-ldap php-bcmath php-mbstring php-common php-gd phpmysql php-xml php-cli php-devel php-pecl-memcached php-pecl-redis php-opcache -y php -v
3、配置 php.ini ,(使用清华大学 yum 安装的 php 配置文件路径在 /etc/opt/remi/php74/ )
cp /etc/opt/remi/php74/php.ini{,.bak} vim /etc/opt/remi/php74/php.ini [PHP] #该标签已有,只是将下列参数加到(或修改)该标签下。 expose_php = Off #禁止显示php版本的信息 short_open_tag = On #取消前面的;,修改为On。表示支持php短标签 cgi.fix_pathinfo=1 #将注释去掉,开启PHP的pathinfo伪静态功能。 max_execution_time = 300 #脚本运行的最长时间,默认30秒 max_input_time = 300 #脚本可以消耗的时间,默认60秒 memory_limit = 256M #脚本运行最大消耗的内存,根据你的需求更改数值,默认128M post_max_size = 100M #单提交的最大数据,此项不是限制上传单个文件的大小,而是针对整个表单的 提交数据进行限制的。限制范围包括表单提交的所有内容.例如:发表贴子时,贴子标题,内容,附件等…默认8 upload_max_filesize = 10M #上载文件的最大许可大小 ,默认2M [Date] #该标签已有,只是修改下方的时区 date.timezone = Asia/Shanghai
4、配置 php-fpm.conf
vim /etc/opt/remi/php74/php-fpm.conf include=/etc/opt/remi/php74/php-fpm.d/*.conf error_log = /var/opt/remi/php74/log/php-fpm/error.log
5、启动 php 并加入开机启动
systemctl enable --now php74-php-fpm.service
备注:如果需要卸载老版本 php 可以使用以下命令进行卸载
rpm -qa |grep php|xargs -i rpm -e {} --nodeps