screen,rsync,系統日誌,
阿新 • • 發佈:2018-05-16
screen rsync 系統日誌 rsync 通過服務的方式同步
- 要編輯配置文件/etc/rsyncd.conf
- rsyncd.conf樣例
port=873 log file=/var/log/rsync.log pid file=/var/run/rsyncd.pid address=192.168.21.128 [test] path=/tmp/rsync use chroot=true max connections=4 read only=no list=true uid=root gid=root auth users=test secrets file=/etc/rsyncd.passwd hosts allow=192.168.21.129 1.1.1.1 2.2.2.2 192.168.21.0/24
- rsyncd.conf樣例
- 創建同步目錄,修改權限,並啟動服務
[root@akuilinux01 ~]# vim /etc/rsyncd.conf [root@akuilinux01 ~]# mkdir /tmp/rsync [root@akuilinux01 ~]# chmod 777 /tmp/rsync/ [root@akuilinux01 ~]# rsync --daemon [root@akuilinux01 ~]# ps aux |grep rsync root 3408 1.6 0.0 114696 540 ? Ss 22:02 0:00 rsync --daemon root 3410 0.0 0.0 112676 980 pts/0 S+ 22:02 0:00 grep --color=auto rsync [root@akuilinux01 ~]# netstat -lntp Active Internet connections (only servers) Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 880/sshd tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN 1080/master tcp 0 0 192.168.21.128:873 0.0.0.0:* LISTEN 3408/rsync tcp6 0 0 :::22 :::* LISTEN 880/sshd tcp6 0 0 ::1:25 :::* LISTEN 1080/master
- rsync -avP /tmp/1.txt 192.168.21.128::test/aming02.txt同步文件
- 常見錯誤
- 密碼錯誤的需要先註釋掉
[root@akuilinux02 ~]# rsync -avP /tmp/1.txt 192.168.21.128::test/aming02.txt Password: @ERROR: auth failed on module test rsync error: error starting client-server protocol (code 5) at main.c(1648) [sender=3.1.2] [root@akuilinux01 ~]# vim /etc/rsyncd.conf gid=root #auth users=test #secrets file=/etc/rsyncd.passwd hosts allow=192.168.21.129 1.1.1.1 2.2.2.2 192.168.21.0/24
rsync服務配置文件詳解
- port:指定在哪個端口啟動rsyncd服務,默認是873端口。
- log file:指定日誌文件。
- pid file:指定pid文件,這個文件的作用涉及服務的啟動、停止等進程管理操作。
- address:指定啟動rsyncd服務的IP。假如你的機器有多個IP,就可以指定由其中一個啟動rsyncd服務,如果不指定該參數,默認是在全部IP上啟動。 - []:指定模塊名,裏面內容自定義。
- path:指定數據存放的路徑。
- use chroot true|false:表示在傳輸文件前首先chroot到path參數所指定的目錄下。這樣做的原因是實現額外的安全防護,但缺點是需要以roots權限,並且不能備份指向外部的符號連接所指向的目錄文件。默認情況下chroot值為true,如果你的數據當中有軟連接文件,阿銘建議你設置成false。
- max connections:指定最大的連接數,默認是0,即沒有限制。
- read only ture|false:如果為true,則不能上傳到該模塊指定的路徑下。
- list:表示當用戶查詢該服務器上的可用模塊時,該模塊是否被列出,設定為true則列出,false則隱藏。如果沒有限制ip其他人就可以看到模塊名並上傳木馬
- uid/gid:指定傳輸文件時以哪個用戶/組的身份傳輸。
- auth users:指定傳輸時要使用的用戶名。
- secrets file:指定密碼文件,該參數連同上面的參數如果不指定,則不使用密碼驗證。註意該密碼文件的權限一定要是600。格式:用戶名:密碼
- hosts allow:表示被允許連接該模塊的主機,可以是IP或者網段,如果是多個,中間用空格隔開。
- 當設置了auth users和secrets file後,客戶端連服務端也需要用用戶名密碼了,若想在命令行中帶上密碼,可以設定一個密碼文件
- rsync -avL [email protected]::test/test1/ /tmp/test8/ --password-file=/etc/pass
- 其中/etc/pass內容就是一個密碼,權限要改為600
- hosts allow允許誰來鏈接,可以是多個ip和ip段
修改rsync端口號
- 修改配置文件並重啟服務
[root@akuilinux01 ~]# killall rsync [root@akuilinux01 ~]# ps aux |grep rsync root 3642 0.0 0.0 112676 980 pts/0 S+ 22:53 0:00 grep --color=auto rsync [root@akuilinux01 ~]# rsync --daemon [root@akuilinux01 ~]# !ps ps aux |grep rsync root 3645 0.8 0.0 114696 540 ? Ss 22:54 0:00 rsync --daemon root 3647 0.0 0.0 112676 980 pts/0 S+ 22:54 0:00 grep --color=auto rsync [root@akuilinux01 ~]# !net netstat -lntp Active Internet connections (only servers) Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 880/sshd tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN 1080/master tcp 0 0 192.168.21.128:8730 0.0.0.0:* LISTEN 3645/rsync tcp6 0 0 :::22 :::* LISTEN 880/sshd tcp6 0 0 ::1:25 :::* LISTEN 1080/master
- --port 8730選項指定端口
[root@akuilinux02 ~]# rsync -avP --port 8730 /tmp/1.txt 192.168.21.128::test/aming02.txt sending incremental file list sent 44 bytes received 12 bytes 112.00 bytes/sec total size is 846 speedup is 15.11
系統日誌
- /var/log/messages系統的總日誌,包括網絡,系統服務,內核的日誌
- 系統有個自動切割機制logrotate,他的配置文件為/etc/logratate.conf,每周切割一次,只保留四個
root@akuilinux02 ~]# ls /var/log/messages* /var/log/messages /var/log/messages-20180313 /var/log/messages-20180328 /var/log/messages-20180512
- linux寫文件時找的是文件的inode,所以日誌切割的時候需要重啟下日誌服務
- 參考
- dmesg命令,查看硬件的錯誤日誌,存放在內存中
- 加-c清空日誌
- /var/log/dmesg系統啟動的日誌
- last命令,調用的文件/var/log/wtmp。查看用戶登錄信息的日誌
- lastb命令查看登錄失敗的用戶,調用的是/var/log/btmpwenj
- /var/log/secure安全日誌,記錄登錄驗證成功或失敗都會記錄
screen工具
- 系統有個自動切割機制logrotate,他的配置文件為/etc/logratate.conf,每周切割一次,只保留四個
- 為了不讓一個任務意外中斷
- nohup command &這個沒法看到輸出信息
- screen是一個虛擬終端
- yum install -y screen
- screen直接回車就進入了虛擬終端
- ctral a組合鍵再按d退出虛擬終端,但不是結束
- screen -ls 查看虛擬終端列表
- screen -r id 進入指定的終端
- screen -S aming 自定義名字
- screen -r aming 進入自定義的終端
擴展
- Linux日誌文件總管logrotate
- xargs用法詳解
screen,rsync,系統日誌,