Zabbix5.4安装详细过程(centos8.0+mysql8.0)

淳于星宇
2023-12-01

一、下载MYSQL二进制包文件 mysql-8.0.21-linux-glibc2.12-x86_64.tar.xz
二、上传mysql到centos8.0,解压  tar xvJf mysql-8.0.21-linux-glibc2.12-x86_64.tar.xz
三、mkdir -p /data/mysql
    mkdir -p /usr/local/mysql
    mkdir -p /var/lib/mysql
四、添加用户   groupadd mysql     useradd -g mysql mysql
五、创建和修改相关目录权限
     chown -R mysql.mysql /usr/local/mysql
     chown -R mysql.mysql /data/mysql    
     chown -R mysql.mysql /var/lib/mysql
     cp  -a -r mysql-8.0.25-linux-glibc2.12-x86_64/*  /usr/local/mysql/
     vi /etc/my.cnf   配置如下:
[client]
port=3306
socket=/var/lib/mysql/mysql.sock
[mysql]
no-auto-rehash
[mysqld]
user=mysql
port=3306
basedir=/usr/local/mysql
datadir=/data/mysql/
socket=/var/lib/mysql/mysql.sock
pid-file=/data/mysql/db.pid
character-set-server=utf8mb4
skip_name_resolve=1
open_files_limit=65535
back_log=1024
max_connections=512
max_connect_errors=1000000
table_open_cache=1024
table_definition_cache=1024
table_open_cache_instances=64
thread_stack=512K
external-locking=FALSE
max_allowed_packet=32M
sort_buffer_size=4M
join_buffer_size=4M
thread_cache_size=768
interactive_timeout=600
wait_timeout=600
tmp_table_size=32M
max_heap_table_size=32M
slow_query_log=1
slow_query_log_file=/data/mysql/slow.log
log-error=/data/mysql/error.log
long_query_time=0.1
server-id=3306101
expire_logs_days=7
log-bin=/data/mysql/mysql-bin
sync_binlog=1
binlog_cache_size=4M
max_binlog_cache_size=1G
max_binlog_size=1G
gtid_mode=on
enforce_gtid_consistency=1
log_slave_updates
binlog_format=row
relay_log_recovery=1
relay-log-purge=1
key_buffer_size=32M
read_buffer_size=8M
read_rnd_buffer_size=4M
bulk_insert_buffer_size=64M
lock_wait_timeout=3600
explicit_defaults_for_timestamp=1
innodb_thread_concurrency=0
innodb_sync_spin_loops=100
innodb_spin_wait_delay=30
transaction_isolation=REPEATABLE-READ
innodb_buffer_pool_size=512M
innodb_buffer_pool_instances=8
innodb_buffer_pool_load_at_startup=1
innodb_buffer_pool_dump_at_shutdown=1
innodb_data_file_path=ibdata1:1G:autoextend
innodb_flush_log_at_trx_commit=1
innodb_log_buffer_size=32M
innodb_log_file_size=2G
innodb_log_files_in_group=2
innodb_max_undo_log_size=4G
innodb_io_capacity=4000
innodb_io_capacity_max=8000
innodb_flush_neighbors=0
innodb_write_io_threads=8
innodb_read_io_threads=8
innodb_purge_threads=4
innodb_page_cleaners=4
innodb_open_files=65535
innodb_max_dirty_pages_pct=50
innodb_flush_method=O_DIRECT
innodb_lru_scan_depth=4000
innodb_checksum_algorithm=crc32
innodb_lock_wait_timeout=10
innodb_rollback_on_timeout=1
innodb_print_all_deadlocks=1
innodb_file_per_table=1
innodb_online_alter_log_max_size=4G
innodb_stats_on_metadata=0
default_authentication_plugin=mysql_native_password

[mysqldump]
quick
max_allowed_packet=32M


六、初始化MYSQL

cd /usr/local/mysql/bin/  
      /usr/local/mysql/bin/mysqld --defaults-file=/etc/my.cnf  --basedir=/usr/local/mysql --datadir=/data/mysql --user=mysql --initialize     
      
七、创建自动启动 

 cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysql
       chmod  +x /etc/init.d/mysql
       chkconfig --add mysql
       
八、启动 service mysql start    
   
九、  将mysql命令添加到服务  ln -s /usr/local/mysql/bin/mysql /usr/bin
       ln -s /usr/lib64/libtinfo.so.6.1 /usr/lib64/libtinfo.so.5
      #mysql -uroot -p   /随机密码在错误日志里 /data/mysql/error日志中可以找到
      修改root密码:  
      ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'password';
      flush privileges;
      修改远程连接并生效
        use mysql;
        update user set host='%' where user='root';
        flush privileges;
       

ZABBIX编译安装:        
一、添加用户
groupadd --system zabbix
useradd --system -g zabbix -d /usr/lib/zabbix -s /sbin/nologin -c "Zabbix Monitoring System" zabbix
mkdir -m u=rwx,g=rwx,o= -p /usr/lib/zabbix
chown zabbix:zabbix /usr/lib/zabbix

mysql -uroot -p
create database zabbix character set utf8 collate utf8_bin;
create user 'zabbix'@'localhost' identified by 'password';
grant all privileges on zabbix.* to 'zabbix'@'localhost';
flush privileges;

# cd /tmp/zabbix-5.4.0/database/mysql
# mysql -uzabbix -p zabbix < schema.sql
# stop here if you are creating database for Zabbix proxy
# mysql -uzabbix -p zabbix < images.sql
# mysql -uzabbix -p zabbix < data.sql


二、GCC环境安装

yum install gcc gcc-c++ autoconf automake zlib zlib-devel openssl openssl-devel pcre pcre-devel   -y
yum install  net-snmp net-snmp-devel libxml2-devel libevent libevent-devel libcurl  mysql-devel libcurl-devel  -y
yum install make -y
yum install httpd  -y  Apache安装
三、php安装:
sudo dnf -y install https://dl.fedoraproject.org/pub/epel/epel-release-latest-8.noarch.rpm
dnf install https://rpms.remirepo.net/enterprise/remi-release-8.rpm
dnf module list php
dnf module reset php
dnf module enable php:remi-7.4
dnf install php php-cli php-mysql php-common php-gd php-mbstring php-mcrypt php-devel php-xml php-bcmath php-ldap -y
php -v

vi /etc/php.ini
max_execution_time = 300
max_input_time = 300
post_max_size = 16M
date.timezone =Asia/Shanghai
systemctl start httpd
systemctl enable httpd.service

三、web目录复制
mkdir -p /var/www/html/zabbix/
mkdir -p /usr/local/zabbix
chown -R zabbix.zabbix   /usr/local/zabbix
cp -r -a /tmp/zabbix-5.4.0/ui/* /var/www/html/zabbix/
chown -R apache.apache   /var/www/html/zabbix/


./configure --prefix=/usr/local/zabbix --enable-server --enable-agent --with-mysql  --with-net-snmp --with-libcurl --with-libxml2
make&&make install

修改配置文件:
vi /usr/local/zabbix/etc/zabbix_server.conf
LogFile=/usr/local/zabbix/zabbix_server.log
PidFile=/usr/local/zabbix/zabbix_server.pid
DBHost=localhost
DBName=zabbix
DBUser=zabbix
DBPassword=password
DBPort=3306
Timeout=30
AlertScriptsPath=/usr/local/zabbix/alertscripts
ExternalScripts=/usr/local/zabbix/externalscripts

cd /usr/local/zabbix/sbin  启动服务

修正字体乱码的问题:  /var/www/html/zabbix/assets/fonts
yum install -y traceroute
yum install -y  fping


修改 /etc/zabbix 配置文件:
# 启动子进程数量,数量越多,则服务端吞吐能力越强,对系统资源消耗越大
StartPollers=120
#不可达主机的轮询进程的初始实例启动数量         
StartPollersUnreachable=50
#用于设置诸如SNMP STRAPPER场景提交来的数据的接收进程数,若客户机SNMP TRAPPER技术较多,建议加大此参数值
StartPingers=50
StartTrappers=10
#pre-forked discoverers的数量
StartDiscoverers=30
StartHTTPPollers=10
StartAlerters=5
StartTimers=2
StartEscalators=2
#配置缓存,用于存储host,item,trigger数据,,目前最大支持8G
CacheSize=256M
StartDBSyncers=10
#历史记录缓存大小,用于存储历史记录
HistoryCacheSize=128M
TrendCacheSize=64M
#文本类型历史记录的缓存大小,存储character, text 、log历史记录.
HistoryIndexCacheSize=64M
ValueCacheSize=512M

增加开机自启动:
vi  /etc/rc.d/rc.local
chmod a+x   /etc/rc.d/rc.local
增加:sh /usr/local/zabbix/zbx.sh
 vi /usr/local/zabbix/zbx.sh
   #!/bin/bash
   /usr/local/zabbix/sbin/zabbix_server
   sleep 5
   /usr/local/zabbix/sbin/zabbix_agentd


centos8安装tools的命令:
yum install open-vm-tools

 类似资料: