rsync經過服務同步、 linux系統日誌 、screen工具

rsync經過服務同步

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

port=873
log file=/var/log/rsync.log
pid file=/var/run/rsyncd.pid
address=192.168.244.128   //本機ip
[test] //模塊名
path=/tmp/rsync  //路徑      
use chroot=true  //true 表明不能同步其餘目錄 false 表明能夠同步其餘目錄
max connection=4
read only=no
list=true
uid=root
gid=root
auth users=test
secrets file=/etc/rsyncd.passwd
hosts allow=192.168.244.129   //指定連通的機器,多個ip用空格分開,也可1/25

 

  • rsync --daemon啓動服務

  • 語法:rsync -av 1.txt 【服務所在機器ip】::【模塊名】/1_dest.txt

報錯,可嘗試查看網絡是否有問題,或者端口是否通linux

telnet 192.168.244.128 873  檢查873端口(如未安裝telnet 先安裝)安全

發現端口有問題,能夠先停掉firewalld,在測試端口是否通,成功~網絡

systemctl stop firewalldssh

退出telnet 打「]」 quit 工具

運行同步命令rsync -av 1.txt 192.168.244.128::test/1_dest.txt (test是模塊名字)測試

[root@glinux-02 ~]# rsync -av 1.txt 192.168.244.128::test
Password: 
@ERROR: auth failed on module test
rsync error: error starting client-server protocol (code 5) at main.c(1516) [sender=3.0.9]

提示輸入密碼,能夠修改配置文件,將以下兩行註釋掉。ui

再次執行同步命令,成功~this

[root@glinux-02 ~]# rsync -av 1.txt 192.168.244.128::test/1_dest.txt
sending incremental file list
1.txt

sent 65 bytes  received 27 bytes  184.00 bytes/sec
total size is 0  speedup is 0.00

更換端口

  1. 更改配置文件 port=8730
  2. killall rsync 殺掉進程
  3. 重啓服務 rsync daemon
  4. rsync -acLP --port 8730 ip::test/ /tmp/test 加上--port

配置文件中list =true 表示能夠列出該服務有多少模塊,false 不能列出spa

用法:rsync --port 873 192.168.198.128::日誌

[root@g_linux02 ~]# rsync --port 873 192.168.198.128::
ben

設置用戶密碼,

auth users=test //用戶名
secrets file=/etc/rsyncd.passwd //密碼文件

編輯密碼文件 vi /etc/rsyncd.passwd------------添加test:123456

更改密碼文件權限爲600

再執行rsync --port 873 test@192.168.198.128::ip 輸入密碼才能同步
若是不想輸入密碼,能夠在客戶端增長一個密碼文件,如:/etc/rsync_passwd.txt  

密碼文件中寫入密碼123456,更改密碼文件權限爲600

運行rsync --port 873 --passwd-file=/etc/rsync_passwd.txt   test@192.168.198.128::ip

 

linux系統日誌

/var/log/messages 系統總日誌

/etc/logrotate.conf日誌切割配置文件,會將日誌切割成4份,

[root@glinux-01 ~]# cat /etc/logrotate.conf
# see "man logrotate" for details
# rotate log files weekly
weekly   每星期切割

# keep 4 weeks worth of backlogs
rotate 4   切割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@glinux-01 ~]# ls /var/log/message*
/var/log/messages           /var/log/messages-20180311  /var/log/messages-20180326
/var/log/messages-20180304  /var/log/messages-20180318

dmesg 查看硬件日誌文件

dmesg -c清空,重啓後會在加載。日誌存在內存中。

/var/log/dmesg系統啓動的日誌

last 正確的登陸歷史-------last 調用的文件是/var/log/wtmp

[root@glinux-01 ~]# last
root     pts/0        192.168.244.1    Thu Mar 29 19:14   still logged in   
root     tty1                          Wed Mar 28 21:43   still logged in   
root     pts/0        192.168.244.1    Wed Mar 28 21:43 - 22:25  (00:42)    
root     pts/0        192.168.244.1    Wed Mar 28 19:53 - 21:43  (01:49)    
root     pts/0        192.168.244.1    Tue Mar 27 19:52 - 22:25  (02:33)    
root     pts/1        192.168.244.1    Mon Mar 26 19:37 - 20:21 (1+00:44)

lastb 登陸失敗的歷史 -------調用的文件是 /var/log/btmp

[root@glinux-01 ~]# lastb

btmp begins Sun Mar 18 19:15:09 2018

安全日誌 /var/log/secure (好比登陸密碼輸錯等信息會寫入這個日誌)

screen工具(虛擬終端)

應用場景:好比我一個腳本要執行一天一晚上,那我爲了防止ssh遠程鏈接出現異常中斷(好比網絡緣由),解決方法1:丟到後臺nohup command & (但這種方法無法實時查看輸出信息)

方法2:使用虛擬終端 

  • screen  (exit退出)
  • ctrl +a  再加d  退出終端,但任務在後臺執行
  • screen -ls  查看虛擬終端列表
  • screen -r id進入指定終端
[root@glinux-01 ~]# screen
[detached from 10491.pts-0.glinux-01]
[root@glinux-01 ~]# screen -ls
There is a screen on:
	10491.pts-0.glinux-01	(Detached)
1 Socket in /var/run/screen/S-root.

[root@glinux-01 ~]# screen -r 10491
  • screen -S "自定義終端名" 
  • screen -r "自定義終端名" 進入終端名
相關文章
相關標籤/搜索