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
标签:bin,zabbix5.0,mnt,server,zabbix,mysql,安装,rhd
From: https://www.cnblogs.com/kkit/p/18343577