Cacti Database Synchronization Method Cactirrdtoolmysql
CACTI database synchronization scripts between different hosts
The software used has
Rsync SCP MySQL
1. Key-Free Login
The first to master the server's key-free login, requiring the primary server to be able to free the key to log on to other node servers
1.1 A public/private key pair is generated under a machine.
ssh-keygen -t rsa -P ‘‘
-P for the password,-p ' means the empty password, you can not use the-p parameter, so that three cars to enter, with-P on a return.
It generates the. SSH directory under/HOME/CHENLB, with Id_rsa and id_rsa.pub under SSH.
1.2 Copy the id_rsa.pub under the A machine to B machine, in the. ssh/authorized_keys file of B machine, I use SCP to copy
scp .ssh/id_rsa.pub [email protected]:/root/id_rsa.pub [email protected]‘s password:id_rsa.pub 100% 223 0.2KB/s 00:00
Because there is no password-free login, so enter the password
The 1.3 b machine adds the id_rsa.pub copied from a to the. ssh/authorzied_keys file
‘‘600 .ssh/authorized_keys
Authorized_keys's permission, if 600,
1.4 A machine login B machine
ssh 192.168 . 1.2 The authenticity of host "192.168.1.2 (192.168.1.2) ' can ' t be established. RSA key fingerprint is 00:a6:a8:87:eb:c7:40:10:39:cc:a0:eb:50:d9:6a:5b. Is you sure want to continue connecting (yes/no)? Yeswarning:permanently added ' 192.168 . 1.2 "(RSA) to the list of known hosts. Last Login:thu Feb 3 09:53:18 from root
The first time you log in is to enter Yes, now a machine can be no password login B machine.
Summary: Log on the machine can have a private key, the machine to be logged on to have the public key of the machine. This public/private key pair is typically generated on the private key host. Above is the RSA algorithm's public/private key pair, of course, you can also use DSA (the corresponding file is id_dsa,id_dsa.pub)
Want to let A, B machine without password mutual login, that machine is configured in the same manner as above can
2. Synchronization Scripts
touch /var/www/sqlbackup.shchmod +x /var/www/sqlbackup.sh
Create the following script to/var/www/sqlbackup.sh and give Execute permissions
Modify the database user name password to notify the Mailbox node server login password and database backup recovery password
#!/bin/bash# Cacti Database Master backup synchronization script# make by Fenei# e-mail: [Email protected]# date:07-feb-2017# url:http://babyfenei.blog.51cto.com/443861/1852324#-----------------------------------------------------# This script automatically backs up the cacti data and sends it to the remote server via SCP and remotely performs database recovery operations# requires master server to be able to key-free login node server# This script will automatically pack the backed up database and save it for 1 monthsUser="Cactiuser"password="Cactiuser"Database="Cacti"Mail="[email protected]"#告警通知邮箱Backup_dir=/var/www/sqlbackup/caname=cacti.sql#备份文件存储路径logfile=/var/Log/data_backup.log#日志文件路径Date= ' Date +%y%m%d-%h%m ' archive=$DATE. sql.tar.gzoptions="-u$USER -P$PASSWORD $DATABASE --ignore-table=cacti.settings"#--ignore-table=cacti.settings is a backup that skips the settings table, prevents individual CA settings settings, and can be changed as required#判断备份文件存储目录是否存在, otherwise create the directoryif[ !- D $BACKUP _dir] ThenMkdir-p"$BACKUP _dir"fi#开始备份之前, writes the backup information header to the journal fileEcho " ">>$LOGFILEEcho "--------------------">>$LOGFILE#切换至备份目录CD $BACKUP _dirMysqldump$OPTIONS>$BACKUP _dir$CANAME#判断数据库备份是否成功if[[ $? ==0]] ThenTar CZVF$ARCHIVE $CANAME>>$LOGFILE 2>&1 Echo "[$ARCHIVE] Backup successful!">>$LOGFILE Else Echo "Database Backup fail!">>$LOGFILE#备份失败后向管理者发送邮件提醒Echo "Backup Alter Mail"|mail- S "Database:$DATABASE Daily Backup Fail" $MAILfiEcho "Backup Process Done"# Backup file is Cacti.sql and remotely backed up to a node server############## #电信CA同步 ###############Scp-p2141 $BACKUP _dir$CANAME[Email protected]192.168.1.2:/tmp/>>$LOGFILE 2>&1if[[ $? ==0]] Then Echo "SCP Process down"SSH-T-P2141[Email protected]192.168.1.2 "Mysql-u$USER -P$PASSWORD $DATABASE </tmp/cacti.sql"SSH-T-P2141[Email protected]192.168.1.2 "Rm-f/tmp/cacti.sql" Echo "Shell Process down!" ElseEcho "Backup Alter Mail"|mail- S "Telecommunications CA Database synchronization Error" $MAIL fi############## #电信CA同步 ###############Rm- F $BACKUP _dir$CANAME#删除31天以上的备份文件#CleaningFind$BACKUP _dir-type F-mtime + to-name"*.tar.gz"-exec RM- F{} \;
3. Create a Crond task plan
echo "58 23 * * * root /var/www/sqlbackup.sh > /dev/null 2>&1" >> /etc/cron.d/backupservice crond restart
4. Check database synchronization Results the next day
Cacti Database Synchronization method