天天看點

10.32-10.33 rsync服務同步;10.34 Linux系統日志10.35screen工具

擴充:

1. Linux日志檔案總管logrotate:  

<a href="http://linux.cn/article-4126-1.html">http://linux.cn/article-4126-1.html</a>

2. xargs用法詳解:

<a href="http://blog.csdn.net/zhangfn2011/article/details/6776925">http://blog.csdn.net/zhangfn2011/article/details/6776925</a>

10.32 rsync通過服務同步(上)

• rsync 通過服務的方式同步:

在 A機器上操作:

1. 建立 rsync目錄 :

[root@hao-001 ~]# mkdir /tmp/rsync

2. 設定 rsync目錄權限 為777 :

[root@hao-001 ~]# chmod 777 /tmp/rsync

3. 建立 rsync配置檔案 :

[root@hao-001 ~]# vim /etc/rsyncd.conf

最下面另起行——插入:

port=873

log file=/var/log/rsync.log

pid file=/var/run/rsyncd.pid

address=192.168.223.128

[hao1]

path=/tmp/rsync

use chroot=true

max connections=4

read only=no

list=true

uid=root

gid=root

#auth users=haolinux

#secrets file=/etc/rsyncd.passwd

hosts allow=192.168.223.129

注解:

port=873  定義的是端口

address=192.168.223.128   定義的是A機器的ip

[hao1]   子產品名字,指向的是/tmp/rsync目錄

path=/tmp/rsync  定義的是傳輸檔案儲存目錄(hao1子產品指向的路徑)

#auth users=haolinux  定義使用者名,這裡暫時注釋掉了

#secrets file=/etc/rsyncd.passwd  定義密碼檔案的路徑(需要建立密碼檔案)

hosts allow=192.168.223.129   定義的是B機器的ip

rsyncd.conf配置檔案詳解:

• port:自定義(指定)端口,啟動rsyncd服務(預設是873端口)

• log file:自定義(指定)日志檔案(自定義絕對路徑)

• pid file:自定義(指定)pid檔案,這個檔案的作用涉及服務的啟動、停止等程序管理操作。

• address:自定義(指定)啟動rsyncd服務的IP

(假如你的機器有多個IP,就可以指定由其中一個啟動rsyncd服務,如果不指定該參數,預設是在全部IP上啟動)

• []:自定義子產品名([hao1])。

• path:指定資料存放的路徑。

• use chroot true/false:use chroot true如果同步軟連結,則會被攔截;use chroot false 如果同步軟連結,不會被攔截!!

表示在傳輸檔案前首先chroot到path參數所指定的目錄下。這樣做的原因是實作額外的安全防護,但缺點是需要以roots權限,并且不能備份指向外部的符号連接配接所指向的目錄檔案。(預設情況下chroot值為true,如果你的資料當中有軟連接配接檔案,阿銘建議你設定成false。)

• max connections:指定最大同時連接配接數,(預設是0,即沒有限制)

• read only ture:如果為true,則不能上傳到該子產品指定的路徑下(read only false可以上傳)

• list:表示當使用者查詢該伺服器上的可用子產品時,該子產品是否被列出,設定: true列出,false隐藏。

• uid/gid:指定傳輸檔案時,以哪個使用者或組的身份傳輸。

• auth users:指定傳輸時要使用的使用者名。

• secrets file:指定密碼檔案,該參數連同上面的參數如果不指定,則不使用密碼驗證。

(注意該密碼檔案的權限一定要是600。格式:使用者名:密碼)

設定auth users和secrets file後,用戶端連服務端也需要使用者名密碼了(若想在指令行中帶上密碼,可以設定一個密碼檔案)

• hosts allow:表示被允許連接配接該子產品的主機,可以是IP或者ip網段(如果是多個IP,中間用空格隔開)

4. 啟動 rsync服務 :

[root@hao-001 ~]# rsync --daemon

5. 搜素 rsync服務,是否啟動?

[root@hao-001 ~]# ps aux |grep rsync

在 B機器上操作:

6. 檢查是否ping通hao1網卡ip :

[root@hao-02 ~]# ping 192.168.223.128

7. 安裝 telnet指令:

[root@hao-02 ~]# yum install -y telnet

8. 檢查 A機器 ip端口 是否 ping通?

[root@hao-02 ~]# telnet 192.168.223.128 873

9. 如果不通,A機器,和B機器,把firewalld服務關掉 :

[root@hao-02 ~]# systemctl stop firewalld

[root@hao-001 ~]# systemctl stop firewalld

10. 推送 本地檔案到遠端 :

(把hao2的檔案,推送到遠端hao1子產品對應的目錄下:把B機器上的檔案,傳送給遠端A機器—儲存在子產品對應的目錄(/tmp/rsync)下)

rsync -avP 本地推送檔案   遠端ip::子產品名/重命名檔案

[root@hao-02 ~]# rsync -avP /tmp/1.txt   192.168.223.128::hao1/222.txt

11. 拉 遠端檔案到本地 :

(把hao1子產品對應目錄下檔案,拉到本地hao2的指定目錄下,并重命名)

rsync -avP 遠端ip::子產品名/遠端拉的原檔案  本地存放目錄/重命名檔案

