1、郵箱設置
2、網盤設置
3、同步策略
前言:目前自建網址的需求越來越多,但是一些網站的維護和消息通知機制,一直不太適宜;所以本章基於QQ郵箱和百度網盤實現簡單的郵箱告警和網盤同步,讓我們更好的管理我們的個人網址
<h5 id=1>一、配置自動發送到QQ郵箱:</h5>
設置並取得 smtp.qq.com 的 使用 授權密碼
QQ首頁或者網頁登錄到QQ郵箱
點擊設置
選擇賬戶設置
一值下滑找到POP3樣式的服務,然後開啓服務
短信驗證身份
返回POP3默認密鑰
服務端詳細配置
[root@localhost ~]#
[root@localhost ~]# yum install mailx sendmail -y #安裝對應mail郵件服務
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
* base: mirrors.huaweicloud.com
* extras: mirrors.huaweicloud.com
* updates: mirrors.tuna.tsinghua.edu.cn
Package mailx-12.5-19.el7.x86_64 already installed and latest version
Package sendmail-8.14.7-5.el7.x86_64 already installed and latest version
Nothing to do
[root@localhost ~]#
[root@localhost ~]#
[root@localhost ~]# vi /etc/mail.rc
[root@localhost ~]#
[root@localhost ~]# tail -n 4 /etc/mail.rc 修改配置文件把QQ郵箱信息和放出獲取的POP3密碼鍵入此處
set [email protected] smtp="smtp.qq.com"
set smtp-auth-user="[email protected]" smtp-auth-password="whtobh67sdfsgroobf" #密鑰之間不需要輸入空格
set smtp-auth=login
[root@localhost ~]#
[root@localhost ~]#
[root@localhost ~]# echo 'test'|mail -s 'warning' [email protected]
測試郵件是否正常能收到
<h5 id=2> 二、安裝連接百度網盤插件bypy</h5>
bypy是基於python的程序所有安裝時需要python環境,好在一般centos和Ubuntu都有,需要注意當前系統的python版本,然後下載pip,相當於python程序的yum或apt管理器,然後通過pip安裝bypyyum install python2-pip -y
安裝pip包管理器yum install python3-pip -y
安裝bypy程序pip install bypy
安裝後使用bypy info
生成鏈接碼給bypy程序授權
授權碼效果圖
至此百度網盤同步已初步完成
bypy常用命令
1、上傳本目錄到雲盤(同步並不影響本地數據,只是一次簡單的copy)bypy upload [localpath] [remotepath] [ondup]
2、下載雲盤目錄到本地bypy downdir [remotedir] [localdir]
3、下載雲盤文件到本地bypy downfile <remotefile> [localpath]
4、查看網盤中的目錄文件bypy list [remotepath] [format] [sort] [order]
D表示目錄 <br/>F表示文件
5、比較本地和雲盤bypy compare [remotedir] [localdir]
6、其它命令可以看幫助bypy --help
<h5 id=3>三、自動化告警和同步配置基於base腳本實現</h5>
[root@97 ~]#cat scripts/checkdisk.sh
#!/bin/bash
#
DiskPcent=`df /dev/sda1 --output=source,pcent |awk -F'[ ]*|%' '/^\/dev\/sd/ {print $2}'`
#檢查本地磁盤佔用值是否大於60
if [ $DiskPcent -gt 60 ];then
echo "waring copy file!!"
find /tmp/log >./filelist
TIME=`date +%F_$RANDOM`
tar czPf ${TIME}.tar.gz `cat filelist`
bypy upload 備份到百度網盤
if [ $DiskPcent -gt 70 ];then
echo "waring devsdb is full" 如果磁盤大於70則QQ郵箱告警通知管理員
echo "plase check the data disk"|mail -s 'error' [email protected]
fi
fi
設置定時任務crontab -e
0 1 * * 1 /usr/bin/bash /baidu/backup.sh
每週凌晨一點備份一次