zabbix
簡介
zabbix_server版本: 5.0.12
linux系統版本: centos7
安裝包路徑: https://www.zabbix.com/cn/
yum安裝
# install zabbix repository
rpm -Uvh https://repo.zabbix.com/zabbix/5.0/rhel/7/x86_64/zabbix-release-5.0-1.el7.noarch.rpm
yum clean all
# install zabbix-server web前端 agent
yum install zabbix-server-mysql zabbix-agent
# install zabbix frontend
# 編輯倉庫配置檔案 開啟zabbix-frontend
[zabbix-frontend]
...
enabled=1
...
# 命令列開啟
yum-config-manager --enable rhel-server-rhscl-7-rpms
# 安裝
yum install zabbix-web-mysql-scl zabbix-apache-conf-scl
安裝資料庫
version: mysql_5.7.22_二進位制包
安裝包位置: https:/downloads.mysql.com/archives/community/
# 下載安裝包
wget https://cdn.mysql.com/archives/mysql-5.7/mysql-5.7.22-linux-glibc2.12-x86_64.tar.gz
# 刪除centos7中自帶的mariadb-libs
rpm -e mariadb-libs --nodeps
# 建立使用者和組並賦予資料夾許可權
groupadd -r mysql
useradd -r -g mysql -M -s /bin/false mysql
tar -zxf /root/mysql-5.7.22-linux-glibc2.12-x86_64.tar.gz
# 將二進位制包移動到/usr/local/mysql
mv mysql-5.722-linux-glibc2.12-x86_64 /mnt/rhd/mysql
# 做服務的軟連結
ln -s /mnt/rhd/mysql/bin/* /usr/local/bin/
# 建立所需目錄
mkdir /mnt/rhd/mysql/conf
mkdir /mnt/rhd/mysql/data
mkdir /mnt/rhd/mysql/dbbak
mkdir /mnt/rhd/mysql/logs
mkdir /mnt/rhd/mysql/redo
mkdir /mnt/rhd/mysql/undo
chown -R mysql.mysql /mnt/rhd/mysql
# 建立systemctl管理mysql
cat /usr/lib/systemd/system/mysqld.service <<EOF
[Unit]
Description=MySQL Server
After=network.target
[Install]
WantedBy=multi-user.target
[Service]
Type=simple
PrivateNetwork=false
User=mysql
Group=mysql
CapabilityBoundingSet=CAP_IPC_LOCK
ProtectSystem=full
PrivateDevices=true
ProtectHome=true
PermissionsStartOnly=true
PIDFile=/mnt/rhd/mysql/data/mysql.pid
ExecStart=/mnt/rhd/mysql/bin/mysqld_safe --defaults-file=/mnt/rhd/mysql/conf/my.cnf --user=mysql
ExecStop=/bin/kill -9 $MAINPID
KillSignal=SIGTERM
SendSIGKILL=no
Restart=on-abort
RestartSec=5s
UMask=007
PrivateTmp=false
TimeoutStartSec=900
TimeoutStopSec=900
LimitNOFILE=16384
EOF
# 載入配置
systemctl daemon-reload
# 編輯my.cnf配置檔案
cat>/mnt/rhd/mysql/conf/my.cnf <<EOF
[client]
port = 3316
socket = /mnt/rhd/mysql/logs/mysql.sock
[mysqld]
explicit_defaults_for_timestamp=true
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
#sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES,NO_ZERO_DATE,NO_ZERO_IN_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER
port = 3316
basedir = /mnt/rhd/mysql
datadir = /mnt/rhd/mysql/data
server_id = 803316
socket = /mnt/rhd/mysql/logs/mysql.sock
back_log = 350
connect_timeout = 20
event_scheduler = off
local_infile = off
secure_file_priv = /mnt/rhd/mysql/dbbak
pid-file = /mnt/rhd/mysql/data/mysql.pid
wait_timeout = 1800
interactive_timeout =1800
character_set_server = utf8mb4
skip_name_resolve
log_timestamps=system
skip-ssl
disable-partition-engine-check
#skip_grant_tables
######### bin log ####################
binlog_format = row
binlog_row_image = full
binlog_cache_size = 2M
max_binlog_size = 1G
max_binlog_cache_size = 4G
binlog_rows_query_log_events = 0
master_verify_checksum = 1
slave_allow_batching = 1
expire_logs_days = 7
log-bin =/mnt/rhd/mysql/logs/mysql_bin
######### error log ####################
#log_warnings = 2
log_error = /mnt/rhd/mysql/logs/error.log
log_syslog
log_syslog_tag = 3316
########## general_log ####################
#general_log_file = /mnt/rhd/mysql/logs/general.log
########## slow log ####################
long_query_time = 1
slow_query_log = on
log_queries_not_using_indexes = off
#log_slow_admin_statements = on
slow_query_log_file = /mnt/rhd/mysql/logs/slow.log
skip_slave_start
read_only = off
slave_parallel_type = logical_clock
slave_parallel_workers = 4
relay_log_info_repository = TABLE
master_info_repository = TABLE
relay_log_recovery = on
sync_master_info = 10000
slave_compressed_protocol = off
slave_net_timeout = 10
log_slave_updates
relay_log=/mnt/rhd/mysql/logs/relay_bin
#auto-increment-increment = 2
#auto-increment-offset = 2
#slave_skip_errors = all
#slave-skip-errors=1064 1146 1062
#rpl_semi_sync_master_enabled = ON
#rpl_semi_sync_slave_enabled = ON
#rpl_semi_sync_master_timeout = 10000
gtid_mode = ON
enforce_gtid_consistency = ON
relay_log_purge=0
#replicate_wild_ignore_table =mysql.%
#replicate_wild_ignore_table =information_schema.%
#replicate_wild_ignore_table =performance_scheme.%
#replicate_wild_ignore_table =sys.%
#replicate_wild_ignore_table =percona.%
########### innodb ####################
default_storage_engine = InnoDB
innodb_buffer_pool_size = 12G
innodb_buffer_pool_instances = 6
innodb_data_home_dir = /mnt/rhd/mysql/data/
#innodb_data_file_path = ibdata1:1000M;ibdata2:100M:autoextend
innodb_log_group_home_dir = /mnt/rhd/mysql/redo/
innodb_log_files_in_group = 3
innodb_log_file_size = 256M
innodb_log_buffer_size = 8M
innodb_lock_wait_timeout = 40
innodb_file_per_table = 1
innodb_stats_on_metadata = OFF
lower_case_table_names = 1
innodb_flush_method = O_DIRECT
innodb_flush_log_at_trx_commit = 1
log_bin_trust_function_creators = 1
sync_binlog = 1
innodb_open_files = 1024
innodb_thread_concurrency = 0
innodb_print_all_deadlocks = ON
performance_schema = ON
innodb_undo_log_truncate = 1
innodb_undo_tablespaces = 0
innodb_rollback_segments = 128
innodb_max_undo_log_size = 1073741824
innodb_undo_directory = /mnt/rhd/mysql/undo/
#innodb_purge_threads = 1
##innodb_write_io_threads = 4
##innodb_read_io_threads = 4
#thread_pool
#thread_handling =pool-of-threads
#thread_pool_stall_limit =10
#########for SSD ###################
innodb_io_capacity = 2000
innodb_adaptive_flushing = OFF
innodb_flush_neighbors = 2
#########per_thread_buffers####################
max_connections = 3000
max_connect_errors = 2048
max_allowed_packet = 32M
max_heap_table_size = 256M
tmp_table_size = 256M
max_prepared_stmt_count = 1M
query_alloc_block_size = 128K
query_cache_limit = 0
query_cache_size = 0
join_buffer_size = 512k
key_buffer_size = 1M
query_cache_type = 0
query_prealloc_size = 64K
read_buffer_size = 1M
read_rnd_buffer_size = 512K
sort_buffer_size = 2M
table_open_cache = 2048
table_open_cache_instances= 8
thread_cache_size = 128
group_concat_max_len = 2048
skip-external-locking
#myisam
#myisam_recover_options=BACKUP,FORCE
#key_buffer_size=2G
[mysqldump]
max_allowed_packet = 32M
EOF
# 初始化mysql,記住初始密碼
mysqld --initialize --user=mysql --basedir=/mnt/rhd/mysql/ --datadir=/mnt/rhd/mysql/data
# 修改密碼
systemctl restart mysqld
mysqlpwd=剛才初始化是自動生成的密碼
mysql -uroot -p${mysqlpwd} -e 'alter user root@localhost identified by"123.com"' --connect-expired-password
# 建立zabbix資料庫
# mysql -uroot -p
password
mysql> create database zabbix character set utf8 collate utf8_bin;
mysql> create user zabbix@localhost identified by 'password';
mysql> grant all privileges on zabbix.* to zabbix@localhost;
mysql> set global log_bin_trust_function_creators = 1;
mysql> quit;
# 匯入資料庫
# zcat /usr/share/doc/zabbix-server-mysql*/create.sql.gz | mysql -uzabbix -p zabbix
# 禁用 log_bin_trust_function_creators選項
# mysql -uroot -p
password
mysql> set global log_bin_trust_function_creators = 0;
mysql> quit;
配置zabbix_server配置檔案
# /etc/zabbix/zabbix_server.conf
DBPassword=password
配置php檔案
# /etc/opt/rh/rh-php72/php-fpm.d/zabbix.conf
php_value[date.timezone] = Asia/Shanghai
啟動服務
systemctl restart zabbix-server zabbix-agent httpd rh-php72-php-fpm
systemctl enable zabbix-server zabbix-agent httpd rh-php72-php-fpm
訪問
http:IP/zabbix
檢查所有元件ok -----------------> 填寫mysql資料庫的連線資訊 -----------------> 其他直接點選下一步 ---------> successfully-------finish
測試
# 網頁端新增主機,檢視是否有監控值
# 服務命令列端測試
zabbix_get -s 127.0.0.1 -p 10050 -k system.cpu.load[all,avg1]
問題
# 問題一: 顯示中文亂碼解決方法
### zabbix-server 伺服器上安裝如下檔案字符集
yum install wqy-microhei-fonts
### 然後替換linux上預設的字符集
cp /usr/share/fonts/wqy-microhei/wqy-microhei.ttc /usr/share/fonts/dejavu/DejaVuSans.ttf
### 重啟
systemctl restart zabbix-server