1、架构及主机准备 环境:zabbix5.0 LTS,ubuntu20.04,mysql8.0,nginx主机: zabbix-server:10.0.0.100 mysql-server:10.0.0.101 2、数据库服务器准备 ubuntu20.04版本的系统自带的mysql版本就是8.0的,
1、架构及主机准备
环境:zabbix5.0 LTS,ubuntu20.04,mysql8.0,nginx 主机: zabbix-server:10.0.0.100 mysql-server:10.0.0.101
2、数据库服务器准备
ubuntu20.04版本的系统自带的mysql版本就是8.0的,这里我就直接使用apt安装了 root@mysql-server:~# apt update root@mysql-server:~# apt -y install mysql-server mysql-client 配置数据库环境(首先对数据库安全做一下初始化) root@mysql-server:~# vim /etc/mysql/mysql.conf.d/mysqld.cnf bind-address = 0.0.0.0 #默认安装后的mysql只能本地连接,外部连接不了,这里之所以改成了0.0.0.0,即允许所有的IP访问。 default_authentication_plugin=mysql_native_password #设置数据库默认的认证方式 character-set-server=utf8 default-storage-engine=INNODB root@mysql-server:~# systemctl restart mysql root@mysql-server:~# mysql mysql> use mysql; mysql> select user,host,plugin from user; mysql> ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'Mysql@2022'; mysql> select user,host,plugin from user; mysql> FLUSH PRIVILEGES; #修改完后记得刷新一下权限 准备zabbix需要的数据库(mysql8.0创建用户并授权时需要分开两步完成,先创建用户,在授权) root@mysql-server:~# mysql -uroot -pMysql@2022 mysql> create database zabbix_server character set utf8 collate utf8_bin; mysql> create user zabbix@'10.0.0.%' identified by "Zabbix@123"; mysql> grant all privileges on zabbix_server.* to zabbix@"10.0.0.%"; mysql> flush privileges; mysql> select host,user,authentication_string,plugin from mysql.user; 验证创建的zabbix用户连接性 root@mysql-server:~# mysql -uzabbix -p'Zabbix@123' -h10.0.0.101 mysql> show databases; +--------------------+ | Database | +--------------------+ | information_schema | | performance_schema | | zabbix_server | +--------------------+ 3 rows in set (0.00 sec)
3、apt安装zabbix服务
官网步骤:https://www.zabbix.com/cn/download?zabbix=5.0&os_distribution=ubuntu&os_version=20.04&components=server_frontend_agent&db=mysql&ws=nginx 1、下载zabbix储存库
root@zabbix-server:~# wget https://repo.zabbix.com/zabbix/5.0/ubuntu/pool/main/z/zabbix-release/zabbix-release_5.0-1%2Bfocal_all.deb root@zabbix-server:~# dpkg -i zabbix-release_5.0-1+focal_all.deb root@zabbix-server:~# sed -i.bak 's#http://repo.zabbix.com#https://mirrors.aliyun.com/zabbix#' /etc/apt/sources.list.d/zabbix.list #修改官方的源地址,在这样会下载会快点 root@zabbix-server:~# cat /etc/apt/sources.list.d/zabbix.list deb https://mirrors.aliyun.com/zabbix/zabbix/5.0/ubuntu focal main deb-src https://mirrors.aliyun.com/zabbix/zabbix/5.0/ubuntu focal main2、安装Zabbix server,Web前端,agent
root@zabbix-server:~# apt update root@zabbix-server:~# apt install -y zabbix-server-mysql zabbix-frontend-php zabbix-nginx-conf zabbix-agent3、导入初始化架构和数据
root@zabbix-server:~# ll /usr/share/doc/zabbix-server-mysql/create.sql.gz -rw-r--r-- 1 root root 1999025 Sep 19 14:49 /usr/share/doc/zabbix-server-mysql/create.sql.gz root@zabbix-server:~# apt -y install mysql-client #安装mysql客户端 root@zabbix-server:~# zcat /usr/share/doc/zabbix-server-mysql/create.sql.gz | mysql -uzabbix -p'Zabbix@123' -h'10.0.0.101' zabbix_server #初始化数据库4、验证对数据库初始化后的数据表信息
root@zabbix-server:~# mysql -uzabbix -p'Zabbix@123' -h'10.0.0.101' mysql> show databases; mysql> use zabbix_server; mysql> show tables;5、zabbix server配置数据库
root@zabbix-server:~# ll /etc/zabbix/zabbix_server.conf -rw------- 1 root root 22306 Sep 19 14:49 /etc/zabbix/zabbix_server.conf root@zabbix-server:~# vim /etc/zabbix/zabbix_server.conf DBHost=10.0.0.101 DBName=zabbix_server DBUser=zabbix DBPassword=Zabbix@123 DBPort=3306 root@zabbix-server:~# grep -Ev '^#|^$' /etc/zabbix/zabbix_server.conf LogFile=/var/log/zabbix/zabbix_server.log LogFileSize=0 PidFile=/run/zabbix/zabbix_server.pid SocketDir=/run/zabbix DBHost=10.0.0.101 DBName=zabbix_server DBUser=zabbix DBPassword=Zabbix@123 DBPort=3306 SNMPTrapperFile=/var/log/snmptrap/snmptrap.log Timeout=4 AlertScriptsPath=/usr/lib/zabbix/alertscripts ExternalScripts=/usr/lib/zabbix/externalscripts FpingLocation=/usr/bin/fping Fping6Location=/usr/bin/fping6 LogSlowQueries=3000 StatsAllowedIP=127.0.0.16、配置Zabbix前端配置PHP 我这webserver是使用的nginx,数据库是使用的mysql,这里我就修改一下nginx的配置
root@zabbix-server:~# ll /etc/nginx/conf.d/zabbix.conf #这个文件其实是一个软连接文件 lrwxrwxrwx 1 root root 22 Oct 31 12:28 /etc/nginx/conf.d/zabbix.conf -> /etc/zabbix/nginx.conf root@zabbix-server:~# vim /etc/nginx/conf.d/zabbix.conf root@zabbix-server:~# cat /etc/nginx/conf.d/zabbix.conf server { listen 80; #默认是注释的 server_name 10.0.0.100; #默认是example.com root /usr/share/zabbix; index index.php; location = /favicon.ico { log_not_found off; } location / { try_files $uri $uri/ =404; } location /assets { access_log off; expires 10d; } location ~ /\.ht { deny all; } location ~ /(api\/|conf[^\.]|include|locale|vendor) { deny all; return 404; } location ~ [^/]\.php(/|$) { fastcgi_pass unix:/var/run/php/zabbix.sock; fastcgi_split_path_info ^(.+\.php)(/.+)$; fastcgi_index index.php; fastcgi_param DOCUMENT_ROOT /usr/share/zabbix; fastcgi_param SCRIPT_FILENAME /usr/share/zabbix$fastcgi_script_name; fastcgi_param PATH_TRANSLATED /usr/share/zabbix$fastcgi_script_name; include fastcgi_params; fastcgi_param QUERY_STRING $query_string; fastcgi_param REQUEST_METHOD $request_method; fastcgi_param CONTENT_TYPE $content_type; fastcgi_param CONTENT_LENGTH $content_length; fastcgi_intercept_errors on; fastcgi_ignore_client_abort off; fastcgi_connect_timeout 60; fastcgi_send_timeout 180; fastcgi_read_timeout 180; fastcgi_buffer_size 128k; fastcgi_buffers 4 256k; fastcgi_busy_buffers_size 256k; fastcgi_temp_file_write_size 256k; } } root@zabbix-server:~# vim /etc/zabbix/php-fpm.conf #将时区改为东八区上海 php_value[date.timezone] = Asia/Shanghai 启动zabbix相关服务,并设置开机自启动 root@zabbix-server:~# systemctl restart zabbix-server zabbix-agent nginx php7.4-fpm root@zabbix-server:~# systemctl enable zabbix-server zabbix-agent nginx php7.4-fpm4、web界面初始化
打开浏览器访问http://10.0.0.100/
5、Web界面修改成中文
1、系统安装中文语言环境并验证WEB页面
安装并设置中文简体语言环境 root@zabbix-server:~# apt -y install language-pack-zh* 增加中文语言环境变量 root@zabbix-server:~# echo 'LANG="zh_CN.UTF-8"' >> /etc/environment root@zabbix-server:~# cat /etc/environment PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin" LANG="zh_CN.UTF-8" 重新设置本地配置 root@zabbix-server:~# dpkg-reconfigure locales 配置完本地后再重启一下php7.4-fpm服务 root@zabbix-server:~# systemctl restart php7.4-fpm
6、解决上面图形乱码
在Windows主机上找到一个中文字体拷贝到zabbix server的web目录下
通过xftp工具或者使用rz命令上传到相关目录下 root@zabbix-server:~# cd /usr/share/zabbix/assets/fonts/ root@zabbix-server:/usr/share/zabbix/assets/fonts# ls graphfont.ttf simkai.ttf root@zabbix-server:/usr/share/zabbix/assets/fonts# chown zabbix.zabbix ./* 修改zabbix文件来调用新的字体 root@zabbix-server:~# cd /usr/share/zabbix/ root@zabbix-server:/usr/share/zabbix# vim include/defines.inc.php 81 #define('ZBX_GRAPH_FONT_NAME', 'graphfont'); // font file name 82 define('ZBX_GRAPH_FONT_NAME', 'simkai'); 123 #define('ZBX_FONT_NAME', 'graphfont'); 124 define('ZBX_FONT_NAME', 'simkai'); 修改完这个配置文件后,是立即生效的,把web页面刷新一下即可