八週三次課
10.32/10.33 rsync經過服務同步
10.34 linux系統日誌
10.35 screen工具linux
10.32/10.33 rsync經過服務同步shell
port=873 //監聽端口默認爲873,也能夠是別的端口 數據庫
log file=/var/log/rsync.log //指定日誌vim
pid file=/var/run/rsyncd.pid //指定pid安全
address=192.168.202.130 #能夠定義綁定的ip服務器
[test] #爲模塊名,自定義網絡
path=/root/rsync // 指定該模塊對應在哪一個目錄下session
use chroot=true //是否限定在該目錄下,默認爲true,當有軟鏈接時,須要改成fasle,若是爲true就限定爲模塊默認目錄架構
max connections=4 //指定最大能夠鏈接的客戶端數less
read only=no //是否爲只讀,若是是no的話,客服端推送給服務端的時候不成功,這時候要改爲yes list=true //是否能夠列出模塊名 rsync --port 8730 172.16.37.139:: 若是爲yes的話會列出客戶端全部的模塊名字。
uid=root //以哪一個用戶的身份來傳輸
gid=root //以哪一個組的身份來傳輸
auth users=test //指定驗證用戶名,能夠不設置,不設置默認不用密碼,設置的話安全性更高點
secrets file=/etc/rsyncd.passwd //指定密碼文件,若是設定驗證用戶,這一項必須設置,設定密碼權限爲400.
hosts allow=192.168.133.132 1.1.1.1 2.2.2.2 192.168.133.0/24 //設置能夠容許訪問的主機,能夠是網段,多個Ip地址用空格隔
1. 首先在虛擬機CentOS7.4上打開/etc/rsyncd.conf文件
[root@tianqi ~]# vi /etc/rsyncd.conf
2.而後將上述代碼複製到 /etc/rsyncd.conf 文件中——>在打開文件的文件時候,會看到全部文件都存在的,但被註釋掉的,咱們能夠另起一行,粘貼進去
port=873 #監聽端口默認爲873,也能夠是別的端口
log file=/var/log/rsync.log
pid file=/var/run/rsyncd.pid
address=192.168.11.136
[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.11.137
3.啓動服務rsync --daemon
[root@tianqi ~]# rsync --daemon
[root@tianqi ~]#
4.在CentOS7.4虛擬機上檢查服務是否已經啓動
[root@tianqi-01 ~]# ps aux | grep rsync
root 2041 0.0 0.0 114652 528 ? Ss 14:11 0:00 rsync --daemon
root 2043 0.0 0.0 112660 984 pts/0 R+ 14:11 0:00 grep --color=auto rsync
[root@tianqi-01 ~]#
5. 在CentOS7.4虛擬機上檢查監聽的端口是否爲873
[root@tianqi-01 ~]# 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 1051/sshd
tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN 1136/master
tcp 0 0 192.168.11.136:873 0.0.0.0:* LISTEN 1253/rsync
tcp6 0 0 :::22 :::* LISTEN 1051/sshd
tcp6 0 0 ::1:25 :::* LISTEN 1136/master
[root@tianqi-01 ~]#
6.在CentOS7.4虛擬機上檢查path指定的路徑
[root@tianqi-01 ~]# vim /etc/rsyncd.conf
//將path=/root/rsync改成path=/tmp/rsync
[root@tianqi-01 ~]# mkdir /tmp/rsync
[root@tianqi-01 ~]#
7. 在CentOS7.4虛擬機上設置權限——>這裏設置的777權限是爲了方便測試
[root@tianqi-01 ~]# chmod 777 !$
chmod 777 /tmp/rsync
[root@tianqi-01 ~]#
8.在另外一臺虛擬機CentOS7.2上,運行
[root@tianqi-02 ~]# rsync -avP /tmp/aming.txt 192.168.11.136::test/aming-02.txt
rsync: failed to connect to 192.168.11.136 (192.168.11.136): No route to host (113)
rsync error: error in socket IO (code 10) at clientserver.c(122) [sender=3.0.9]
[root@tianqi-02 ~]#
9. 在CentOS7.2虛擬機上,會提示沒有路由到遠程機器上去,遇到這種問題,首先在CentOS7.2虛擬機上檢查網絡連通性
[root@tianqi-02 ~]# ping 192.168.11.136
PING 192.168.11.136 (192.168.11.136) 56(84) bytes of data.
64 bytes from 192.168.11.136: icmp_seq=1 ttl=64 time=0.643 ms
64 bytes from 192.168.11.136: icmp_seq=2 ttl=64 time=0.299 ms
^C
--- 192.168.11.136 ping statistics ---
2 packets transmitted, 2 received, 0% packet loss, time 1000ms
rtt min/avg/max/mdev = 0.299/0.471/0.643/0.172 ms
[root@tianqi-02 ~]#
10.這時在CentOS7.2虛擬機上,檢查是否爲端口的問題
[root@tianqi-02 ~]# telnet 192.168.11.136 873
Trying 192.168.11.136...
telnet: connect to address 192.168.11.136: No route to host
[root@tianqi-02 ~]#
11. 這時候會發現873端口是不通的
12. 首先檢查是否爲iptables的問題
[root@tianqi-02 ~]# iptables -nvL
Chain INPUT (policy ACCEPT 0 packets, 0 bytes)
pkts bytes target prot opt in out source destination
5700 16M ACCEPT all -- * * 0.0.0.0/0 0.0.0.0/0 ctstate RELATED,ESTABLISHED
0 0 ACCEPT all -- lo * 0.0.0.0/0 0.0.0.0/0
35 11105 INPUT_direct all -- * * 0.0.0.0/0 0.0.0.0/0
35 11105 INPUT_ZONES_SOURCE all -- * * 0.0.0.0/0 0.0.0.0/0
35 11105 INPUT_ZONES all -- * * 0.0.0.0/0 0.0.0.0/0
0 0 ACCEPT icmp -- * * 0.0.0.0/0 0.0.0.0/0
34 11053 REJECT all -- * * 0.0.0.0/0 0.0.0.0/0 reject-with icmp-host-prohibited
Chain FORWARD (policy ACCEPT 0 packets, 0 bytes)
pkts bytes target prot opt in out source destination
0 0 ACCEPT all -- * * 0.0.0.0/0 0.0.0.0/0 ctstate RELATED,ESTABLISHED
0 0 ACCEPT all -- lo * 0.0.0.0/0 0.0.0.0/0
0 0 FORWARD_direct all -- * * 0.0.0.0/0 0.0.0.0/0
0 0 FORWARD_IN_ZONES_SOURCE all -- * * 0.0.0.0/0 0.0.0.0/0
0 0 FORWARD_IN_ZONES all -- * * 0.0.0.0/0 0.0.0.0/0
0 0 FORWARD_OUT_ZONES_SOURCE all -- * * 0.0.0.0/0 0.0.0.0/0
0 0 FORWARD_OUT_ZONES all -- * * 0.0.0.0/0 0.0.0.0/0
0 0 ACCEPT icmp -- * * 0.0.0.0/0 0.0.0.0/0
0 0 REJECT all -- * * 0.0.0.0/0 0.0.0.0/0 reject-with icmp-host-prohibited
Chain OUTPUT (policy ACCEPT 4560 packets, 432K bytes)
pkts bytes target prot opt in out source destination
4560 432K OUTPUT_direct all -- * * 0.0.0.0/0 0.0.0.0/0
Chain FORWARD_IN_ZONES (1 references)
pkts bytes target prot opt in out source destination
0 0 FWDI_public all -- eno33554984 * 0.0.0.0/0 0.0.0.0/0 [goto]
0 0 FWDI_public all -- eno16777736 * 0.0.0.0/0 0.0.0.0/0 [goto]
0 0 FWDI_public all -- + * 0.0.0.0/0 0.0.0.0/0 [goto]
Chain FORWARD_IN_ZONES_SOURCE (1 references)
pkts bytes target prot opt in out source destination
Chain FORWARD_OUT_ZONES (1 references)
pkts bytes target prot opt in out source destination
0 0 FWDO_public all -- * eno33554984 0.0.0.0/0 0.0.0.0/0 [goto]
0 0 FWDO_public all -- * eno16777736 0.0.0.0/0 0.0.0.0/0 [goto]
0 0 FWDO_public all -- * + 0.0.0.0/0 0.0.0.0/0 [goto]
Chain FORWARD_OUT_ZONES_SOURCE (1 references)
pkts bytes target prot opt in out source destination
Chain FORWARD_direct (1 references)
pkts bytes target prot opt in out source destination
Chain FWDI_public (3 references)
pkts bytes target prot opt in out source destination
0 0 FWDI_public_log all -- * * 0.0.0.0/0 0.0.0.0/0
0 0 FWDI_public_deny all -- * * 0.0.0.0/0 0.0.0.0/0
0 0 FWDI_public_allow all -- * * 0.0.0.0/0 0.0.0.0/0
Chain FWDI_public_allow (1 references)
pkts bytes target prot opt in out source destination
Chain FWDI_public_deny (1 references)
pkts bytes target prot opt in out source destination
Chain FWDI_public_log (1 references)
pkts bytes target prot opt in out source destination
Chain FWDO_public (3 references)
pkts bytes target prot opt in out source destination
0 0 FWDO_public_log all -- * * 0.0.0.0/0 0.0.0.0/0
0 0 FWDO_public_deny all -- * * 0.0.0.0/0 0.0.0.0/0
0 0 FWDO_public_allow all -- * * 0.0.0.0/0 0.0.0.0/0
Chain FWDO_public_allow (1 references)
pkts bytes target prot opt in out source destination
Chain FWDO_public_deny (1 references)
pkts bytes target prot opt in out source destination
Chain FWDO_public_log (1 references)
pkts bytes target prot opt in out source destination
Chain INPUT_ZONES (1 references)
pkts bytes target prot opt in out source destination
33 10824 IN_public all -- eno33554984 * 0.0.0.0/0 0.0.0.0/0 [goto]
2 281 IN_public all -- eno16777736 * 0.0.0.0/0 0.0.0.0/0 [goto]
0 0 IN_public all -- + * 0.0.0.0/0 0.0.0.0/0 [goto]
Chain INPUT_ZONES_SOURCE (1 references)
pkts bytes target prot opt in out source destination
Chain INPUT_direct (1 references)
pkts bytes target prot opt in out source destination
Chain IN_public (3 references)
pkts bytes target prot opt in out source destination
35 11105 IN_public_log all -- * * 0.0.0.0/0 0.0.0.0/0
35 11105 IN_public_deny all -- * * 0.0.0.0/0 0.0.0.0/0
35 11105 IN_public_allow all -- * * 0.0.0.0/0 0.0.0.0/0
Chain IN_public_allow (1 references)
pkts bytes target prot opt in out source destination
1 52 ACCEPT tcp -- * * 0.0.0.0/0 0.0.0.0/0 tcp dpt:22 ctstate NEW
Chain IN_public_deny (1 references)
pkts bytes target prot opt in out source destination
Chain IN_public_log (1 references)
pkts bytes target prot opt in out source destination
Chain OUTPUT_direct (1 references)
pkts bytes target prot opt in out source destination
[root@tianqi-02 ~]#
13. 會看到是iptables的問題,咱們須要停掉firewalld 服務停掉
[root@tianqi-02 ~]# systemctl stop firewalld
[root@tianqi-02 ~]# iptables -nvL
Chain INPUT (policy ACCEPT 0 packets, 0 bytes)
pkts bytes target prot opt in out source destination
Chain FORWARD (policy ACCEPT 0 packets, 0 bytes)
pkts bytes target prot opt in out source destination
Chain OUTPUT (policy ACCEPT 0 packets, 0 bytes)
pkts bytes target prot opt in out source destination
[root@tianqi-02 ~]#
看一下CentOS7.4的iptables,也有問題,須要停掉firewalld。
14.這時會發現端口通了
[root@tianqi-02 ~]# telnet 192.168.11.136 873
Trying 192.168.11.136...
Connected to 192.168.11.136.
Escape character is '^]'.
@RSYNCD: 30.0
^]
telnet> quit
Connection closed.
[root@tianqi-02 ~]#
15. 這時在CentOS7.2虛擬機上,執行rsync -avP /tmp/aming.txt 192.168.11.136::test/aming-02.txt命令,會看到提示要輸出密碼——由於在/etc/rsyncd.conf文件中,有定義密碼
[root@tianqi-02 ~]# rsync -avP /tmp/aming.txt 192.168.11.136::test/aming-02.txt
Password:
@ERROR: auth failed on module test
rsync error: error starting client-server protocol (code 5) at main.c(1516) [sender=3.0.9]
[root@tianqi-02 ~]#
16. 這時能夠在CentOS7.4虛擬機中的/etc/rsyncd.conf文件中,註釋掉輸入密碼
#auth users=test
#secrets file=/etc/rsyncd.passwd
17.這時在CentOS7.2虛擬機上,執行rsync -avP /tmp/aming.txt 192.168.11.136::test/aming-02.txt
[root@tianqi-02 ~]# rsync -avP /tmp/aming.txt 192.168.11.136::test/aming-02.txt
sending incremental file list
aming.txt
834 100% 0.00kB/s 0:00:00 (xfer#1, to-check=0/1)
sent 907 bytes received 27 bytes 1868.00 bytes/sec
total size is 834 speedup is 0.89
[root@tianqi-02 ~]#
18. 在CentOS7.4虛擬機中,檢查文件
[root@tianqi-01 ~]# ls /tmp/rsync/
aming-02.txt
[root@tianqi-01 ~]#
19. 這時就表示實驗成功了
[root@tianqi-02 ~]# rsync -avP 192.168.11.136::test/aming-02.txt /tmp/123.txt
receiving incremental file list
aming-02.txt
834 100% 814.45kB/s 0:00:00 (xfer#1, to-check=0/1)
sent 45 bytes received 941 bytes 1972.00 bytes/sec
total size is 834 speedup is 0.85
[root@tianqi-02 ~]#
• port:指定在哪一個端口啓動rsyncd服務,默認是873端口。
• log file:指定日誌文件。
• pid file:指定pid文件,這個文件的做用涉及服務的啓動、中止等進程管理操做。
• address:指定啓動rsyncd服務的IP。假如你的機器有多個IP,就能夠指定由其中一個啓動rsyncd服務,若是不指定該參數,默認是在所有IP上啓動。
• []:指定模塊名,裏面內容自定義。
• path:指定數據存放的路徑。
• use chroot true|false:表示在傳輸文件前首先chroot到path參數所指定的目錄下。這樣作的緣由是實現額外的安全防禦,但缺點是須要以root權限,而且不能備份指向外部的符號鏈接所指向的目錄文件。默認狀況下chroot值爲true,若是你的數據當中有軟鏈接文件,阿銘建議你設置成false。
•max connections:指定最大的鏈接數,默認是0,即沒有限制。
• read only ture|false:若是爲true,則不能上傳到該模塊指定的路徑下。
• list:表示當用戶查詢該服務器上的可用模塊時,該模塊是否被列出,設定爲true則列出,false則隱藏。
• uid/gid:指定傳輸文件時以哪一個用戶/組的身份傳輸。
• auth users:指定傳輸時要使用的用戶名。
• secrets file:指定密碼文件,該參數連同上面的參數若是不指定,則不使用密碼驗證。注意該密碼文件的權限必定要是600。格式:用戶名:密碼
• hosts allow:表示被容許鏈接該模塊的主機,能夠是IP或者網段,若是是多個,中間用空格隔開。
• 當設置了auth users和secrets file後,客戶端連服務端也須要用用戶名密碼了,若想在命令行中帶上密碼,能夠設定一個密碼文件
• rsync -avL test@192.168.133.130::test/test1/ /tmp/test8/ --password-file=/etc/pass
• 其中/etc/pass內容就是一個密碼,權限要改成600
[root@tianqi-01 ~]# cat /var/log/rsync.log
2018/01/29 14:11:02 [2041] rsyncd version 3.0.9 starting, listening on port 873
2018/01/29 15:54:18 [1253] rsyncd version 3.0.9 starting, listening on port 873
2018/01/29 16:45:09 [1606] name lookup failed for 192.168.11.137: Name or service not known
2018/01/29 16:45:09 [1606] connect from UNKNOWN (192.168.11.137)
2018/01/29 16:45:17 [1606] rsync: connection unexpectedly closed (0 bytes received so far) [Receiver]
2018/01/29 16:45:17 [1606] rsync error: error in rsync protocol data stream (code 12) at io.c(605) [Receiver=3.0.9]
2018/01/29 16:47:46 [1614] name lookup failed for 192.168.11.137: Name or service not known
2018/01/29 16:47:46 [1614] connect from UNKNOWN (192.168.11.137)
2018/01/29 16:47:49 [1614] auth failed on module test from unknown (192.168.11.137): unauthorized user
2018/01/29 16:51:22 [1622] name lookup failed for 192.168.11.137: Name or service not known
2018/01/29 16:51:22 [1622] connect from UNKNOWN (192.168.11.137)
2018/01/29 08:51:22 [1622] rsync to test/aming-02.txt from unknown (192.168.11.137)
2018/01/29 08:51:22 [1622] receiving file list
2018/01/29 08:51:22 [1622] sent 54 bytes received 926 bytes total size 834
2018/01/29 16:55:39 [1644] name lookup failed for 192.168.11.137: Name or service not known
2018/01/29 16:55:39 [1644] connect from UNKNOWN (192.168.11.137)
2018/01/29 08:55:39 [1644] rsync on test/aming-02.txt from unknown (192.168.11.137)
2018/01/29 08:55:39 [1644] building file list
2018/01/29 08:55:39 [1644] sent 956 bytes received 46 bytes total size 834
[root@tianqi-01 ~]#
[root@tianqi-01 ~]# rsync --port=873 192.168.11.136::
test
[root@tianqi-01 ~]#
[root@tianqi-01 ~]# rsync --port=873 192.168.11.136::
[root@tianqi-01 ~]#
rsync傳輸時設置密碼
在/etc/rsyncd.passwd文件中編輯
而後修改權限爲600
rsync -avP /tmp/test/ test@192.168.11.136::test/
在rsync傳輸文件的時候,在寫shell腳本輸入密碼很差,好比天天凌晨半夜更新數據庫文件啥的,那就會很麻煩
10.34 linux系統日誌
[root@tianqi-01 ~]# ls /var/log/messages
/var/log/messages
[root@tianqi-01 ~]# less !$
less /var/log/messages
Jan 29 09:49:57 tianqi-01 dhclient[683]: DHCPREQUEST on ens33 to 192.168.11.254 port 67 (xid=0x3f2161bf)
Jan 29 09:49:57 tianqi-01 dhclient[683]: DHCPACK from 192.168.11.254 (xid=0x3f2161bf)
Jan 29 09:49:57 tianqi-01 NetworkManager[558]: <info> [1517190597.5342] dhcp4 (ens33): address 192.168.11.136
Jan 29 09:49:57 tianqi-01 NetworkManager[558]: <info> [1517190597.5342] dhcp4 (ens33): plen 24 (255.255.255.0)
Jan 29 09:49:57 tianqi-01 NetworkManager[558]: <info> [1517190597.5342] dhcp4 (ens33): gateway 192.168.11.2
Jan 29 09:49:57 tianqi-01 NetworkManager[558]: <info> [1517190597.5342] dhcp4 (ens33): lease time 1800
Jan 29 09:49:57 tianqi-01 NetworkManager[558]: <info> [1517190597.5342] dhcp4 (ens33): nameserver '192.168.11.2'
Jan 29 09:49:57 tianqi-01 NetworkManager[558]: <info> [1517190597.5342] dhcp4 (ens33): domain name 'localdomain'
Jan 29 09:49:57 tianqi-01 NetworkManager[558]: <info> [1517190597.5342] dhcp4 (ens33): state changed bound -> bound
等等,只截取了一部分
[root@tianqi-01 ~]# du -sh !$
du -sh /var/log/messages
504K /var/log/messages
[root@tianqi-01 ~]#
在查看日誌的時候,會發現日誌自動切割了
[root@tianqi-01 ~]# ls /var/log/messages*
/var/log/messages /var/log/messages-20180129
[root@tianqi-01 ~]#
查看日誌文件cat /etc/logrotate.conf
[root@tianqi-01 ~]# cat /etc/logrotate.conf
# see "man logrotate" for details //會告訴你查看logrotate的幫助文檔
# 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 //是否須要壓縮,壓縮成 .tar.gz
# 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@tianqi-01 ~]#
[root@tianqi-01 ~]# ls /etc/logrotate.d
bootlog syslog wpa_supplicant yum
[root@tianqi-01 ~]# cat /etc/logrotate.d/syslog
/var/log/cron
/var/log/maillog
/var/log/messages
/var/log/secure
/var/log/spooler
{
missingok
sharedscripts
postrotate
/bin/kill -HUP `cat /var/run/syslogd.pid 2> /dev/null` 2> /dev/null || true
endscript
}
[root@tianqi-01 ~]#
logrotate就介紹這麼多,用的也很少
[root@tianqi-01 ~]# last
root pts/0 192.168.11.1 Mon Jan 29 21:09 still logged in
reboot system boot 3.10.0-693.el7.x Mon Jan 29 20:59 - 22:15 (01:15)
root pts/1 192.168.11.1 Mon Jan 29 15:47 - 15:47 (00:00)
root pts/0 192.168.11.1 Mon Jan 29 15:47 - crash (05:11)
root tty1 Mon Jan 29 15:47 - crash (05:12)
reboot system boot 3.10.0-693.el7.x Mon Jan 29 15:46 - 22:15 (06:28)
root pts/0 192.168.11.1 Mon Jan 29 08:55 - crash (06:50)
root tty1 Mon Jan 29 08:29 - crash (07:16)
reboot system boot 3.10.0-693.el7.x Mon Jan 29 08:29 - 22:15 (13:45)
root pts/1 192.168.11.1 Sat Jan 27 16:09 - 16:10 (00:00)
root pts/0 192.168.11.1 Sat Jan 27 14:28 - crash (1+18:00)
root tty1 Sat Jan 27 14:20 - crash (1+18:08)
reboot system boot 3.10.0-693.el7.x Sat Jan 27 14:19 - 22:15 (2+07:55)
root pts/0 192.168.11.1 Sat Jan 27 08:00 - crash (06:19)
root tty1 Sat Jan 27 07:53 - crash (06:26)
reboot system boot 3.10.0-693.el7.x Sat Jan 27 07:52 - 22:15 (2+14:22)
root pts/0 192.168.11.1 Fri Jan 26 21:04 - crash (10:47)
root tty1 Fri Jan 26 21:04 - crash (10:48)
reboot system boot 3.10.0-693.el7.x Fri Jan 26 21:02 - 22:15 (3+01:12)
root pts/0 192.168.11.1 Fri Jan 26 15:48 - crash (05:13)
root tty1 Fri Jan 26 15:48 - crash (05:14)
reboot system boot 3.10.0-693.el7.x Fri Jan 26 15:47 - 22:15 (3+06:27)
root pts/1 192.168.11.1 Fri Jan 26 11:37 - crash (04:09)
root pts/1 192.168.11.1 Fri Jan 26 11:36 - 11:37 (00:01)
root pts/0 192.168.11.1 Fri Jan 26 11:36 - crash (04:10)
root pts/1 192.168.11.1 Fri Jan 26 11:36 - 11:36 (00:00)
root pts/0 192.168.11.1 Fri Jan 26 11:30 - 11:36 (00:05)
root tty1 Fri Jan 26 11:29 - 15:43 (04:13)
reboot system boot 3.10.0-693.el7.x Fri Jan 26 11:29 - 22:15 (3+10:45)
root pts/2 192.168.11.1 Fri Jan 26 10:29 - 10:30 (00:00)
root pts/1 192.168.11.1 Fri Jan 26 10:28 - 10:54 (00:25)
root pts/0 192.168.11.1 Fri Jan 26 09:50 - 10:30 (00:39)
root pts/0 192.168.11.1 Fri Jan 26 09:36 - 09:49 (00:13)
root tty1 Fri Jan 26 09:28 - crash (02:00)
reboot system boot 3.10.0-693.el7.x Fri Jan 26 09:27 - 22:15 (3+12:47)
wtmp begins Fri Jan 26 09:27:20 2018
[root@tianqi-01 ~]# ls /var/log/wtmp
/var/log/wtmp
[root@tianqi-01 ~]#
[root@tianqi-01 ~]# lastb
btmp begins Fri Jan 26 11:29:27 2018
[root@tianqi-01 ~]# ls /var/log/btmp
/var/log/btmp
[root@tianqi-01 ~]#
[root@tianqi-01 ~]# ls /var/log/secure
/var/log/secure
[root@tianqi-01 ~]#
10.35 screen工具
screen,虛擬的一個屏幕,也能夠理解爲一個虛擬的終端
需求,執行一個腳本,須要一天一晚上,並且腳本會輸出一些東西出來,這就意味着這個腳本不能中途斷開,保證腳本不中斷,有兩種方法:
安裝screen包——>yum install -y screen
[root@tianqi-01 ~]# screen //在虛擬終端下執行了vmstat 1,同時按 ctrl+a鍵 ,隨後再按d鍵,就把screen丟到後臺了。
[detached from 1674.pts-0.tianqi-01]
[root@tianqi-01 ~]# screen -ls //列出當前全部的session
There is a screen on:
1674.pts-0.tianqi-01 (Detached)
1 Socket in /var/run/screen/S-root.
[root@tianqi-01 ~]# screen -r 1674 //從新回到虛擬終端——>若不須要screen了,直接殺死,按 exit 便可
[root@tianqi-01 ~]# screen -ls //再次查看,會發現沒有screen
No Sockets found in /var/run/screen/S-root.
[root@tianqi-01 ~]# screen
[screen is terminating]
[root@tianqi-01 ~]# screen
[detached from 1864.pts-0.tianqi-01]
[root@tianqi-01 ~]# screen
[detached from 1889.pts-0.tianqi-01]
[root@tianqi-01 ~]# screen -ls
There are screens on:
1889.pts-0.tianqi-01 (Detached)
1864.pts-0.tianqi-01 (Detached)
1674.pts-0.tianqi-01 (Detached)
3 Sockets in /var/run/screen/S-root.
[root@tianqi-01 ~]#
友情連接:阿銘Linux