当前位置:网站首页>zabbix5.0的安装与实现
zabbix5.0的安装与实现
2022-07-21 05:21:00 【ehuo_】
zabbix实战
实验一:安装zabbix5.0
范例: 在ubuntu20.04 安装 Zabbix Server 5.0
#官网下载
[email protected]:~# wget https://repo.zabbix.com/zabbix/5.0/ubuntu/pool/main/z/zabbix-release/zabbix-release_5.0-1+focal_all.deb
--2022-06-22 21:33:23-- https://repo.zabbix.com/zabbix/5.0/ubuntu/pool/main/z/zabbix-release/zabbix-release_5.0-1+focal_all.deb
Resolving repo.zabbix.com (repo.zabbix.com)... 178.128.6.101, 2604:a880:2:d0::2062:d001
Connecting to repo.zabbix.com (repo.zabbix.com)|178.128.6.101|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 4244 (4.1K) [application/octet-stream]
Saving to: ‘zabbix-release_5.0-1+focal_all.deb’
zabbix-release_5.0-1+focal_all 100%[====================================================>] 4.14K --.-KB/s in 0s
2022-06-22 21:33:24 (367 MB/s) - ‘zabbix-release_5.0-1+focal_all.deb’ saved [4244/4244]
[email protected]:~# dpkg -i zabbix-release_5.0-1+focal_all.deb
Selecting previously unselected package zabbix-release.
(Reading database ... 114056 files and directories currently installed.)
Preparing to unpack zabbix-release_5.0-1+focal_all.deb ...
Unpacking zabbix-release (1:5.0-1+focal) ...
Setting up zabbix-release (1:5.0-1+focal) ...
[email protected]:~# dpkg -L zabbix-release
/.
/etc
/etc/apt
/etc/apt/sources.list.d
/etc/apt/sources.list.d/zabbix.list
/etc/apt/trusted.gpg.d
/etc/apt/trusted.gpg.d/zabbix-official-repo.gpg
/usr
/usr/share
/usr/share/doc
/usr/share/doc/zabbix-release
/usr/share/doc/zabbix-release/README.Debian
/usr/share/doc/zabbix-release/changelog.Debian
/usr/share/doc/zabbix-release/copyright
#镜像加速
[email protected]:/etc/apt/sources.list.d# sed -i.bak 's#http://repo.zabbix.com#https://mirror.tuna.tsinghua.edu.cn/zabbix#' /etc/apt/sources.list.d/zabbix.list
[email protected]:~# cat /etc/apt/sources.list.d/zabbix.list
deb https://mirror.tuna.tsinghua.edu.cn/zabbix/zabbix/5.0/ubuntu focal main
deb-src https://mirror.tuna.tsinghua.edu.cn/zabbix/zabbix/5.0/ubuntu focal main
[email protected]:~# apt update
#安装包
[email protected]:~#apt -y install zabbix-server-mysql zabbix-frontend-php zabbix-nginx-conf zabbix-agent2 zabbix-get
#安装数据库MySQL
[email protected]:~# apt -y install mysql-server
#如果MySQL和ZabbixServer在同一台主机,此项可不改
[[email protected] ~]#vim /etc/mysql/mysql.conf.d/mysqld.cnf
bind-address = 0.0.0.0
[[email protected] ~]#systemctl restart mysql.service
mysql> create database zbbix character set utf8 collate utf8_bin;
Query OK, 1 row affected, 2 warnings (0.00 sec)
mysql> create user [email protected]'10.0.0.%' identified by '123456';
Query OK, 0 rows affected (0.01 sec)
mysql> grant all privileges on zabbix.* to [email protected]'10.0.0.%';
Query OK, 0 rows affected (0.00 sec)
mysql> select user,host from mysql.user;
+------------------+-----------+
| user | host |
+------------------+-----------+
| zabbix | 10.0.0.% |
| debian-sys-maint | localhost |
| mysql.infoschema | localhost |
| mysql.session | localhost |
| mysql.sys | localhost |
| root | localhost |
+------------------+-----------+
6 rows in set (0.00 sec)
mysql> exit
Bye
#初绐化数据库的表
[[email protected] ~]#zcat /usr/share/doc/zabbix-server-mysql*/create.sql.gz | mysql -uzabbix -p123456 zabbix
#修改Zabbix Server 连接MySQL
[[email protected] ~]#vim /etc/zabbix/zabbix_server.conf
DBPassword=123456
[email protected]:~# cat /etc/zabbix/nginx.conf
server {
listen 80;
server_name zabbix.ehuo.org; #修改主机名
# listen 80;
# server_name 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;
}
}
[email protected]:~#
[email protected]:~# sed -i.bak '/date.timezone/c php_value[date.timezone] = Asia/Shanghai' /etc/zabbix/php-fpm.conf
[email protected]:~# ^C
[email protected]:~# cat /etc/zabbix/php-fpm.conf
[zabbix]
user = www-data
group = www-data
listen = /var/run/php/zabbix.sock
listen.owner = www-data
listen.allowed_clients = 127.0.0.1
pm = dynamic
pm.max_children = 50
pm.start_servers = 5
pm.min_spare_servers = 5
pm.max_spare_servers = 35
php_value[session.save_handler] = files
php_value[session.save_path] = /var/lib/php/sessions/
php_value[max_execution_time] = 300
php_value[memory_limit] = 128M
php_value[post_max_size] = 16M
php_value[upload_max_filesize] = 2M
php_value[max_input_time] = 300
php_value[max_input_vars] = 10000
php_value[date.timezone] = Asia/Shanghai
#安装中文包
[[email protected] ~]#apt -y install language-pack-zh-hans
[email protected]:~# systemctl disable --now apache2
Synchronizing state of apache2.service with SysV service script with /lib/systemd/systemd-sysv-install.
Executing: /lib/systemd/systemd-sysv-install disable apache2
Removed /etc/systemd/system/multi-user.target.wants/apache2.service.
[email protected]:~# systemctl restart zabbix-server zabbix-agent2 nginx php7.4-fpm
[email protected]:~# systemctl enable zabbix-server
Synchronizing state of zabbix-server.service with SysV service script with /lib/systemd/systemd-sysv-install.
Executing: /lib/systemd/systemd-sysv-install enable zabbix-server
Created symlink /etc/systemd/system/multi-user.target.wants/zabbix-server.service → /lib/systemd/system/zabbix-server.service.
[email protected]:~#
第一次登录, 默认的用户名是 Admin,密码是zabbix
安装zabbix5.0脚本
wget https://repo.zabbix.com/zabbix/5.0/ubuntu/pool/main/z/zabbix-release/zabbix-release_5.0-1+focal_all.deb
dpkg -i zabbix-release_5.0-1+focal_all.deb
sed -i.bak 's#http://repo.zabbix.com#https://mirror.tuna.tsinghua.edu.cn/zabbix#' /etc/apt/sources.list.d/zabbix.list
apt update
apt -y install zabbix-server-mysql zabbix-frontend-php zabbix-nginx-conf zabbix-agent2
apt -y install mysql-server
cat << EOF | mysql
create database zabbix character set utf8 collate utf8_bin;
create user [email protected] identified by '123456';
grant all privileges on zabbix.* to [email protected];
EOF
zcat /usr/share/doc/zabbix-server-mysql*/create.sql.gz | mysql -uzabbix -p123456 zabbix
sed -i.bak '/# DBPassword/a DBPassword=123456' /etc/zabbix/zabbix_server.conf
sed -i.bak '/^server/a\ listen 80;\n server_name zabbix.ehuo.org;' /etc/zabbix/nginx.conf
sed -i.bak '/date.timezone/c php_value[date.timezone] = Asia/Shanghai' /etc/zabbix/php-fpm.conf
systemctl disable --now apache2
systemctl restart zabbix-server zabbix-agent2 nginx php7.4-fpm
systemctl enable zabbix-server
因为字体兼容性的原因,在显示中文时可能会有乱码出现
[email protected] fonts]#pwd
/usr/share/zabbix/assets/fonts
#支持ttf和ttc后缀的字体文件
[[email protected] fonts]#mv graphfont.ttf graphfont.ttf.bak
[[email protected] fonts]#mv SIMYOU.TTF graphfont.ttf
[[email protected] fonts]#ls
graphfont.ttf graphfont.ttf.bak
#注意:字体文件路径和名称的定义在文件/usr/share/zabbix/include/defines.inc.php中配置
#可以修改下面FONT_NAME指定新字体件,注意不需加文件后缀
[[email protected] ~]#grep FONT_NAME /usr/share/zabbix/include/defines.inc.php
define('ZBX_GRAPH_FONT_NAME', 'graphfont'); // font file name
define('ZBX_FONT_NAME', 'graphfont');
[email protected]:/usr/share/zabbix/assets/fonts# mv SIMYOU.TTF graphfont.ttf
[email protected]:/usr/share/zabbix/assets/fonts# ls
graphfont.ttf graphfont.ttf.bak MSYH.TTC
[email protected]:/usr/share/zabbix/assets/fonts# grep FONT_NAME /usr/share/zabbix/include/defines.inc.php
define('ZBX_GRAPH_FONT_NAME', 'graphfont'); // font file name
define('ZBX_FONT_NAME', 'graphfont');
[email protected]:/usr/share/zabbix/assets/fonts#
注意:乱码和语言环境无关,英语环境也支持中文显示,但会有乱码
范例: Rocky8 安装Zabbix Agent2
#从国内镜像下载
[[email protected] ~]#rpm -ivh https://mirror.tuna.tsinghua.edu.cn/zabbix/zabbix/6.0/rhel/8/x86_64/zabbix-agent2-6.0.5-1.el8.x86_64.rpm
[[email protected] ~]# rpm -ql https://mirror.tuna.tsinghua.edu.cn/zabbix/zabbix/6.0/rhel/8/x86_64/zabbix-agent2-6.0.5-1.el8.x86_64.rpm
warning: https://mirror.tuna.tsinghua.edu.cn/zabbix/zabbix/6.0/rhel/8/x86_64/zabbix-agent2-6.0.5-1.el8.x86_64.rpm: Header V4 RSA/SHA512 Signature, key ID a14fe591: NOKEY
/etc/logrotate.d/zabbix-agent2
/etc/zabbix/zabbix_agent2.conf
/etc/zabbix/zabbix_agent2.d
/etc/zabbix/zabbix_agent2.d/plugins.d/ceph.conf
/etc/zabbix/zabbix_agent2.d/plugins.d/docker.conf
/etc/zabbix/zabbix_agent2.d/plugins.d/memcached.conf
/etc/zabbix/zabbix_agent2.d/plugins.d/modbus.conf
/etc/zabbix/zabbix_agent2.d/plugins.d/mongodb.conf
/etc/zabbix/zabbix_agent2.d/plugins.d/mqtt.conf
/etc/zabbix/zabbix_agent2.d/plugins.d/mysql.conf
/etc/zabbix/zabbix_agent2.d/plugins.d/oracle.conf
/etc/zabbix/zabbix_agent2.d/plugins.d/postgres.conf
/etc/zabbix/zabbix_agent2.d/plugins.d/redis.conf
/etc/zabbix/zabbix_agent2.d/plugins.d/smart.conf
/usr/lib/.build-id
/usr/lib/.build-id/88
/usr/lib/.build-id/88/e20f765be60a306e65225d3110fae01371ddee
/usr/lib/systemd/system/zabbix-agent2.service
/usr/lib/tmpfiles.d/zabbix_agent2.conf
/usr/sbin/zabbix_agent2
/usr/share/doc/zabbix-agent2
/usr/share/doc/zabbix-agent2/AUTHORS
/usr/share/doc/zabbix-agent2/COPYING
/usr/share/doc/zabbix-agent2/ChangeLog
/usr/share/doc/zabbix-agent2/NEWS
/usr/share/doc/zabbix-agent2/README
/usr/share/man/man8/zabbix_agent2.8.gz
/var/log/zabbix
/var/run/zabbix
[email protected] ~]#vim /etc/zabbix/zabbix_agent2.conf
Server=zabbix.ehuo.org
[[email protected] ~]#systemctl enable --now zabbix-agent2.service
[[email protected] ~]#ss -ntlp|grep zabbix
LISTEN 0 128 *:10050 *:* users:
(("zabbix_agent2",pid=22792,fd=8))
[[email protected] ~]#zabbix_get -s 10.0.0.8 -k agent.ping
1
范例: 原来生成环境zabbix agent 升级到zabbix agent2
#停止agent 防止端口10050/tcp冲突
[[email protected] ~]#system disable --now zabbix-agent
#安装
[[email protected] ~]#apt -y install zabbix-agent2
[[email protected] ~]#yum -y install zabbix-agent2
#配置文件和agent相同
[[email protected] ~]#grep -vE '^$|#' /etc/zabbix/zabbix_agent2.conf
PidFile=/var/run/zabbix/zabbix_agent2.pid
LogFile=/var/log/zabbix/zabbix_agent2.log
LogFileSize=0
Server=10.0.0.100 #修改此行
ServerActive=127.0.0.1
Hostname=Zabbix server
Include=/etc/zabbix/zabbix_agent2.d/*.conf
ControlSocket=/tmp/agent.sock
[[email protected] ~]#systemctl restart zabbix-agent2
#在Zabbix Server测试
[[email protected] ~]#zabbix_get -s 10.0.0.58 -k 'agent.ping'
1
#agent2是多线程
[[email protected] ~]#pstree -p|grep zabbix_agent2
`-zabbix_agent2(1825)-+-{zabbix_agent2}(1826)
|-{zabbix_agent2}(1827)
|-{zabbix_agent2}(1828)
|-{zabbix_agent2}(1829)
|-{zabbix_agent2}(1830)
|-{zabbix_agent2}(1831)
`-{zabbix_agent2}(1833)
#agent是多进程
[[email protected] ~]#pstree -p | grep zabbix_agent
`-zabbix_agentd(1448)-+-zabbix_agentd(1449)
|-zabbix_agentd(1450)
|-zabbix_agentd(1451)
|-zabbix_agentd(1452)
`-zabbix_agentd(1453)
案例:将Zabbix Server的MySQL 数据库迁移到独立的MySQL服务器
#备份数据库
[[email protected] ~]#mysqldump -uroot -A -F --single-transaction > /data/all.sql
[[email protected] ~]#systemctl stop zabbix-server.service
[[email protected] ~]#systemctl disable --now mysql
#在独立数据库服务器上安装并恢复数据库
[[email protected] ~]#apt -y install mysql-server
[[email protected] ~]#mysql < all.sql
#重新授权用户允许远程连接zabbix数据库
[[email protected] ~]#mysql
mysql> grant all privileges on zabbix.* to zabbix'10.0.0.%' identified by '123456';
#将php的配置指向新的数据库服务器IP
[[email protected] ~]#vim /usr/share/zabbix/conf/zabbix.conf.php
$DB['SERVER'] = '10.0.0.101';
#将Zabbix Server的配置指向新的数据库服务器IP
[[email protected] ~]#vim /etc/zabbix/zabbix_server.conf
DBHost=10.0.0.101
DBPort=3306
#重启服务生效
[[email protected] ~]#systemctl start zabbix-server.service
rivileges on zabbix.* to zabbix’10.0.0.%’ identified by ‘123456’;
#将php的配置指向新的数据库服务器IP
[[email protected] ~]#vim /usr/share/zabbix/conf/zabbix.conf.php
$DB[‘SERVER’] = ‘10.0.0.101’;
#将Zabbix Server的配置指向新的数据库服务器IP
[[email protected] ~]#vim /etc/zabbix/zabbix_server.conf
DBHost=10.0.0.101
DBPort=3306
#重启服务生效
[[email protected] ~]#systemctl start zabbix-server.service
边栏推荐
- LAMP架构——mysql路由器(读写分离器)
- Five states of the process
- Data driven testing of hand-in-hand teaching UI automation
- 235. Nearest common ancestor DFS method of binary search tree
- Solutions to the situation that some software cannot start and start automatically (solved)
- 2. Modules communs dans ansible
- [untitled] this year's noteworthy God book, Douban scored as high as 9.0, and Jingdong Dangdang is available for sale
- The actual case of Cisco configuring single arm routing is very simple
- 12. User microservice
- Lamp Architecture - mysq cluster and master-slave replication (2)
猜你喜欢
[untitled] this year's noteworthy God book, Douban scored as high as 9.0, and Jingdong Dangdang is available for sale
Dry goods | overview of RDBMS index types
win7系统忘记登录密码怎么办?(不用启动盘情况下)
Jenkins build
Complete IP protocol number
2. Common modules in ansible
File download, how to write the use case?
What happens when you have threads
What information does the process control block (PCB) contain
The organization mode of the process: link mode and index mode
随机推荐
3.使用Ansible中的playbook
Zabbix+ distributed database tidb realizes distributed database monitoring
Dbeaver vs Navicat: database tool duel
DNS domain name resolution service
虛擬機的封裝
JMeter's BeanShell generates random Chinese characters
[rviz2] error occurs when importing URDF model: could not load resource XXX, unable to open file XXX, error retrieving file XXX
Markdown and idea shortcut keys
Complete IP protocol number
Stack differences
postman newman jenkins
LVS的不足之处及第四种转发类型FULLNAT
Blocking and wakeup of processes
Kruskal reconstruction tree
Lamp Architecture - MySQL high availability switching (MHA high availability)
Using disassembly debugging and complement to explain 0x80000000 / -1 shaping output exception inconsistency
PeopleSoft warning, error, message box
[secondary development of GeoServer] development of rest automatic deployment module based on GeoServer Manager
3. Use playbook in ansible
Importance of database monitoring