前言:
- 本文為本人整理之筆記及複習用,以避免原網站停止服務
- 本站無營利作用,如有侵權冒犯,請立即告知,會立即下架
- 請支持原出處網站,因此會將參考資料放在頁首
系統規格:
VM name | vCPU | vMemory | vDisk | vOS |
---|---|---|---|---|
Zabbix | 2 cores | 2 GB | 400 GB | CentOS7 |
vDisk | Thin Disk | Virtual Device | Size | Device Name | File system | Mount |
---|---|---|---|---|---|---|
☐Flash | Disk 0 | SCSI .0 | 50 GiB | /dev/sda | ext4 | / |
☐Flash | Disk 1 | SCSI .1 | 50 GiB | /dev/sdb | xfs | /var/log |
☐Flash | Disk 2 | SCSI .2 | 100GiB | /dev/sdc | ext4 | /mariabackup |
☐Flash | Disk 3 | SCSI .3 | 200 GiB | /dev/sdd | xfs | /var/lib/mysql |
Zabbix Server
File | Path |
---|---|
Zabbix Config | /etc/zabbix |
Zabbix log | /var/log/zabbix |
JVM Config | /etc/zabbix/zabbix_java_gateway.conf |
MariaDB Server
File | Path |
---|---|
Mariadb Config | /etc/my.cnf.d/server.cnf |
Mariadb log | /var/log/mariadb |
MariaDB backup | /mariabackup |
Maraidb lib | /var/lib/mysql |
Service | |
---|---|
Zabbix Server | systemctl status zabbix-server |
Zabbix Agent | systemctl status zabbix-agent |
Zabbix Agent version | zabbix_agentd -V |
MariaDB | systemctl status mariadb |
JMX | systemctl status zabbix-java-gateway |
系統配置:
Logrotate
vi /etc/logrotate.d/zabbix-server
/var/log/zabbix/zabbix_server.log { su root root create 0733 root root compress copytruncate daily dateext dateformat -%Y-%m-%d delaycompress missingok notifempty rotate 14 } |
vi /etc/logrotate.d/zabbix-agent
/var/log/zabbix/zabbix_agentd.log { su root root compress copytruncate daily dateext dateformat -%Y-%m-%d delaycompress missingok notifempty rotate 14 create 0664 zabbix zabbix } |
磁碟與檔案系統管理
yum install lvm2 -y
pvcreate /dev/sdb /dev/sdc /dev/sdd
vgcreate VG_log /dev/sdb
vgcreate VG_backup /dev/sdc
vgcreate VG_mysql /dev/sdd
lvcreate -l 100%FREE -n LV_log VG_log
lvcreate -l 100%FREE -n LV_backup VG_backup
lvcreate -l 100%FREE -n LV_mysql VG_mysql
lvdisplay
lvchange -r 0 /dev/VG_log/LV_log
lvchange -r 0 /dev/VG_backup/LV_backup
lvchange -r 0 /dev/VG_mysql/LV_mysql
mkfs -t xfs /dev/VG_log/LV_log
mkfs -t xfs /dev/VG_backup/LV_backup
mkfs -t xfs /dev/VG_mysql/LV_mysql
blkid /dev/VG_log/LV_log >> /etc/fstab
blkid /dev/VG_backup/LV_backup >> /etc/fstab
blkid /dev/VG_mysql/LV_mysql >> /etc/fstab
mkdir -p /var/lib/mysql
mkdir -p /mariabackup
mkdir log
mv /var/log/* log/
mount -a
mv log/* /var/log/
rm -rf log/
Zabbix Server 5.0 安裝:
rpm -Uvh https://repo.zabbix.com/zabbix/5.0/rhel/7/x86_64/zabbix-release-5.0-1.el7.noarch.rpm
yum clean all
yum install zabbix-server-mysql zabbix-agent -y
yum install centos-release-scl -y
vi /etc/yum.repos.d/zabbix.repo
[zabbix-frontend] ... enabled=1 ... |
#啟用 zabbix-frontend 存儲庫
yum install zabbix-web-mysql-scl zabbix-apache-conf-scl -y
yum -y install mariadb-server
systemctl start mariadb;systemctl enable mariadb;systemctl status mariadb
mysql -uroot -p
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> quit;
*'password'
, 務必設置自己記得的資料庫密碼
zcat /usr/share/doc/zabbix-server-mysql*/create.sql.gz | mysql -uzabbix -p zabbix
*導入初始架構和數據,系統將提示您輸入新創建的密碼。
vi /etc/zabbix/zabbix_server.conf
DBPassword=password |
vi /etc/opt/rh/rh-php72/php-fpm.d/zabbix.conf
;php_value[date.timezone] = Europe/Riga php_value[date.timezone] = Etc/GMT+4 |
*依照個別需要設定所需求的時區
systemctl restart zabbix-server zabbix-agent httpd rh-php72-php-fpm
systemctl enable zabbix-server zabbix-agent httpd rh-php72-php-fpm
Firewall
firewall-cmd --zone=public --add-port=80/tcp --permanent
firewall-cmd --zone=public --add-port=10051/tcp --permanent
firewall-cmd --zone=public --add-port=10050/tcp --permanent
firewall-cmd --reload
*進入「 Web UI 」http://localhost/zabbix
Zabbix-Server 參數優化修改
vi zabbix_server.conf
CacheSize=2G #配置緩存大小 ValueCacheSize=2G #歷史值緩存大小 |
systemctl restart zabbix-server
Zabbix MariaDB 備份:
mysql -uroot -p
select user,host,concat('SHOW GRANTS FOR ''',user,'''@''',host,''';') as GRANTS from mysql.user order by 1;
DROP USER ''@'localhost';
DROP USER 'root'@'localhost';
DROP USER ''@'zabbix';
DROP USER 'root'@'zabbix';
DROP USER 'root'@'127.0.0.1';
DROP USER 'root'@'::1';
create user mariabackup@localhost identified by 'password';
GRANT RELOAD, PROCESS, SUPER, LOCK TABLES, REPLICATION CLIENT ON *.* TO 'mariabackup'@'localhost' IDENTIFIED BY PASSWORD '*D0135230C742059196C5B6325B4244C64593787E';
SHOW GRANTS FOR 'mariabackup'@'localhost';
FLUSH PRIVILEGES;
*'password'
, 務必設置自己記得的資料庫密碼
vi maintain_sh/Backup-Zabbix.sh
#!/bin/bash MyUser="mariabackup" OldDay=$(date --date '+3 day ago' +'%F') ## 1. Full Backup FullBak="${MyDest}/FullBackup" sync;sync;sync START_TIME=$(date +"%s") mariabackup --backup \ END_TIME=$(date +"%s") echo "$(date +'%F %T'),TW:${TW_TIME},${MYDB_SIZE},${TASK_TIME},${BAK_SIZE}" >> ${MyCSV} sleep 60 ## 2. Table and Procedure Backup sleep 10 ## 3. MySQL.user backup sleep 10 ## 4. My.cnf backup ## 5. system config backup sync;sync;sync ##tar ##--decompress #mariabackup --prepare \ find ${MyTemp} -print0 | xargs -0 rm -v > /dev/null ## End of script |
chmod a+x Backup-Zabbix.sh
chown -R mysql:mysql /etc/my.cnf.d
mkdir -p /var/log/mysql/binlog
mkdir -p /var/log/mysql/redo
mkdir -p /var/log/mysql/undo
mkdir -p /var/log/mysql/tmpdir
chown -R mysql:mysql /var/log/mysql
chown -R mysql:mysql /var/lib/mysql
vi /etc/yum.repos.d/MariaDB.repo
# MariaDB 10.2 CentOS repository list - created 2016-02-28 13:16 UTC # http://mariadb.org/mariadb/repositories/ [mariadb] name = MariaDB baseurl = http://yum.mariadb.org/10.2/centos7-amd64 gpgkey=https://yum.mariadb.org/RPM-GPG-KEY-MariaDB gpgcheck=1 |
yum -y install MariaDB-backup
systemctl restart zabbix-server;systemctl restart mariadb
vi /root/Script/zabbix-backup.sh
#!/bin/bash deldate="$(date -d '1 days ago' +"%Y-%m-%d")" rm -rf /mariabackup/${deldate}_zabbix.tar |
chmod a+x zabbix-backup.sh
crontab -e
# For details see man 4 crontabs # Example of job definition: |
Other:
vi .bash_profile
# .bash_profile # Get the aliases and functions # User specific environment and startup programs JAVA_HOME=/usr/local/java ## The different colours as variables |
Troubleshooting:
執行備份腳本時,發生錯誤訊息:
mysqldump: Got error: 1142: "SELECT command denied to user 'mariabackup'@'localhost' for table 'acknowledges'" when using LOCK TABLES
mysqldump: Got error: 1142: "SELECT command denied to user 'mariabackup'@'localhost' for table 'acknowledges'" when using LOCK TABLES
ERROR 1142 (42000) at line 2: SELECT command denied to user 'mariabackup'@'localhost' for table 'user'
依照錯誤訊息,其原因是mariabackup 沒有SELECT權限,因此我們需要依序關閉Zabbix Server、MariaDB
然後啟動Mysql安全模式,root使用者登入,來開啟mariabackup的Select權限
mysqld_safe --skip-grant-tables &
mysql -uroot
mysql> use mysql;
mysql> show tables;
mysql> select * from user where user='mariabackup' and host='localhost'\G;
update user set `Select_priv` ='Y' where user='mariabackup' and host='localhost';
FLUSH PRIVILEGES;
-END-
天下風雲出我輩,一入江湖歲月催,
塵事如潮人如水,只嘆江湖幾人回。