天天看點

Linux日常運維(rsync通過服務連接配接,linux日志,screen)

一、rsync通過服務同步

分為服務端(server1) 和用戶端(server2)

服務端(server1):

[root@litongyao ~]# vim /etc/rsyncd.conf

port=873                                   (指定哪個端口啟動rsync服務,不寫的話預設是873)

log file=/var/log/rsync.log                      (指定日志檔案)

pid file=/var/run/rsyncd.pid                     (指定Pid檔案)    

address=192.168.52.101                          (指定監聽的ip,不寫的話監聽全網)

[test]                                    (指定子產品名字)

path=/tmp/rsync                 (指定資料存放的路徑,沒有的話記得建立)

use chroot=true/false          (安全參數,限定隻能在指定存放的路徑,若硬連接配接在别的檔案下,則會報錯,不會同步)

max connections=4              (指定最大連接配接數,預設是0,既沒有限制)

read only=no                   (是否為隻讀,如果為true,則不能上傳到該子產品指定的路徑下)

list=true                       (當用戶端運作rsync 192.168.52.100::  是否會顯示子產品名)   

uid=root                        (傳輸時預設以哪個使用者的身份傳輸)

gid=root                         (傳輸時預設以哪個使用者組的身份傳輸)

auth users=test                     (指定傳輸時指定使用者名和密碼)

secrets file=/etc/rsyncd.passwd           (指定傳輸時使用者名的密碼檔案位址 格式 使用者:密碼)

當設定了auth users和secrets file後,用戶端連接配接服務端也需要使用者名密碼了,羅想在指令行中帶上密碼,可以在用戶端(server2)上設定一個密碼檔案  rsync -avL [email protected]::test/test1/ /tmp/test8/ --password-file=/etc/pass (/etc/pass内容是一個密碼,隻寫密碼就好,權限要改成600)

hosts allow=192.168.52.0/24    (表示允許那些機器連接配接,可以寫ip.或者ip段)

啟動服務 

[root@litongyao ~]# rsync --daemon

[root@litongyao ~]# ps aux | grep rsync

root      2644  0.0  0.0 114656   520 ?        Ss   14:25   0:00 rsync --daemon

root      2646  0.0  0.0 112680   976 pts/0    R+   14:25   0:00 grep --color=auto rsync

格式:

[root@lnmp ~]# rsync -avP /tmp/1.txt 192.168.52.100::test/litongyao02

如果發現erroy,首先檢查是否能Ping通,

然後 [root@lnmp ~]# telnet 192.168.52.100 873   看看873端口是否通暢。如果不通,應該是防火牆問題。關閉firewalld或者打開873端口。

如果更改端口不為873的話,指令行應該加--prot:

且如果設定auth users和secrets file後,

服務端的指令行

[root@lnmp ~]# rsync -avP /tmp/1.txt [email protected]::test/litongyao02         (test為/etc/rsyncd.passwd裡的使用者)

用戶端的指令行

[root@lnmp ~]# rsync -avL [email protected]::test/1.txt /tmp/litongyao/ --password-file=/etc/pass         (/etc/pass裡放的是test裡的密碼)

二、Linux系統日志  /var/log/messages 

當系統出錯時,會不停的向/var/log/messages寫東西。是以系統自己帶了日志切割功能, logrotate

檢視日志切割配置檔案

[root@litongyao ~]# cat /etc/logrotate.conf 

# see "man logrotate" for details

# rotate log files weekly                    (每周切割一次)

weekly 

# keep 4 weeks worth of backlogs                (保留4周檔案,也就是一個月)

rotate 4

# create new (empty) log files after rotating old ones         (切割完後生成新的檔案)

create

# use date as a suffix of the rotated file                (日志名的格式)

dateext

# uncomment this if you want your log files compressed            (是否要壓縮日志)

#compress

# RPM packages drop log rotation information into this directory

include /etc/logrotate.d

# no packages own wtmp and btmp -- we'll rotate them here       (還會切割/var/log/wtmp日志)

/var/log/wtmp {

    monthly

    create 0664 root utmp

minsize 1M

    rotate 1

}

/var/log/btmp {

    missingok

    create 0600 root utmp

# system-specific logs may be also be configured here.

dmesg指令

[root@lnmp ~]# dmesg         (檢視硬體裝置資訊,都是儲存記憶體,沒有檔案)   

[root@lnmp ~]# cat /var/log/dmesg  (和dmesg沒有任何關系,系統啟動時記錄的資訊)

last 實則打開的是 /var/log/wtmp    不能直接cat            檢視正确的登入曆史

lastb 實則打開的是/var/log/btmp    不能直接cat            檢視登入失敗的使用者曆史

安全日志 /var/log/secure    登入是否驗證成功都會在這個檔案裡記載。當遇到暴力破解時,這個日志裡會寫很多日志

三、screen虛拟螢幕(虛拟終端)

需求:執行一個時間較長的腳本,不能中途中斷

[root@litongyao ~]# yum install screen -y          (安裝screen)

[root@litongyao ~]# screen                     (直接運作screen會進入一個虛拟終端)

ctrl+a  +d                              (退出虛拟終端,回到原始終端,不會終止虛拟終端)

[root@litongyao ~]# screen                     (退出後會出現一個4位數的id.)

[detached from 4025.pts-0.litongyao]

[root@litongyao ~]# screen -r 4025               (用screen -r加id則可以傳回虛拟終端)

[root@litongyao ~]# screen -ls                   (-ls 把目前的虛拟終端全都列出來)

There is a screen on:

4025.pts-0.litongyao (Detached)

1 Socket in /var/run/screen/S-root.

[root@litongyao ~]# screen -S "lty"         (screen -S可以自定義一個虛拟終端的名字)

[detached from 4067.lty]

[root@litongyao ~]# screen -ls

There are screens on:

4067.lty (Detached)

2 Sockets in /var/run/screen/S-root.

本文轉自 小新銳 51CTO部落格,原文連結:http://blog.51cto.com/13407306/2049916,如需轉載請自行聯系原作者

繼續閱讀