zabbix-6.x部署
这么多年过去了,zabbix也发展到了6.x,我们看看新版本有哪些新功能。
zabbix的官方文档:https://www.zabbix.com/documentation/current/zh/manual
zabbix的安装要求:https://www.zabbix.com/documentation/current/zh/manual/installation/requirements #可以得知我们需要Php7+mysql8
一、LNMP环境部署
1.1 mysql8编译安装
#mkdir /opt/soft/package && cd /opt/soft/package
#wget https://cdn.mysql.com/archives/mysql-8.1/mysql-boost-8.1.0.tar.gz
#wget https://cdn.mysql.com/archives/mysql-8.1/mysql-8.1.0.tar.gz
# wget https://cmake.org/files/v3.27/cmake-3.27.5.tar.gz
# tar xf mysql-8.1.0.tar.gz
# tar xf mysql-boost-8.1.0.tar.gz
# tar xf cmake-3.27.5.tar.gz
# cd cmake-3.27.5/
# ./configure --prefix=/opt/soft/cmake
# make -j 4 && make install >/dev/null
# cd /opt/soft/package/mysql-8.1.0/
# /opt/soft/cmake/bin/cmake -DCMAKE_INSTALL_PREFIX=/opt/soft/mysql -DMYSQL_DATADIR=/opt/soft/mysql/data -DSYSCONFDIR=/etc -DWITH_INNOBASE_STORAGE_ENGINE=1 -DWITH_PARTITION_STORAGE_ENGINE=1 -DWITH_FEDERATED_STORAGE_ENGINE=1 -DWITH_BLACKHOLE_STORAGE_ENGINE=1 -DWITH_MYISAM_STORAGE_ENGINE=1 -DENABLED_LOCAL_INFILE=1 -DENABLE_DTRACE=0 -DDEFAULT_CHARSET=utf8mb4 -DDEFAULT_COLLATION=utf8mb4_general_ci -DWITH_EMBEDDED_SERVER=1 -DDOWNLOAD_BOOST=1 -DFORCE_INSOURCE_BUILD=1 -DWITHOUT_PARTITION_STORAGE_ENGINE=0 -DCMAKE_C_COMPILER=/usr/bin/gcc -DCMAKE_CXX_COMPILER=/usr/bin/g++ -DWITH_BOOST=/opt/soft/package/mysql-boost-8.1.0 # make -j 4 && make install
#这个报错我升级了gcc也没解决,不知道到底哪里觉得gcc版本低我就直接把这段判断注释掉了
# vim cmake/os/Linux.cmake
#好了注释掉之后重新执行上面mysql的编译命令。当然机器需要能出网,编译过程还涉及拉包。
#mkdir /opt/soft/mysql/data/
#chown -R work:work /opt/soft/mysql
#/opt/soft/mysql/bin/mysqld --initialize-insecure --user=work --basedir=/opt/soft/mysql --datadir=/opt/soft/mysql/data
#echo 'export PATH=$PATH:/opt/soft/mysql/bin' >>/etc/profile
#source /etc/profile
#cp /opt/soft/mysql/support-files/mysql.server /etc/init.d/mysqld
#chmod +x /etc/init.d/mysqld
#vi /etc/my.cnf
[client] port=3306 socket=/tmp/mysql.sock default-character-set=utf8mb4 [mysqld] server-id=1 #skip-grant-tables port=3306 user=work max_connections=200 socket=/tmp/mysql.sock basedir=/opt/soft/mysql datadir=/opt/soft/mysql/data pid-file=/opt/soft/mysql/data/mysql.pid character-set-client-handshake=FALSE character-set-server=utf8mb4 collation-server=utf8mb4_bin #解决Zabbix数据库中表的字符集或排序规则不受支持的问题 init_connect='SET NAMES utf8mb4' default-storage-engine=INNODB log_error=/opt/soft/mysql/data/mysql-error.log slow_query_log_file=/opt/soft/mysql/data/mysql-slow.log [mysqldump] quick max_allowed_packet=16M
#/etc/init.d/mysqld start
# /etc/init.d/mysqld status
MySQL running (16416) [ 确定 ]
# mysql -uroot -p #至此mysql8编译安装成功
mysql> SELECT @@character_set_database, @@collation_database; #如果不是下面的字符集,web页面里面会有下面的提示:
1.2 PHP7编译部署
yum install libxml2 libxml2-devel openssl openssl-devel bzip2 bzip2-devel libcurl libcurl-devel libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel gmp gmp-devel readline readline-devel libxslt libxslt-devel
#yum install curl-devel oniguruma oniguruma-devel openldap-devel
#yum remove -y libzip #php7需要更高版本的libzip
#wget http://libzip.org/download/libzip-1.2.0.tar.gz
#tar xf libzip-1.2.0.tar.gz
#cd libzip-1.2.0/
#./configure
# make && make install
#vim /etc/ld.so.conf
include ld.so.conf.d/*.conf /usr/local/lib
#ldconfig
#cp /usr/local/lib/libzip/include/zipconf.h /usr/local/include/zipconf.h
#echo 'export PKG_CONFIG_PATH=/usr/local/lib/pkgconfig:$PKG_CONFIG_PATH' >>/etc/profile
#source /etc/profile
#wget https://www.php.net/distributions/php-7.4.33.tar.gz
# tar xf php-7.4.33.tar.gz
# cd php-7.4.33/
./configure --prefix=/opt/soft/php --with-config-file-path=/opt/soft/php/etc --with-fpm-user=work --with-fpm-group=work --with-curl --enable-gd --with-gettext --with-iconv-dir --with-kerberos --with-libdir=lib64 --with-libxml --with-mysqli --with-openssl --with-pcre-regex --with-pdo-mysql --with-pdo-sqlite --with-pear --with-xmlrpc --with-xsl --with-zlib --with-bz2 --with-mhash --enable-fpm --enable-bcmath --with-libxml --enable-inline-optimization --enable-mbregex --enable-mbstring --enable-opcache --enable-pcntl --enable-shmop --enable-soap --enable-sockets --enable-sysvsem --enable-sysvshm --enable-xml --with-zip --with-png=/usr/include/ --with-jpeg=/usr/include/ --with-freetype=/usr/include/
#make -j 4 && make install
# cp /opt/soft/package/php-7.4.33/php.ini-production /opt/soft/php/etc/php.ini
# cp /opt/soft/php/etc/php-fpm.conf.default /opt/soft/php/etc/php-fpm.conf
# cp /opt/soft/php/etc/php-fpm.d/www.conf.default /opt/soft/php/etc/php-fpm.d/www.conf
# cd /opt/soft/package/php-7.4.33/ext/ldap/ #编译下ldap依赖不然后面会提示需要这个ldap
# cp -frp /usr/lib64/libldap* /usr/lib/
# /opt/soft/php/bin/phpize
#./configure --with-php-config=/opt/soft/php/bin/php-config --with-ldap
# make && make install
# echo 'extension="ldap.so"' >>/opt/soft/php/etc/php.ini
#当然如果其他的不支持也是类似的做法,具体问题具体分析吧
1.3 nginx安装
#yum install pcre pcre-devel openssl openssl-devel gd gd-devel -y
#wget http://nginx.org/download/nginx-1.24.0.tar.gz
# tar xf nginx-1.24.0.tar.gz
# cd nginx-1.24.0/
./configure --prefix=/opt/soft/nginx --sbin-path=/opt/soft/nginx/sbin/nginx --conf-path=/opt/soft/nginx/main-conf/nginx.conf --error-log-path=/opt/log/nginx/error.log --http-log-path=/opt/log/nginx/access.log --pid-path=/opt/soft/nginx/run/nginx.pid --lock-path=/opt/soft/nginx/run/nginx.lock --user=work --group=work --http-client-body-temp-path=/opt/soft/nginx/cache/client_temp --http-proxy-temp-path=/opt/soft/nginx/cache/proxy_temp --http-fastcgi-temp-path=/opt/soft/nginx/cache/fastcgi_temp --http-uwsgi-temp-path=/opt/soft/nginx/cache/uwsgi_tmp --http-scgi-temp-path=/opt/soft/nginx/cache/scgi_temp --with-http_ssl_module --with-http_realip_module --with-http_addition_module --with-http_image_filter_module --with-http_sub_module --with-http_dav_module --with-http_flv_module --with-http_mp4_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_random_index_module --with-http_stub_status_module --with-http_gzip_static_module --with-file-aio --with-mail --with-mail_ssl_module --with-http_image_filter_module
#make && make install
博文来自:www.51niux.com
二、Zabbix服务端的安装
2.1 zabbix服务端编译安装
# yum install unixODBC-devel net-snmp-devel libssh2-devel OpenIPMI-devel openldap openldap-devel libevent-devel -y
#wget https://cdn.zabbix.com/zabbix/sources/stable/6.4/zabbix-6.4.8.tar.gz
#tar xf zabbix-6.4.8.tar.gz
# cd zabbix-6.4.8/ #当然需要java环境哈
./configure --prefix=/opt/soft/zabbix --sysconfdir=/opt/soft/zabbix/etc/ --enable-server --enable-proxy --enable-agent --enable-ipv6 --with-mysql=/opt/soft/mysql/bin/mysql_config --with-net-snmp --with-libcurl --with-openipmi --with-unixodbc --with-ldap --with-ssh2 --enable-java
# make -j 4 && make install
2.2 mysql的配置
# mysqladmin -uroot password 'y8FDT0NAeub3RuuN'
# mysql -uroot -py8FDT0NAeub3RuuN -e 'create database zabbix character set utf8;'
# mysql -uroot -py8FDT0NAeub3RuuN -e "create user 'zabbix'@'localhost' identified by 'zabbix';"
# mysql -uroot -py8FDT0NAeub3RuuN -e "grant all privileges on zabbix.* to zabbix@localhost;"
# mysql -uroot -py8FDT0NAeub3RuuN -e "flush privileges;"
# mysql -uroot -py8FDT0NAeub3RuuN zabbix </opt/soft/package/zabbix-6.4.8/database/mysql/schema.sql
# mysql -uroot -py8FDT0NAeub3RuuN zabbix </opt/soft/package/zabbix-6.4.8/database/mysql/images.sql
# mysql -uroot -py8FDT0NAeub3RuuN zabbix </opt/soft/package/zabbix-6.4.8/database/mysql/data.sql
2.3 zabbix的配置
#cp /opt/soft/package/zabbix-6.4.8/misc/init.d/fedora/core/zabbix_* /etc/init.d/
# chmod +x /etc/init.d/zabbix_*
# sed -i "s#BASEDIR=/usr/local#BASEDIR=/opt/soft/zabbix#" /etc/init.d/zabbix_server
# sed -i "s#BASEDIR=/usr/local#BASEDIR=/opt/soft/zabbix#" /etc/init.d/zabbix_agentd
# vim /opt/soft/zabbix/etc/zabbix_server.conf #配置上zabbix的密码
LogFile=/opt/soft/zabbix/log/zabbix_server.log PidFile=/opt/soft/zabbix/run/zabbix_server.pid DBPassword=zabbix
# mkdir /opt/soft/zabbix/{log,run}
# chown zabbix:zabbix /opt/soft/zabbix/{log,run}
# ln -sn /opt/soft/mysql/lib/libmysqlclient.so.22 /usr/lib/
# /etc/init.d/zabbix_server restart
2.4 PHP环境配置
# vim /opt/soft/php/etc/php.ini #把里面的参数改成下面的内容
date.timezone = Asia/Shanghai max_execution_time 300 memory_limit 128M post_max_size 16M upload_max_filesize 2M max_input_time 300 max_input_vars 10000 always_populate_raw_post_data -1
# /opt/soft/php/sbin/php-fpm
2.5 zabbix前端页面配置
# mkdir /opt/soft/nginx/cache
# chown work:work /opt/soft/nginx/cache
# vim /opt/soft/nginx/main-conf/nginx.conf #简单修改几个地方
user work; worker_processes 4; server { listen 80; server_name localhost; root /opt/soft/nginx/html/zabbix; location / { index index.html index.htm index.php; } location ~ .*\.(php|php5)?$ { index index.html index.htm index.php; fastcgi_pass 127.0.0.1:9000; #这就是php的启动ip加端口 fastcgi_index index.php; #首页为index.php fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name; include fastcgi.conf; }
# rsync -avz /opt/soft/package/zabbix-6.4.8/ui/ /opt/soft/nginx/html/zabbix/ >/dev/null
# chown -R work:work /opt/soft/nginx/html/zabbix
# /opt/soft/nginx/sbin/nginx
博文来自:www.51niux.com
2.6 Web页面进行配置
首先当然是浏览器:http://ip地址
#点击下一步后进入检查项
#进入到下一步
#后面的步骤就正常点下去就行了。之前的文档也有截图说明
#上图就是我们登录zabbix6.4的首页面了
#这时候你会发现有一个红色的地方,没错就是数据库中历史数据表已升级那里有红色的提示:
官网文档说明:https://www.zabbix.com/documentation/current/en/manual/appendix/install/db_float_range
# vim /opt/soft/nginx/html/zabbix/conf/zabbix.conf.php #因为我们是新环境不需要关注旧数据,将默认是false的改为true就行了
//$DB['DOUBLE_IEEE754'] = false; $DB['DOUBLE_IEEE754'] = true;
#再次刷新系统信息,整个界面清爽了再也没有错误提示了
2.7 解决中文乱码
#老问题了,需要将中文字体文件到web目录中来
#yum install wqy-microhei-fonts -y
#cp /usr/share/fonts/wqy-microhei/wqy-microhei.ttc /opt/soft/nginx/html/zabbix/assets/fonts/DejaVuSans.ttf
#因为zabbix的web目录下面的include/defines.inc.php文件定义了字体的路径
define('ZBX_FONTPATH', realpath('assets/fonts')); // where to search for font (GD > 2.0.18) define('ZBX_GRAPH_FONT_NAME', 'DejaVuSans'); // font file name
#然后重启php-fpm就好了
2.8 主机可用性为未知状态
#当然这个问题如果你的agent监控模版并非全是Zabbix客户端(主动式)也不会遇到。
一般我们肯定是选用agent active主动上报监控模版,这时候你可能会发现你的数据都正常采集了,但是zabbix可用性哪里还是未知灰色状态
#这时候你需要找一个监控项更换为客户端的模式,如下面:
#如果你是一分钟一采集的话,就过一分钟再看就可以了,666绿色的小图标成功点亮。
#至此新版zabbix的一些部署操作就结束了,剩下的改动不大,操作之前的zabbix系列文档然后把官方文档看一遍,就可以弄起来了。
三、zabbix升级操作
#我们zabbix版本不能一直不升级吧,那些新特性好想用。这里以从6.4.9升级到6.4.12最新版本举例。
官网文档:https://www.zabbix.com/documentation/current/zh/manual/installation/upgrade/sources
这里就不做详细记录了,根据官网文档操作就行,就可以升级到最新版了。