[root@hao-02 ~]# rsync -avP 192.168.223.128::hao1/222.txt  /tmp/123.txt

12. A機器上,檢視rsync記錄檔 :

[root@hao-001 ~]# cat /var/log/rsync.log

10.33 rsync通過服務同步(下)

1. 更改 rsync配置檔案 :

(把預設端口号873更改為8730)

更改内容:port=8730

2. 重新開機 killall服務 :

關閉rsync服務:

[root@hao-001 ~]# killall rsync

開啟rsync服務:

[root@hao-001 ~]# rsync --daemon

3. 在B機器上,同步A機器檔案,需要指定端口号了:

rsync -avP 本地推送檔案 --port hao1端口号 遠端ip::子產品名/重命名檔案

[root@hao-02 ~]# rsync -avP /tmp/1.txt --port 8730 192.168.223.128::hao1/333.txt

4. 檢視 可用子產品 :

( list:表示當使用者查詢該伺服器上的可用子產品時,該子產品是否被列出,設定: true列出,false隐藏。列出list=true  或隐藏list=false )

[root@hao-02 ~]# rsync --port=8730 192.168.223.128::

5. 修改 rsyncd.conf配置檔案 :

編輯:消除設定密碼的兩行行首 #(注釋符号)

auth users=自定義使用者名  

secrets file=自定義密碼檔案路徑  

6. 建立 密碼檔案 :

[root@hao-001 ~]# /etc/rsyncd.passwd

添加格式: 自定義使用者名:自定義密碼

7. 設定 密碼檔案權限為600 :

[root@hao-001 ~]# chmod 600 /etc/rsyncd.passwd

8. 用戶端B機器上操作,推送本地檔案到遠端下:

rsync -avP 本地推送檔案 --port=端口号 密碼對應的使用者名@遠端ip::子產品名/重命名檔案

[root@hao-02 ~]# rsync -avP /tmp/1.txt --port=8730 [email protected]::hao1/444.txt

9. 用戶端B機器上操作,建立 密碼檔案 :

[root@hao-02 ~]# vi /etc/rsync_pass.txt

添加内容:A機器rsync_pass.txt密碼檔案設定的密碼!

10. 設定 密碼檔案權限為600 :

[root@hao-02 ~]# chmod 600 /etc/rsync_pass.txt

11. B機器本地檔案推送到遠端A機器子產品對應的目錄下,并重命名檔案 :

密碼驗證,免輸入密碼,就可以同步檔案到遠端

rsync -avP 本地推送檔案 --port=端口号 --password-file=用戶端密碼檔案路徑 密碼對應的使用者名@遠端ip::子產品名/重命名檔案

[root@hao-02 ~]# rsync -avP /tmp/1.txt --port=8730 --password-file=/etc/rsync_pass.txt [email protected]::hao1/555.txt

10.34 Linux系統日志

logrotate工具 使用參考 :

<a href="https://my.oschina.net/u/2000675/blog/908189">https://my.oschina.net/u/2000675/blog/908189</a>

1. 列出 linux系統日志檔案 :

(一周切割一次,保留四個日志檔案帶日期)

[root@hao-01 ~]# ls /var/log/messages*

2. 檢視 系統日志切割配置檔案内容 :

[root@hao-01 ~]# cat /etc/logrotate.conf

3. 記憶體中系統日志 :

[root@hao-01 ~]# dmesg

4. 清除 記憶體中系統日志 :

[root@hao-01 ~]# dmesg -c

5. 列出 記錄系統啟動的日志 :

[root@hao-01 ~]# ls /var/log/dmesg

6. 檢視 正确的使用者登陸曆史日志 :

•last指令調用的檔案/var/log/wtmp(用last指令來檢視的)

[root@hao-01 ~]# last

7. 檢視 失敗的使用者登陸曆史日志 :

•lastb指令調用的檔案/var/log/btmp(用lastb指令來檢視的)

[root@hao-01 ~]# lastb

8. 檢視 安全日志 :

[root@hao-01 ~]# less /var/log/secure

10.35 screen工具

•screen是一個虛拟終端

1. 安裝 screen :

[root@hao-01 ~]# yum install -y screen

2. 進入 虛拟終端:

[root@hao-01 ~]# screen

3. 退出 screen虛拟終端,但不結束:

鍵盤快捷鍵: ctral a組合鍵   再按d

4. 檢視 虛拟終端清單:

[root@hao-01 ~]# screen -ls

10.32-10.33 rsync服務同步;10.34 Linux系統日志10.35screen工具

5. 進入 指定的終端 :screen -r 終端id号

[root@hao-01 ~]# screen -r 2693

6. 退出(殺死) 運作的終端 :

[root@hao-01 ~]# exit

7. 自定義 screen :screen -S "自定義screen"

[root@hao-01 ~]# screen -S "hao_screen"

8. 進入 自定義的screen:

[root@hao-01 ~]# screen -r hao_screen

9. 檢視 虛拟終端清單:

10.32-10.33 rsync服務同步;10.34 Linux系統日志10.35screen工具

本文轉自 主内安詳 51CTO部落格,原文連結:http://blog.51cto.com/zhuneianxiang/2067487,如需轉載請自行聯系原作者

繼續閱讀