rsync,linux系統日誌,screen工具

linux 文件同步工具rsync

安裝rsync:yum install -y rsynclinux

rsync能夠遠程和本地同步數據,可是和cp或者scp不一樣的是,他不會覆蓋之前的數據,而是先判斷已經存在的數據和新的數據的差別,只有數據不一樣時,纔會把不相同的部分覆蓋。安全

把passwd備份到tmp下1.txt: rsync -av /etc/passwd /tmp/1.txt網絡

[root@aminglinux-01 ~]# rsync -av /etc/passwd /tmp/1.txt 
sending incremental file list
passwd

sent 1238 bytes  received 31 bytes  2538.00 bytes/sec
total size is 1164  speedup is 0.92
[root@aminglinux-01 ~]#

遠程同步:rsync -av /etc/passwd 用戶名@IP:路徑ssh

[root@aminglinux-01 ~]# rsync -av /etc/passwd root@192.168.245.128:/tmp/1.txt 
The authenticity of host '192.168.245.128 (192.168.245.128)' can't be established.
ECDSA key fingerprint is 2c:de:ff:09:8f:e8:d7:06:04:a7:7b:22:48:71:cd:86.
Are you sure you want to continue connecting (yes/no)? y
Please type 'yes' or 'no': y
Please type 'yes' or 'no': y
Please type 'yes' or 'no': y
Please type 'yes' or 'no': y
Please type 'yes' or 'no': yes
Warning: Permanently added '192.168.245.128' (ECDSA) to the list of known hosts.
root@192.168.245.128's password: 
Permission denied, please try again.
root@192.168.245.128's password: 
sending incremental file list

sent 31 bytes  received 12 bytes  1.06 bytes/sec
total size is 1164  speedup is 27.07
[root@aminglinux-01 ~]#
  • rsync的命令格式

rsync [OPTION] SRC DEST工具

rsync [OPTION] SRC [USER@]HOST:DESTui

rsync [OPTION] [USER@]HOST:SRC DESTthis

rsync [OPTION] [USER@]HOST::DEST.net

rsync [OPTION] SRC [USER@]HOST::DEST設計

  • rsync經常使用選項

-a : 這是歸檔模式,表示以遞歸方式輸出文件,並保持全部屬性,它等同於-rlptgoD。-a選項後面能夠跟一個--no-OPTION ,表示關閉-rlptgoD 中的某一個,好比-a--no-l等同於-rptgoD。日誌

-r :表示以遞歸模式處理子目錄。它主要是針對目錄來講的,若是單獨傳一個文件不須要加-r選項,可是輸出目錄時必須加。

-v : 表示打印一些信息,好比文件列表,文件數量。

-l : 表示保留軟鏈接。

-L : 表示像對待常規文件同樣處理軟鏈接,若是是SRC 中有軟鏈接文件,則加上該選項後,將會把軟鏈接指向的目標文件複製到DST。

-p : 表示保持文件權限。

-o : 表示保持文件屬主信息。

-g : 表示保持文件屬組信息。

-D : 保持設備文件信息。

-t : 表示保持文件時間信息。

--delete :表示刪除DST當中SRC沒有的文件。

--exclude=PATTERN :表示指定排除不須要傳輸的文件,等號後面跟文件名,能夠是萬用字符模式(如*.txt)。

--progress : 表示在同步的過程當中能夠看到同步的過程狀態,好比統計要同步的文件數量,同步的文件傳速度等。

-u : 表示把DST中比SRC還新的文件排除掉,不會覆蓋。

-z : 加上該選項,將會在傳輸過程當中壓縮。

  • rsync經過ssh方式同步

推文件:rsync -av /etc/passwd 用戶名@IP:路徑

拉文件:rsync -avP 192.168.133.132:/tmp/aming.txt /tmp/123.txt

指定22端口:rsync -avP -e "ssh -p 22" /etc/passwd 192.168.133.132:/tmp/aming.txt

rsync經過服務的方式同步

  • 首先要編輯配置文件/etc/rsyncd.conf

[root@aminglinux-01 ~]# vi /etc/rsyncd.conf 

# /etc/rsyncd: configuration file for rsync daemon mode

# See rsyncd.conf man page for more options.

# configuration example:

# uid = nobody
# gid = nobody
# use chroot = yes
# max connections = 4
# pid file = /var/run/rsyncd.pid
# exclude = lost+found/
# transfer logging = yes
# timeout = 900
# ignore nonreadable = yes
# dont compress   = *.gz *.tgz *.zip *.z *.Z *.rpm *.deb *.bz2

# [ftp]
#        path = /home/ftp
#        comment = ftp export area
port=873
log file=/var/log/rsync.log
pid file=/var/run/rsyncd.pid
address=192.168.245.128
[test]
path=/root/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.245.130
:wq

rsyncd.conf 配置文件詳解

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。

  • 啓動服務 rsync --daemon

[root@aminglinux-01 ~]# rsync --daemon
[root@aminglinux-01 ~]# 
檢測一下:
[root@aminglinux-01 ~]# ps aux |grep rsync
root       2403  0.0  0.0 114644   552 ?        Ss   21:07   0:00 rsync --daemon
root       2434  0.0  0.0 112664   976 pts/0    S+   21:09   0:00 grep --color=auto rsync
[root@aminglinux-01 ~]#
  • 格式: rsync -av test1/ 192.168.245.128::module/dir/

linux系統日誌

/var/log/messages 系統日誌,裏面有各類各樣的日誌,網絡系統內核等等不少

爲了防止日誌無限制的增長,系統有一個服務logrotate 來進行切割

[root@aminglinux-01 ~]# ls /var/log/messages*
/var/log/messages  /var/log/messages-20170829  /var/log/messages-20170904  /var/log/messages-20170911  /var/log/messages-20170917
[root@aminglinux-01 ~]#
能夠看一下 cat /etc/logrotate.conf

[root@aminglinux-01 ~]# cat /etc/logrotate.conf
# see "man logrotate" for details
# rotate log files weekly
weekly  一週分割一次

# keep 4 weeks worth of backlogs
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 {
    monthly
    create 0664 root utmp
	minsize 1M
    rotate 1
}

/var/log/btmp {
    missingok
    monthly
    create 0600 root utmp
    rotate 1
}

# system-specific logs may be also be configured here.
[root@aminglinux-01 ~]#

dmesg 系統硬件的日誌,這個日誌是在內存中的,能夠-c清空。通常有問題會有error等關鍵字

/var/log/dmesg 與上面的dmesg日誌無關聯,記錄系統啓動的日誌

last命令 調用的文件 /var/log/wtmp 用來查看正確登錄的歷史。

lastb命令 查看登錄失敗的歷史。調用的/var/log/btmp

安全日誌 :/var/log/secure

screen工具

爲了避免讓一個任務意外中斷 ,

能夠把任務丟到後臺去:nohup command &

可是後臺不能實時的看到輸出

screen 是一個虛擬終端

安裝yum install -y screen

安裝好後直接敲screen

Ctrl+a 再按d 把screen丟到後臺。

screen -ls 列出screen

screen -r 加上指定的id或者名字就能回去

exit 殺死 screen

screen -S "test_screen" 自定義 screen名字

相關文章
相關標籤/搜索