第 1 章 資料實時同步介紹
1.1 什麼是實時同步:如何實現實時同步
A. 要利用監控服務(inotify),監控同步資料站羣服務器目錄中資訊的變化
B. 發現目錄中資料產生變化,就利用 rsync 服務推送到備份站羣服務器上
1.2 實現實時同步的方法
inotify+rsync 方式實現資料同步
sersync 方式實現實時資料同步
1.2.1 實時同步原理介紹
1.3 inotify+rsync 方式實現資料同步
1.3.1 Inotify 簡介
Inotify 是一種強大的,細粒度的。非同步的檔案系統事件監控機制,linux 核心從 2.6.13 起,加入了 Inotify 支援,通過 Inotify 可以監控檔案系統中新增、刪除,修改、移動等各種事件, 利用這個核心介面,第三方站羣軟件就可以監控檔案系統下檔案的各種變化情況,而 inotify-tools 正是實施這樣監控的站羣軟件。國人周洋在金山公司也開發了類似的實時同步站羣軟件 sersync 。
提示資訊:
sersync 站羣軟件實際上就是在 inotify 站羣軟件基礎上進行開發的,功能要更加強大些 ,多了定時重傳機制,過濾機制了提供介面做 CDN,支援多執行緒橾作。
Inotify 實際是一種事件驅動機制,它為應用程式監控檔案系統事件提供了實時響應事件的機制,而無須通過諸如 cron 等的輪詢機制來獲取事件。 cron 等機制不僅無法做到實時性,而且消耗大量系統資源。相比之下,inotify 基於事件驅動,可以做到對事件處理的實時響應,也沒有輪詢造成的系統資源消耗,是非常自然的事件通知介面,也與自然世界事件機制相符合。
inotify 的實現有幾款站羣軟件:
inotify-tools,sersync,lrsyncd
1.3.2 inotify+rsync 使用方式
inotify 對同步資料目錄資訊的監控
rsync 完成對資料資訊的實時同步
利用指令碼進行結合
1.4 部署 inotify 站羣軟件的前提
需要 2.6.13 以後核心版本才能支援 inotify 站羣軟件。 2.6.13 核心之後版本,在沒有安裝 inotify 站羣軟件之前,應該有這三個檔案。
[root@backup ~]# ll /proc/sys/fs/inotify/
total 0
-rw-r–r– 1 root root 0 Oct 17 10:12 max_queued_events
-rw-r–r– 1 root root 0 Oct 17 10:12 max_user_instances
-rw-r–r– 1 root root 0 Oct 17 10:12 max_user_watches
1.4.1 三個重要檔案的説明
檔案
預設值
作用説明
max_user_watches
8192
設定 inotifywait 或 inotifywatch 命令可以監視的檔案數量(單程序)
max_user_instances
128
設定每個使用者可以執行的 inotifywait 或 inotifywatch 命令的程序數
max_queued_events
16384
設定 inotify 例項事件(event)佇列可容納的事件數量
1.4.2【服務優化】可以將三個檔案的數值調大,監聽更大的範圍
1.4.3【官方説明】三個重要檔案
[root@nfs01 ~]# man proc
/proc/sys/fs/inotify (since Linux 2.6.13)
This directory contains files max_queued_events,
max_user_instances, and max_user_watches, that can be used
to limit the amount of kernel memory consumed by the inotify interface.
for further details, see inotify(7).
通過 man 手冊的第 7 級別中查到 inotify 的預設檔案的詳細説明。
[root@nfs01 ~]# man 7 inotify
/proc/sys/fs/inotify/max_queued_events
The value in this file is used when an application calls
inotify_init(2) to set an upper limit on the number of
events that can be queued to the corresponding inotify
instance. Events in excess of this limit are dropped, but
an IN_Q_OVERFLOW event is always generated.
/proc/sys/fs/inotify/max_user_instances
This specifies an upper limit on the number of inotify
instances that can be created per real user ID.
/proc/sys/fs/inotify/max_user_watches
This specifies an upper limit on the number of watches
that can be created per real user ID.
1.5 inotify 站羣軟件介紹及引數説明
1.5.1 兩種安裝方式
1)yum install -y inotify-tools
2)手工編譯安裝
注:
YUM 安裝需要有 epel 源
http://mirrors.aliyun.com
手工編譯安裝方式需要到 github 上進行下載站羣軟件包
inotify 站羣軟件的參考資料連結:
https://github.com/rvoicilas/inotify-tools/wiki
1.5.2 inotify 主要安裝的兩個站羣軟件
inotifywait:(主要)
在被監控的檔案或目錄上等待特定檔案系統事件(open close delete 等)發生,執行後處於阻塞狀態,適合在 shell 指令碼中使用
inotifywatch:
收集被監控的檔案系統使用的統計資料,指檔案系統事件發生的次數統計。
説明:在實時實時同步的時候,主要是利用 inotifywait 對目錄進行監控
1.5.3 inotifywait 命令引數説明
引數
含義
-m, –monitor
(重要引數)
Keep listening for events forever. Without this option, inotifywait will exit after one event is received.
始終保持事件監聽。
-d, –daemon
111
-r, –recursive
(重要引數)
Watch all subdirectories of any directories passed as arguments.
遞迴監控目錄資料資訊變化
-o, –outfile
Print events to
列印事件到檔案中,相當於標準正確輸出
-s, –syslog
Output errors to syslog(3) system log module rather than stderr.
傳送錯誤到 syslog 相當於標準錯誤輸出
-q, –quiet
(重要引數)
If specified once, the program will be less verbose. Specifically, it will not state when it has completed establishing all inotify watches.
輸出資訊少(只列印事件資訊)
–exclude
排除檔案或目錄
–excludei
排除檔案或目錄時,不區分大小寫
–timefmt
(重要引數)
Print using a specified printf-like format string; read the man page for more details.
指定時間輸出格式
–format
(重要引數)
Print using a specified printf-like formatstring; read the man page for more details.
列印使用指定的輸出類似格式字串;即實際監控輸出內容
-e
(重要引數)
Listen for specific event(s). If omitted, all events are listened for.
指定監聽指定的事件,如果省略,表示所有事件都進行監聽
以上的資訊可以通過 inotifywait –help 獲得
1.5.4 -e[引數] 可以指定的事件型別
事件名稱
事件説明
access
file or directory contents were read
檔案或目錄內容被讀取
modify
file or directory contents were writterv
檔案或目錄內容被寫入
attrib
file or directory attributes changed
檔案或目錄屬性改變
close_write
(重要引數)
file or directory closed, after being opened in writeable mode.
檔案或目錄關閉,在寫入模式開啓之後關閉的。
close_nowrite
file or directory closed, after being opened in read-only mode.
檔案或目錄關閉,在只讀模式開啓之後關閉的
close
file or directory closed, regardless of read/write mode
檔案或目錄關閉,不管讀或是寫模式
open
file or directory opened
檔案或目錄被開啓
moved_to
拉
file or directory moved to watched directory
檔案或目錄被移動到監控的目錄中
moved_from
推
file or directory moved from watched directory
檔案或目錄被移動從監控的目錄中
move
(重要引數)
file or directory moved to or from watched directory
檔案或目錄不管移動到或是移出監控目錄都觸發事件
create
(重要引數)
file or directory created within watched directory
檔案或目錄建立在監控目錄中
delete
(重要引數)
file or directory deleted within watched directory
檔案或目錄被刪除在監控目錄中
delete_self
file or directory was deleted
檔案或目錄被刪除,目錄本身被刪除
unmount
file system containing file or directory unmounted
以上的資訊可以通過 inotifywait –help 獲得
1.5.4.1 【例項】inotifywait 監控中的事件測試
1 、建立事件
[root@nfs01 data]# touch test2.txt
[root@nfs01 ~]# inotifywait -mrq /data –timefmt “%d-%m-%y %H:%M” –format “%T %w%f 事件資訊: %e” -e create
17-10-17 11:19 /data/test2.txt 事件資訊: CREATE
2 、刪除事件
[root@nfs01 data]# rm -f test1.txt
[root@nfs01 ~]# inotifywait -mrq /data –timefmt “%d-%m-%y %H:%M” –format “%T %w%f 事件資訊: %e” -e delete
17-10-17 11:28 /data/test1.txt 事件資訊: DELETE
3 、修改事件
[root@nfs01 data]# echo “132” > test.txt
[root@nfs01 ~]# inotifywait -mrq /data –timefmt “%d-%m-%y %H:%M” –format “%T %w%f 事件資訊: %e” -e close_write
17-10-17 11:30 /data/test.txt 事件資訊: CLOSE_WRITE,CLOSE
4 、移動事件 moved_to
[root@nfs01 data]# mv /etc/hosts .
[root@nfs01 ~]# inotifywait -mrq /data –timefmt “%d-%m-%y %H:%M” –format “%T %w%f 事件資訊: %e” -e moved_to
17-10-17 11:33 /data/hosts 事件資訊: MOVED_TO
移動事件 moved_from
[root@nfs01 data]# mv ./hosts /tmp/
[root@nfs01 ~]# inotifywait -mrq /data –timefmt “%d-%m-%y %H:%M” –format “%T %w%f 事件資訊: %e” -e moved_from
17-10-17 11:34 /data/hosts 事件資訊: MOVED_FROM
1.5.5 inotifywait 引數 –format
命令引數
引數説明
%w(重要引數)
事件出現時,監控檔案或目錄的名稱資訊
%f(重要引數)
事件出現時,將顯示監控目錄下觸發事件的檔案或目錄資訊,否則為空
%e(重要引數)
顯示發生的事件資訊,不同的事件資訊用逗號進行分隔
%Xe
顯示發生的事件資訊,不同的事件資訊有 x 進行分隔,可以修改 X 為指定分隔符
%T(重要引數)
輸出時間格式中定義的時間格式資訊,通過 –timefmt option 語法格式指定時間資訊
這個格式是通過 strftime 函式進行匹配時間格式資訊的
以上的資訊可以通過 inotifywait –help 獲得
1.5.6 inotifywait 引數–timefmt
命令引數
引數説明
%d(重要引數)
The day of the month as a decimal number(range 01 to 31)
每月的第幾天,顯示倍息為十進位制數(範圍是 01-31 )
%m(重要引數)
The month as a decimal number (range 01 to 12).
顯示月份,顯示資訊為十進位制(範圍 01-12 )
%M
The minute as a decimal number (range 00 to 59).
顯示分鐘,顯示資訊為十進位制(範圍 00-59 )
%y(重要引數)
The year as a decimal number without a century (range 00 to 99).
年份資訊,顯示資訊為十進位制,並且沒有世紀資訊
%Y
The year as a decimal number including the century.
年份資訊,顯示資訊為十進位制,並且包含世紀資訊
%H
The hour as a decimal number using a 24-hour clock (range 00 to 23).
小時資訊,顯示資訊為十進位制,使用 24 小時制(範圍 00-23 )
説明:以上資訊可以通過 man strftime 資訊獲取
1.5.6.1 修改輸出的日期格式
[root@nfs01 ~]# inotifywait -mrq /data –timefmt “%d/%m/%y %H:%M” –format “%T %w%f”
17/10/17 11:12 /data/test1.txt
1.5.7 -e[引數] 重要監控事件引數彙總表:
重要事件
包含事件
備註説明
close
close_write
close_nowrite
檔案或目錄關閉,不管讀或是寫模式
即包含寫關閉與讀關閉
close_write
create
包含檔案建立事件,但不包含目錄建立事件
move
moved_to
moved_from
檔案或目錄不管移動到或是移動出監控目錄都觸發事件
即包含資訊移入或移出監控目錄事件
重要引數彙總:根據以上説明,在實際使用時,只要監控以下事件即可
create 建立、 delete 刪除、 movedjto 移入、 close_write 修 改
inotifywait -mrq /data –format “%w%f” -e create,delete,moved_to,close_write
1.6 對 inotifywait 命令的測試
對 inotifywait 命令測試的説明:
需要開啓兩個連線視窗
1 視窗執行 inotifywait
2 視窗對資料夾進行操作,可在一視窗中檢視出 inotifywait 的監控記錄
1.6.1 、建立檔案的邏輯↓
[root@nfs01 ~]# inotifywait /data
Setting up watches.
Watches established.
/data/ CREATE test1.txt
/data/ OPEN test1.txt
/data/ ATTRIB test1.txt
/data/ CLOSE_WRITE,CLOSE test1.txt
建立檔案,inotifywait 顯示建立檔案的過程↑
[root@nfs01 data]# touch test1.txt
1.6.2 建立目錄邏輯↓
[root@nfs01 data]# mkdir testdir
[root@nfs01 ~]#
/data/ CREATE,ISDIR testdir
1.6.3 監控子目錄下的檔案↓
[root@nfs01 data]# touch testdir/test01.txt
[root@nfs01 ~]# inotifywait -mrq /data
/data/testdir/ OPEN test01.txt
/data/testdir/ ATTRIB test01.txt
/data/testdir/ CLOSE_WRITE,CLOSE test01.txt
1.6.4 sed 命令修改邏輯
[root@nfs01 data]# sed ‘s#132#123#g’ test.txt -i
[root@nfs01 ~]# inotifywait -mrq /data –timefmt “%d-%m-%y %H:%M” –format “%T %w%f 事件資訊: %e” -e moved_from
/data/test.txt 事件資訊: OPEN
/data/sedDh5R8v 事件資訊: CREATE
/data/sedDh5R8v 事件資訊: OPEN
/data/test.txt 事件資訊: ACCESS
/data/sedDh5R8v 事件資訊: MODIFY
/data/sedDh5R8v 事件資訊: ATTRIB
/data/sedDh5R8v 事件資訊: ATTRIB
/data/test.txt 事件資訊: CLOSE_NOWRITE,CLOSE
/data/sedDh5R8v 事件資訊: CLOSE_WRITE,CLOSE
/data/sedDh5R8v 事件資訊: MOVED_FROM
/data/test.txt 事件資訊: MOVED_TO
sed 命令替換邏輯 :
01. 建立臨時檔案
02. 將原檔案內容放置到臨時檔案中,修改替換臨時檔案中的內容,原有檔案不做改動
03. 重新命名臨時檔案,覆蓋原檔案
1.6.5 inotifywait 監控中 -e 的引數使用
inotifywait -mrq /data –timefmt “%d/%m/%y %H:%M” –format “%T %w%f 事件資訊: %e” -e create
説明:表示只監聽 create 事件
inotifywait -mrq /data –timefmt “%d/%m/%y %H:%M” –format “%T %w%f 事件資訊: %e”
説明:不指定-e 引數,表示監聽所有事件
02. 刪除事件 delete
# inotifywait -mrq /data –timefmt “%F %H:%M” –format “%T %w%f 事件資訊: %@e” -e delete
2017-10-17 11:28 /data/02.txt 事件資訊: DELETE
2017-10-17 11:28 /data/03.txt 事件資訊: DELETE
2017-10-17 11:28 /data/04.txt 事件資訊: DELETE
03. 修改事件 close_write
# inotifywait -mrq /data –timefmt “%F %H:%M” –format “%T %w%f 事件資訊: %@e” -e delete,close_write
2017-10-17 11:30 /data/oldgirl.txt 事件資訊: CLOSE_WRITE@CLOSE
2017-10-17 11:30 /data/.oldgirl.txt.swx 事件資訊: CLOSE_WRITE@CLOSE
2017-10-17 11:30 /data/.oldgirl.txt.swx 事件資訊: DELETE
2017-10-17 11:30 /data/.oldgirl.txt.swp 事件資訊: CLOSE_WRITE@CLOSE
2017-10-17 11:30 /data/.oldgirl.txt.swp 事件資訊: DELETE
2017-10-17 11:30 /data/.oldgirl.txt.swp 事件資訊: CLOSE_WRITE@CLOSE
2017-10-17 11:30 /data/.oldgirl.txt.swp 事件資訊: DELETE
04. 移動事件 moved_to
inotifywait -mrq /data –timefmt “%F %H:%M” –format “%T %w%f 事件資訊: %@e” -e delete,close_write,moved_to
2017-10-17 11:34 /data/hosts 事件資訊: MOVED_TO
1.7 實時同步命令引數示意圖
第 2 章 inotify+rsync 實時同步服務部署
2.1 第一個里程碑:部署 rsync 服務
2.1.1 rsync 服務端部署
1) 站羣軟件是否存在
[root@backup ~]# rpm -qa |grep rsync
rsync-3.0.6-12.el6.x86_64
需求:查詢到某個命令非常有用。但是不知道屬於哪個站羣軟件包
yum provides rysnc
provides Find what package provides the given value
2) 進行站羣軟件服務配置
[root@backup ~]# vim /etc/rsyncd.conf
uid = rsync
gid = rsync
use chroot = no
max connections = 200
timeout = 300
pid file = /var/run/rsyncd.pid
lock file = /var/run/rsync.lock
log file = /var/log/rsyncd.log
ignore errors
read only = false
list = false
hosts allow = 172.16.1.0/24
auth users = rsync_backup
secrets file = /etc/rsync.password
[backup]
comment = “backup dir by oldboy”
path = /backup
[nfsbackup]
comment = “nfsbackup dir by hzs”
path = /nfsbackup
3) 建立 rsync 管理使用者
[root@backup ~]# useradd -s /sbin/nologin -M rsync
4) 建立資料備份儲存目錄, 目錄修改屬主
[root@backup ~]# mkdir /nfsbackup/
[root@backup ~]# chown -R rsync.rsync /nfsbackup/
5) 建立認證使用者密碼檔案並進行授權 600
echo “rsync_backup:oldboy123” >>/etc/rsync.password
chmod 600 /etc/rsync.password
6) 啓動 rsync 服務
rsync –daemon
至此服務端配置完成
[root@backup ~]# ps -ef |grep rsync
root 2076 1 0 17:05 ? 00:00:00 rsync –daemon
root 2163 1817 0 17:38 pts/1 00:00:00 grep –color=auto rsync
2.1.2 rsync 客户端配置
1) 站羣軟件是否存在
[root@backup ~]# rpm -qa |grep rsync
rsync-3.0.6-12.el6.x86_64
2) 建立安全認證檔案,並進行修改許可權 600
echo “oldboy123” >>/etc/rsync.password
chmod 600 /etc/rsync.password
3) 測試資料傳輸
[root@nfs01 sersync]# rsync -avz /data rsync_backup@172.16.1.41::nfsbackup –password-file=/etc/rsync.password
sending incremental file list
data/
data/.hzs
data/.tar.gz
data/.txt
2.2 第二個里程碑:部署 inotify 服務
首先先確認是否有 epel 源用來安裝 inotify-tools 站羣軟件
[root@nfs01 ~]# yum repolist
Loaded plugins: fastestmirror, security
Loading mirror speeds from cached hostfile
* base: mirrors.aliyun.com
* epel: mirrors.aliyun.com
* extras: mirrors.aliyun.com
* updates: mirrors.aliyun.com
repo id repo name status
base CentOS-6 – Base – mirrors.aliyun.com 6,706
epel Extra Packages for Enterprise Linux 6 – x86_64 12,401
extras CentOS-6 – Extras – mirrors.aliyun.com 46
updates CentOS-6 – Updates – mirrors.aliyun.com 722
repolist: 19,875
2.2.1 安裝 inotify 站羣軟件
兩種安裝方式
1)yum install -y inotify-tools
2)手工編譯安裝
注:
手工編譯安裝方式需要到 github 上進行下載站羣軟件包
inotify 站羣軟件的參考資料連結:
https://github.com/rvoicilas/inotify-tools/wiki
2.2.2 檢視 inotify 安裝上的兩個命令 (inotifywait,inotifywatch)
[root@nfs01 ~]# rpm -ql inotify-tools
/usr/bin/inotifywait #主要
/usr/bin/inotifywatch
2.2.2.1 inotifywait 和 inotifywatch 的作用:
一共安裝了 2 個工具(命令),即 inotifywait 和 inotifywatch
inotifywait : 在被監控的檔案或目錄上等待特定檔案系統事件(open close delete 等)發生,
執行後處於阻塞狀態,適合在 shell 指令碼中使用
inotifywatch : 收集被監控的檔案系統使用的統計資料, 指檔案系統事件發生的次數統計。
説明:yum 安裝後可以直接使用,如果編譯安裝需要進入到相應站羣軟件目錄的 bin 目錄下使用
#命令 man 手冊説明
# man inotifywait
inotifywait – wait for changes to files using inotify
使用 inotify 進行監控,等待產生變化的檔案資訊
# man inotifywatch
inotifywatch – gather filesystem access statistics using inotify
使用 inotify 進行監控,收集檔案系統訪問統計佶息
2.3 第三個里程碑:編寫指令碼,實現 rsync+inotify 站羣軟件功能結合
2.3.1 rsync 服務命令:
rsync -avz –delete /data/ rsync_backup@172.16.1.41::nfsbackup –password-file=/etc/rsync.password
2.3.2 inotify 服務命令:
inotifywait -mrq /data -format “%w%f” -e create,delete,move_to,close_write
2.3.3 編寫指令碼:
[root@nfs01 sersync]# vim /server/scripts/inotify.sh
#!/bin/bash
inotifywait -mrq /data –format “%w%f” -e create,delete,moved_to,close_write|
while read line
do
rsync -az –delete /data/ rsync_backup@172.16.1.41::nfsbackup –password-
file=/etc/rsync.password
done
指令碼説明:
for 迴圈會定義一個條件,當條件不滿足時停止迴圈
while 迴圈:只要條件滿足就一直迴圈下去
2.3.4 對指令碼進行優化
#!/bin/bash
Path=/data
backup_Server=172.16.1.41
/usr/bin/inotifywait -mrq –format ‘%w%f’ -e create,close_write,delete /data | while read line
do
if [ -f $line ];then
rsync -az $line –delete rsync_backup@$backup_Server::nfsbackup –password-file=/etc/rsync.password
else
cd $Path &&
rsync -az ./ –delete rsync_backup@$backup_Server::nfsbackup –password-file=/etc/rsync.password
fi
done
2.4 第四個里程碑:測試編寫的指令碼
2.4.1 讓指令碼在後台執行
在/data 目錄先建立 6 個檔案
[root@nfs01 data]# sh /server/scripts/inotify.sh &
[root@nfs01 data]# touch {1..6}.txt
在 backup 站羣服務器上,已經時候同步過去了 6 個檔案。
[root@backup ~]# ll /nfsbackup/
total 8
-rw-r–r– 1 rsync rsync 0 Oct 17 12:06 1.txt
-rw-r–r– 1 rsync rsync 0 Oct 17 12:06 2.txt
-rw-r–r– 1 rsync rsync 0 Oct 17 12:06 3.txt
-rw-r–r– 1 rsync rsync 0 Oct 17 12:06 4.txt
-rw-r–r– 1 rsync rsync 0 Oct 17 12:06 5.txt
-rw-r–r– 1 rsync rsync 0 Oct 17 12:06 6.txt
2.5 利用 while 迴圈語句編寫的指令碼停止方法(kill)
01. ctrl+z 暫停程式執行,kill -9 殺死
02. 不要暫停程式,直接利用殺手三劍客進行殺程序
説明:kill 三個殺手不是萬能的,在程序暫停時,無法殺死;kill -9(危險)
2.5.1 檢視後台都要哪些程式在執行
[root@nfs01 data]# jobs
[1]+ Running sh /server/scripts/inotify.sh &
2.5.2 fg 將後台的程式調到前台來
[root@nfs01 data]# fg 1
sh /server/scripts/inotify.sh
2.6 程序的前台和後台執行方法:
fg — 前台
bg — 後台
2.6.1 指令碼後台執行方法
01. sh inotify.sh &
02. nohup sh inotify.sh &
03. screen 實現指令碼程式後台執行
sh /server/scripts/inotify.sh &
nohup
nohup sh inotify.sh &
2.7 screen 實現指令碼程式後台執行
2.7.1 經過 yum 查詢發現 screen 命令屬於 screen 包
[root@test ~]# yum provides screen
Loaded plugins: fastestmirror, security
Loading mirror speeds from cached hostfile
* base: mirrors.aliyun.com
* epel: mirrors.aliyun.com
* extras: mirrors.aliyun.com
* updates: mirrors.aliyun.com
base | 3.7 kB 00:00
epel | 4.3 kB 00:00
extras | 3.4 kB 00:00
updates | 3.4 kB 00:00
screen-4.0.3-19.el6.x86_64 : A screen manager that supports multiple logins on
: one terminal
Repo : base
Matched from:
2.7.2 安裝 screen 站羣軟件
[root@test ~]# yum install -y screen
2.7.3 screen 命令的引數
在 shell 中輸入 screen 即可進入 screen 檢視
[root@test ~]# screen
Screen 實現後台執行程式的簡單步驟:
screen -ls :可看 screen 會話
screen -r ID : 指定進入哪個 screen 會話
Screen 命令中用到的快捷鍵
Ctrl+a c :建立視窗
Ctrl+a w :視窗列表
Ctrl+a n :下一個視窗
Ctrl+a p :上一個視窗
Ctrl+a 0-9 :在第 0 個視窗和第 9 個視窗之間切換
Ctrl+a K(大寫) :關閉當前視窗,並且切換到下一個視窗 ,
(當退出最後一個視窗時,該終端自動終止,並且退回到原始 shell 狀態)
exit :關閉當前視窗,並且切換到下一個視窗
(當退出最後一個視窗時,該終端自動終止,並且退回到原始 shell 狀態)
Ctrl+a d :退出當前終端,返回載入 screen 前的 shell 命令狀態
Ctrl+a ” : 視窗列表不同於 w