目錄
?
rsync同步操作
rsync基本使用
rsync+ssh同步:遠程同步
實時同步
inotify實時同步
inotifywait監控
cobbler裝機平臺
cobbler簡介
基本概念:
裝機步驟
cobbler裝機部署
cobbler應用
自定義應答文件:開頭注釋行刪除
DNS服務器的主從結構
備份主服務器的數據,解決單點故障
rsync同步操作
rsync基本使用
命令用法:rsync ?[選項] ? ?源目錄 ? ?目標目錄 同步與復制的差異:
? ? ? ? ? ? ? ? ? ? ? ? ? ? ?復制:完全拷貝源到目標
? ? ? ? ? ? ? ? ? ? ? ? ? ? ?同步:增量拷貝,只傳輸變化過程(第一次傳輸的時候會自動記住源目錄和目標目錄的校驗值,以后每次只傳輸變化的值)
? ? ? ? ? ? ? -a:歸檔模式,相當于-rlptgoD
? ? ? ? ? ? ? -n:測試同步過程,不做實際修改
? ? ? ? ? ? ? -v:顯示詳細操作信息
? ? ? ? ? ? ? -z:傳輸過程中啟用壓縮/解壓縮
? ? ? ? ? ? --delete:刪除目標文件夾內多余的文檔
? ? ? ? ? ? ??
執行rsync命令時,源目錄后面如果不加/,則默認把目錄本身以及目錄下面的內容一同傳輸到目標目錄
rsync命令只是單方向,目標數據自己多出來的數據
[root@svr7 ~]# mkdir /nsd01 /todir[root@svr7 ~]# cp /etc/passwd /etc/shadow /nsd01[root@svr7 ~]# ls /nsd01
passwd shadow[root@svr7 ~]# rsync -av /nsd01 /todir
sending incremental file list
nsd01/
nsd01/passwd
nsd01/shadow[root@svr7 ~]# rsync -av /nsd01/ /todir
sending incremental file list
./
passwd
shadow[root@svr7 ~]# rsync --delete -av --delete /nsd01/ /todir
sending incremental file list
deleting nsd01/shadow
deleting nsd01/passwd
deleting nsd01/
./[root@svr7 ~]# ls /todir
passwd shadow[root@svr7 ~]# touch /nsd01/1.txt[root@svr7 ~]# rsync --delete -av --delete /nsd01/ /todir
sending incremental file list
deleting nsd01/shadow
deleting nsd01/passwd
deleting nsd01/
./
1.txt[root@svr7 ~]# ls /todir
1.txt passwd shadow
rsync+ssh同步:遠程同步
rsync ? user@host ? ?:遠程 ? 目錄/
下行(下載):rsync ? [....] ? ?user@host:遠程目錄 ? 本地目錄
上行(上傳):rsync ?[....] ? ?本地目錄 ? ?user@host:遠程目錄
[root@svr7 ~]# rsync ? -av ?--delete ?/todir/ ? root@192.168.4.207:/opt[root@pc207 ~]# ls /opt
1.txt passwd shadow[root@svr7 ~]# touch /todir/3.txt[root@svr7 ~]# rsync -av --delete /todir/ root@192.168.4.207:/opt[root@pc207 ~]# ls /opt
1.txt 3.txt passwd shadow[root@svr7 ~]# touch /todir/4.txt[root@svr7 ~]# rsync -av --delete /todir/ root@192.168.4.207:/opt[root@pc207 ~]# ls /opt
1.txt 3.txt 4.txt passwd shadow
實時同步
虛擬機A:生成公鑰與私鑰,取消密碼驗證 [root@svr7 ~]# ssh-keygen #一路回車
Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa):
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /root/.ssh/id_rsa.
Your public key has been saved in /root/.ssh/id_rsa.pub.
The key fingerprint is:
SHA256:w7qmLC4X9KOR0jsTYe9bmNfHey23UPOPdJ2OnlTZxKw root@svr7.tedu.cn
The key's randomart image is:
+---[RSA 2048]----+
| |
| o |
| +|
| + . oo|
| + = S Eo.|
|. * +o o o ..oo|
| . Bo.+ . o .o..+|
|. B..o.. . .+o*o.|
| +.+++. ...*oo.|
+----[SHA256]-----+[root@svr7 ~]# ls /root/.ssh
authorized_keys id_rsa(私鑰) id_rsa.pub(公鑰) known_hosts(記錄曾經遠程管理過的機器)
?
將公鑰傳遞給對方 [root@svr7 ~]# ssh-copy-id root@192.168.4.207[root@pc207 ~]# ls /root/.ssh
authorized_keys (別的機器傳遞過來的公鑰)[root@svr7 ~]# rsync -av --delete /todir/ root@192.168.4.207:/opt
?
inotify實時同步
安裝inotity-tools工具軟件,監控目錄內容
[student@room9pc01 ~]$ ls /linux-soft/
01 02 03 04 05
[student@room9pc01 ~]$ ls /linux-soft/01
Cobbler.zip tools.tar.gz
[student@room9pc01 ~]$ scp /linux-soft/01/tools.tar.gz root@192.168.4.7:/tmp
tools.tar.gz 100% 766KB 2.3MB/s 00:00
[root@svr7 ~]# ls /tmp #查看tmp目錄下是否有該壓縮包(虛擬機)
systemd-private-8baf54c5b1c04ba3a5f3525818b9c081-chronyd.service-Jon8iZ tools.tar.gz
systemd-private-b4e3a5aa0fe14eb493d2b5bed82bbce7-chronyd.service-1X4Kli
[root@svr7 ~]# tar -xf /tmp/tools.tar.gz -C / #將源碼包釋放到根[root@svr7 ~]# ls /
bin dev home lib64 mnt opt root sbin sys todir tpdir var
boot etc lib media nsd01 proc run srv tmp tools usr[root@svr7 ~]# ls /tools
inotify-tools-3.13.tar.gz other
[root@svr7 ~]# tar -xf /tools/inotify-tools-3.13.tar.gz -C /usr/local/[root@svr7 ~]# ls /usr/local/
bin etc games include inotify-tools-3.13 lib lib64 libexec sbin share src
1)下載gcc和make軟件
[root@svr7 ~]# yum ?-y ?install gcc make
2)./configure配置,指定安裝目錄/功能模塊等選項
[root@svr7 ~]# cd /usr/local/inotify-tools-3.13/[root@svr7 inotify-tools-3.13]# ./configure
3)make編譯,生成可執行的二進制文件
[root@svr7 inotify-tools-3.13]# make
4)make install 安裝,將編譯好的文件復制到安裝目錄
[root@svr7 inotify-tools-3.13]# make install[root@svr7 inotify-tools-3.13]# ls /usr/local/bin/inotifywait
/usr/local/bin/inotifywait #查看是否有該程序
inotifywait監控
inotifywait ?[選項] ? ? ?目標文件夾
-m:持續監控(捕獲一個事件后不退出)
-r:遞歸監控,包括子目錄及文件
-q:減少屏幕輸出的信息
-e:指定監視的modify.move.create.delete.attrib等事件類別
三.書寫一個shell腳本
循環解決重復性的操作
for ? 循環:適合書寫有次數的循環
while 循環:適合書寫不限次數的循環
[root@svr7 ~]# vim /root/rsync.sh
#!/bin/bash
while inotifywait -rqq /todir/
do
rsync -a --delete /todir/ root@192.168.4.207:/opt
done
[root@svr7 ~]# chmod +x /root/rsync.sh[root@svr7 ~]# /root/rsync.sh &
[1] 6113[root@svr7 ~]# jobs -l
[1]+ 6113 運行中 /root/rsync.sh &
cobbler裝機平臺
前提:建立一個支持圖形化的虛擬機
1.操作系統為:CentOs7.5
2.內存大小為:2G
3.磁盤空間為:50G
4.虛擬網絡類型為:private1
5.軟件包選擇"帶GUI的服務器"
6.分區選擇"自動分區"
7.管理員root密碼為1
8.創建普通用戶lisi,密碼為1
cobbler簡介
基本概念:
cobbler是一款快速的網絡系統部署工具 集中管理所需服務,如DHCP.DNS.TFTP.WEB cobbler內部集成了一個鏡像版文件倉庫 cobbler內部集成了一個ks應答文件倉庫 cobbler還提供了包括yum源管理,web界面管理,API接口,電源管理等功能
裝機步驟
一.具備一個CentOs虛擬機 二.虛擬機設置防火墻為trusted,selinux設置為寬松模式,IP地址為192.168.4.123/24,主機名為cobbler.tedu.cn,構建yum源:
[root@cobbler ~]# cd /etc/yum.repos.d/[root@cobbler yum.repos.d]# mkdir repo[root@cobbler yum.repos.d]# mv *.repo repo[root@cobbler yum.repos.d]# ls
repo[root@cobbler yum.repos.d]# vim zz.repo
[aaa]
name=sss
baseurl=ftp://192.168.4.254/centos-1804
enabled=1
gpgcheck=0[root@cobbler yum.repos.d]# yum repolist
三.利用scp真機傳遞cobbler.zip包到虛擬機192.168.4.123中
[student@room9pc01 ~]$ scp /home/student/桌面/cobbler.zip root@192.168.4.123:/root
cobbler概述軟件,管理dhcp.TFTP.web服務
自由的導入鏡像與ks應答文件
解壓cobbler.zip軟件包 [root@cobbler ~]# yum -y install unzip [root@cobbler ~]# unzip /root/cobbler.zip -d /[root@cobbler ~]# ls /cobbler
cobbler_boot.tar.gz cobbler_rpm.zip cobbler_web.png[root@cobbler ~]# unzip /cobbler/cobbler_rpm.zip -d /opt[root@cobbler ~]# ls /opt/cobbler/
cobbler-2.8.2-1.el7.x86_64.rpm python-cheetah-2.4.4-5.el7.centos.x86_64.rpm
cobbler-web-2.8.2-1.el7.noarch.rpm python-django-bash-completion-1.6.11.6-16.el7.noarch.rpm
dhclient-4.2.5-58.el7.centos.1.x86_64.rpm python-markdown-2.4.1-2.el7.noarch.rpm
libyaml-0.1.4-11.el7_0.x86_64.rpm python-pillow-2.0.0-19.gitd1c6db8.el7.x86_64.rpm
mod_wsgi-3.4-12.el7_0.x86_64.rpm python-pygments-1.4-10.el7.noarch.rpm
python2-django-1.6.11.6-16.el7.noarch.rpm PyYAML-3.10-11.el7.x86_64.rpm
python2-simplejson-3.10.0-1.el7.x86_64.rpm tftp-server-5.2-13.el7.x86_64.rpm
?
[root@cobbler ~]# yum -y install dhcp httpd mod_ssl[root@cobbler ~]# yum -y install /opt/cobbler/*.rpm[root@cobbler ~]# rpm -q cobbler
cobbler-2.8.2-1.el7.x86_64
cobbler裝機部署
1.安裝軟件cobbler ? cobbler-web ?dhcp ?tftp-server ? pykickstart ?httpd
cobbler ? ? ? ? ? ? ? ? ? ? ? ? ? #cobbler程序包
cobbler-web ? ? ? ? ? ? ? ? ? ?#cobbler的web程序包
pykickstart ? ? ? ? ? ? ? ? ? ? ?#cobbler檢查kickstart應答文件語法錯誤
httpd ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?#dhcp服務
tftp-server ? ? ? ? ? ? ? ? ? ? ? #tftp服務
[root@cobbler ~]# vim /etc/cobbler/settings
272 next_server: 192.168.4.123 #設置下一個服務器還為本機
384 server: 192.168.4.123 #設置本機為cobbler服務器
242 manage_dhcp: 1 #設置cobbler管理dhcp服務
292 pxe_just_once: 1 #防止客戶端重復安裝操作系統#冒號后面要有空格!!!!!!!!
開機啟動選項:匹配即停止
硬盤啟動 光驅設備 U盤 網絡引導
[root@cobbler ~]# vim /etc/cobbler/dhcp.template :%s /舊/新/g #全文替換:%s /192.168.1/192.168.4/g
4.絕對路徑解壓cobbler_boot.tar.gz ? ?#眾多的引導文件
[root@cobbler ~]# tar -tf /cobbler/cobbler_boot.tar.gz #查看包里面的內容[root@cobbler ~]# tar -xPf /cobbler/cobbler_boot.tar.gz #絕對路徑釋放(選項+P,無需指定釋放路徑)[root@cobbler ~]# ls /var/lib/cobbler/loaders/
COPYING.elilo COPYING.yaboot grub-x86_64.efi menu.c32 README
COPYING.syslinux elilo-ia64.efi grub-x86.efi pxelinux.0 yaboot
[root@cobbler ~]# systemctl restart cobblerd
[root@cobbler ~]# systemctl enable cobblerd[root@cobbler ~]# systemctl restart httpd
[root@cobbler ~]# systemctl enable httpd[root@cobbler ~]# systemctl restart rsyncd
[root@cobbler ~]# systemctl enable rsyncd
[root@cobbler ~]# cobbler sync #檢查所有配置是否正確*** TASK COMPLETE *** #出現此行則證明正確
[root@cobbler ~]# firefox https://192.168.4.123/cobbler_web用戶名:cobbler密碼:cobbler
cobbler應用
cobbler import ?--path=掛載點 ? --name=導入系統命名(隨意起)
[root@cobbler ~]# mkdir /dvd[root@cobbler ~]# mount /dev/cdrom /dvd #一定要提前加光驅設備[root@cobbler ~]# ls /dvd
CentOS_BuildTag EULA images LiveOS repodata RPM-GPG-KEY-CentOS-Testing-7
EFI GPL isolinux Packages RPM-GPG-KEY-CentOS-7 TRANS.TBL[root@cobbler ~]# cobbler import --path=/dvd --name=Centos7#cobbler導入的鏡像在/var/www/cobbler/ks_mirror[root@cobbler ~]# cobbler list #查看有哪些系統
distros:Centos7-x86_64 #安裝客戶端至少要2G內存profiles:Centos7-x86_64
[root@cobbler ~]# cobbler profile remove --name=centos7-x86_64 #刪除菜單信息
[root@cobbler ~]# cobbler distro remove --name=centos7-x86_64 #刪除鏡像信息
[root@cobbler ~]# umount /dvd
[root@cobbler ~]# mount /dev/cdrom /dvd
mount: /dev/sr0 寫保護,將以只讀方式掛載
[root@cobbler ~]# ls /dvd
CentOS_BuildTag EULA images LiveOS repodata RPM-GPG-KEY-CentOS-Testing-7
EFI GPL isolinux Packages RPM-GPG-KEY-CentOS-7 TRANS.TBL
自定義應答文件:開頭注釋行刪除
[root@cobbler ~]# yum -y install system-config-kickstart[root@cobbler ~]# system-config-kickstart #進入圖形化界面,生成ks文件
必須默認kickstart文件存放的位置:/var/lib/cobbler/kickstarts
[root@cobbler ~]# cobbler list
修改kickstart文件:
[root@cobbler ~]# cobbler profile edit --name=Centos7 --kickstart=/var/lib/cobbler/kickstarts/自定義.cfg[root@cobbler ~]# cobbler profile report[root@cobbler ~]# cobbler sync #同步設置
?
DNS服務器的主從結構
備份主服務器的數據,解決單點故障
準備三臺虛擬機:1.虛擬機A:主DNS服務器 ? ?192.168.4.7
? ? ? ? ? ? ? ? ? ? ? ? ? ?2.虛擬機B:從DNS服務器 ? 192.168.4.207
? ? ? ? ? ? ? ? ? ? ? ? ? ?3.虛擬機C:客戶端測試 ? ? ? 192.168.4.10
主DNS服務器
[root@svr7 ~]# yum -y install bind bind-chroot
[root@svr7 ~]# cp /etc/named.conf /etc/named.bak[root@svr7 ~]# vim /etc/named.conf
options {directory "/var/named";
};
zone "tedu.cn" IN {type master;file "tedu.cn.zone";
};
[root@svr7 ~]# cd /var/named[root@svr7 named]# cp -p named.localhost tedu.cn.zone[root@svr7 named]# vim tedu.cn.zone$TTL 1D
@ IN SOA @ rname.invalid. (0 ; serial1D ; refresh1H ; retry1W ; expire3H ) ; minimum
tedu.cn. NS svr7
svr7 A 192.168.4.7
www A 1.2.3.4
[root@svr7 named]# systemctl restart named
options {directory "/var/named";allow-transfer { 192.168.4.207; }; #指定從服務器IP地址
};
zone "tedu.cn" IN {type master;file "tedu.cn.zone";
};
[root@svr7 named]# vim tedu.cn.zone$TTL 1D
@ IN SOA @ rname.invalid. (0 ; serial1D ; refresh1H ; retry1W ; expire3H ) ; minimum
tedu.cn. NS svr7
tedu.cn. NS pc207
svr7 A 192.168.4.7
pc207 A 192.168.4.207
www A 1.2.3.4
[root@svr7 named]# systemctl restart named
從DNS服務器
[root@pc207 ~]# yum -y install bind bind-chroot
[root@pc207 ~]# vim /etc/named.conf options {directory "/var/named";
};zone "tedu.cn" IN {type slave;file "/var/named/slaves/tedu.cn.slave"; #原則named用戶對該目錄具備寫入權限masters { 192.168.4.7; }; #指定主DNS服務器名字
};
[root@pc207 ~]# systemctl restart named[root@pc207 ~]# ls /var/named/slaves
tedu.cn.slave
客戶端測試
[root@C ~]# echo nameserver 192.168.4.7 > /etc/resolv.conf [root@C ~]# echo nameserver 192.168.4.207 >> /etc/resolv.conf #先寫主DNS再寫從DNS
2.解析,當主DNS服務器停止時,會自動找到從DNS服務器解析
[root@C ~]# nslookup www.tedu.cn
Server: 192.168.4.7
Address: 192.168.4.7#53Name: www.tedu.cn
Address: 1.2.3.4[root@svr7 named]# systemctl stop named[root@C ~]# nslookup www.tedu.cn
Server: 192.168.4.207
Address: 192.168.4.207#53Name: www.tedu.cn
Address: 1.2.3.4
主從DNS服務器同步數據
地址庫文件內容:
?( ? ? ? ?? ? ? ?0 ? ? ? ?; serial ? ? ? ? ? ?#數據版本號由10個數字組成 ? ? ? ? ? ?? ?1D ? ? ?; refresh ? ? ? ? #代表每隔一天,主從會進行數據同步 ? ? ? ? ? ?? ?1H ? ? ?; retry ? ? ? ? ? ? #每隔一個小時,重試時間間隔 ? ? ? ? ? ?? ?1W ? ? ;?expire ? ? ? ? ?#失效時間,一個星期 ? ? ? ? ? ??? 3H ) ? ?; minimum ? ? ?#無效記錄的緩存時間,3個小時
[root@svr7 named]# vim tedu.cn.zone
$TTL 1D
@ IN SOA @ rname.invalid. (2019122301 ; serial1D ; refresh1H ; retry1W ; expire3H ) ; minimum
tedu.cn. NS svr7
tedu.cn. NS pc207
svr7 A 192.168.4.7
pc207 A 192.168.4.207
www A 15.20.25.26[root@C ~]# nslookup www.tedu.cn
Server: 192.168.4.7
Address: 192.168.4.7#53Name: www.tedu.cn
Address: 15.20.25.26-------------------------------------------------------------------------------------------------------[root@svr7 named]# vim tedu.cn.zone
$TTL 1D
@ IN SOA @ rname.invalid. (2019122302 ; serial1D ; refresh1H ; retry1W ; expire3H ) ; minimum
tedu.cn. NS svr7
tedu.cn. NS pc207
svr7 A 192.168.4.7
pc207 A 192.168.4.207
www A 45.46.50.25[root@svr7 named]# systemctl restart named[root@C ~]# nslookup www.tedu.cn
Server: 192.168.4.7
Address: 192.168.4.7#53Name: www.tedu.cn
Address: 45.46.50.25
?
?
?
?
?
?
?
?
?
?
?
?
?
?
?
?
?
?
?
?
?
?
總結
以上是生活随笔 為你收集整理的rsync同步操作 inotify实时同步 cobbler装机平台 DNS主从结构 的全部內容,希望文章能夠幫你解決所遇到的問題。
如果覺得生活随笔 網站內容還不錯,歡迎將生活随笔 推薦給好友。