Zabbix Server端编译安装配置
PHP版本:php-7.4.29
NGINX版本:nginx-1.20.2
MYSQL版本:MySQL 5.7.36
zabbix版本:zabbix-5.0.0
一、依赖安装
yum install pcre* libevent-devel pcre-devel libxml2-devel net-snmp-devel gcc gcc-g++ libcurl-devel
二、MySQL安装
1、下载安装包
官网链接:https://downloads.mysql.com/archives/community/
官网缓慢,可通过其它镜像仓库下载
2、卸载自带的mariadb
# 查看自带的mariadb
rpm -qa|grep mariadb
# 卸载自带的mariadb
rpm -e --nodeps mariadb-libs-5.5.60-1.el7-5.x86_64
3、解压安装MySQL
1)解压
tar -zxvf mysql-5.7.37-1.el7.x86_64.rpm-bundle.tar
# 解压后得到以下几个rpm文件
2)安装
rpm -Uvh *.rpm --force --nodeps
3)查看安装情况
rpm -qa | grep myql
4、启动MySQL
systemctl start mysqld.service
5、修改root密码
1)查看初始化密码
cat /var/log/mysqld.log | grep password
2)登录MySQL修改密码
mysql -uroot -p
# 修改密码策略
mysql> set global validate_password_length=1;
mysql> set global validate_password_policy=0;
mysql> flush privileges;
# 修改密码
mysql> alter user 'root'@'localhost' identified by '123456';
# (可选)开启远程连接
mysql> update user set host = '%' where user = 'root';
mysql> flush privileges;
3)设置编码
编辑/etc/my.cnf
,在mysqld
下添加,然后重启mysqld
init_connect='SET collation_connection = utf8_unicode_ci'
init_connect='SET NAMES utf8'
character-set-server=utf8
collation-server=utf8_unicode_ci
skip-character-set-client-handshake
4)(可选)支持中文编码
编辑/etc/my.cnf
character-set-server=utf8
[client]
default-character-set=utf8
[mysql]
default-character-set=utf8
三、Zabbix安装
官方文档:https://www.zabbix.com/documentation/5.0/en/manual/installation/install
1、编译安装
# 配置检查预编译
./configure --prefix=/data/zabbix_software --enable-server --enable-agent --with-mysql --enable-ipv6 --with-net-snmp --with-libcurl --with-libxml2
# Zabbix预编译完成后,直接安装即可
make install
2、配置环境变量
在`/etc/profile.d中新建一个sh文件, software.sh,添加以下内容
export PATH=/data/zabbix_software/bin/:$PATH
export PATH=/data/zabbix_software/sbin/:$PATH
四、Zabbix数据库导入
1、新建库
mysql> create databse zabbix character set utf8 collate utf8_bin;
mysql> grant all on zabbix.* to 'zabbix'@'localhost' identified by 'zabbix';
mysql> flush privileges;
2、导入数据
- 在zabbix的数据库文件在源码包下database目录中
mysql> source /data/zabbix_packages/zabbix-5.5.0/database/mysql/schema.sql
mysql> source /data/zabbix_packages/zabbix-5.5.0/database/mysql/images.sql
mysql> source /data/zabbix_packages/zabbix-5.5.0/database/mysql/data.sql
五、Zabbix配置
编辑安装目录下etc/zabbix_proxy.conf
,修改DBHost(数据库设备)、DBName(zabbix使用的数据库名称)、DBUser(数据库用户)、DBPassword(数据库密码)和DBPort(数据库端口号)等
六、启动Zabbix
1、创建zabbix用户,否则会报错
groupadd --system zabbix
useradd --system -g zabbix -d /usr/lib/zabbix -s /sbin/nologin -c "Zabbix Monitoring System" zabbix
2、启动zabbix server
./zabbix_server -c /data/zabbix_software/etc/zabbix_server.conf
七、配置web
参考博客:https://www.cnblogs.com/charon2/p/10545088.html
1、Nginx安装
1)编译安装
# 下载Nginx
wget http://nginx.org/download/nginx-1.20.2.tar.gz
# 解压Nginx
tar -zxvf nginx-1.20.2.tar.gz
# 编译安装Nginx
cd nginx-1.20.2
mkdir -p /usr/local/nginx/
./configure --prefix=/usr/local/nginx/ --without-http_rewrite_module --without-http_gzip_module --with-pcre
make
make install
2)zabbix前端文件拷贝
cp /data/zabbix_packages/zabbix-5.0.0/ui/* /usr/local/nginx/html
cp /usr/local/nginx/html/conf/zabbix.conf.php.example /usr/local/nginx/html/conf/zabbix.conf.php
vim /usr/local/nginx/html/conf/zabbix.conf.php
chmod 777 /usr/local/nginx/html/conf/zabbix.conf.php # 必须执行,否则在web中配置完成后,无法保覆盖在目录下
3)适应zabbix配置
vim /usr/local/nginx/etc/conf.d/zabbix.conf
server {
listen 8888;
access_log /home/up/ssl.access.log;
error_log /home/up/ssl.error.log;
location / {
root html;
index index.php index.html index.htm;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
location ~ /.php$ {
root /usr/share/nginx/html;
fastcgi_buffer_size 128k;
fastcgi_buffers 4 256k;
fastcgi_busy_buffers_size 256k;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME
$document_root$fastcgi_script_name;
include fastcgi_params;
}
}
2、PHP编译安装
1)编译中可能出现的确实包问题
yum -y install libxml2-devel
yum -y install sqlite-devel
yum -y install bzip2-devel
yum -y install libcurl-devel
yum -y install libpng-devel
yum -y install libjpeg-devel
yum -y install freetype-devel
yum -y install libicu-devel
yum -y install oniguruma-devel
yum -y install libxslt-devel
yum -y install libzip-devel
-
如果报错,libzip >= 0.11
yum remove libzip libzip-devel -y wget https://libzip.org/download/libzip-1.2.0.tar.gz --no-check-certificate tar -zxvf libzip-1.2.0.tar.gz cd libzip-1.2.0 ./configure make -j 4 make install #还需要让PHP的configure程序知道安装的libzip在哪里, export PKG_CONFIG_PATH="/usr/local/lib/pkgconfig/"
2)安装PHP 7
cd /data/php_package/php-7.4.29
./configure --prefix=/data/php_software --with-curl --with-freetype --enable-gd --with-jpeg --with-gettext --with-kerberos --with-libdir=lib64 --with-libxml --with-mysqli --with-openssl --with-pdo-mysql --with-pear --enable-sockets --with-mhash --with-ldap-sasl --with-xsl --with-zlib --enable-fpm --enable-bcmath --enable-mbregex --enable-mbstring --enable-opcache --enable-pcntl --enable-shmop --enable-soap --enable-sockets --enable-sysvsem --enable-xml --with-zip --with-config-file-path=/data/php_software/etc -with-bz2 --enable-sysvsem
make -j 4
make install
3)配置
cp /data/php_package/php-7.4.29/php.ini-production /data/php_software/etc/php.ini
cp /data/php_software/etc/php-fpm.conf.default /data/php_software/etc/php-fpm.conf
cp /data/php_software/etc/php-fpm.d/www.conf.default /data/php_software/etc/php-fpm.d/www.conf
4)适应zabbix配置
# vim /data/php_software/etc/php.ini
max_execution_time = 300
memory_limit = 128M
post_max_size = 16M
upload_max_filesize = 2M
max_input_time = 300
date.timezone = Asia/Shanghai
5)启动php-fpm
/data/php_software/sbin/php-fpm -c /data/php_software/etc/php.ini
6)查看启动
ss -lnt | grep 9000
7)(可忽略)结合nginx测试
vim /usr/local/nginx/etc/conf.d/test_php.conf
server {
listen 8888;
server_name localhost;
root /var/www/html;
index index.htm index.html index.php;
location / {
try_files $uri $uri/ /index.php?$args;
}
location ~ .*/.(php)?$ {
expires -1s;
try_files $uri =404;
fastcgi_split_path_info ^(.+/.php)(/.+)$;
include fastcgi_params;
fastcgi_param PATH_INFO $fastcgi_path_info;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_pass 127.0.0.1:9000;
}
#charset koi8-r;
#access_log logs/host.access.log main;
# location / {
# root html;
# index index.html index.htm;
# }
#error_page 404 /404.html;
# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
-
重启nginx
systemctl restart nginx # 具体命令视具体情况而定
-
vim /var/www/html/info.php
<?php phpinfo(); ?>
-
访问网站:127.0.0.1:8888/info.php
八、Web配置zabbix
1、访问设置的地址
原创文章,作者:254126420,如若转载,请注明出处:https://blog.ytso.com/272028.html