通過后臺服務的方式

在遠程主機上建立一個rsync的服務器,在服務器上配置好rsync的各種應用,然后將本機作為rsync的一個客戶端連接遠程的rsync服務器。

在128主機上建立并配置rsync的配置文件/etc/rsyncd.conf,把你的rsyncd.conf編輯成以下內容:

[root@aminglinux-123?~]#?vim?/etc/rsyncd.conf
#?/etc/rsyncd:?configuration?file?for?rsync?daemon?mode
port=873
log?file=/var/log/rsync.log
pid?file=/var/run/rsyncd.pid
address=192.168.193.128
#?See?rsyncd.conf?man?page?for?more?options.#?configuration?example:
[test]
path=/root/rsync
read?only=no
list=true
uid?=?root
gid?=?root
use?chroot=true
max?connections=4
auth?users=test
secrets?file=/etc/rsyncd.passwd
hosts?allow=192.168.193.128

rscond.com中的port,logfile,pid file,address都屬于全局配置;[test]以下的部分就是模塊配置。man rsyncd.conf可以獲得更多信息。

port:指定在哪個端口啟動rsyncd服務,默認是873端口。

log file:指定日志文件。

pid file:指定pid文件,這個文件的作用涉及服務的啟動、停止等進程管理操作。

address:指定啟動rsyncd服務的IP。

[]:指定模塊名。

path:指定數據存放的路徑。

use chroot true|false:表示在傳輸文件之前,首先chroot到path參數所指定的目錄下。

max connections:指定最大的連接數,默認是0,即沒有限制。

read only ture|false:如果為true,則不能上傳到該模塊指定的路徑下。

list:表示當用戶查詢該服務器上的可用模塊時,該模塊是否被列出,設定為true則列出,設定為false則隱藏。

uid/gid:指定傳輸文件時以哪個用戶/組的身份傳輸。

auth users:指定傳輸時要使用的用戶名。

secrets file:指定密碼文件。

hosts allow:表示被允許連接該模塊的主機。

編輯secrets file并保存后要賦予600權限。

[root@aminglinux-123?etc]#?cat?/etc/rsyncd.passwd
[root@aminglinux-123?etc]#?vim?/etc/rsyncd.passwd
[root@aminglinux-123?etc]#?cat?/etc/rsyncd.passwd
test:test123
[root@aminglinux-123?etc]#?chmod?600?/etc/reyncd.passwd
chmod:?無法訪問"/etc/reyncd.passwd":?沒有那個文件或目錄
[root@aminglinux-123?etc]#?chmod?600?/etc/rsyncd.passwd

linux系統日志

/var/log/messages

體統啟動時的引導信息,系統運行時的其他狀態都會存放在這個文件里。

通過logrotate工具來實現的,它的配置文件是/etc/logrotate.conf。

[root@aminglinux-123?~]#?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?{monthlycreate?0664?root?utmpminsize?1Mrotate?1
}/var/log/btmp?{missingokmonthlycreate?0600?root?utmprotate?1
}#?system-specific?logs?may?be?also?be?configured?here.

man rsyslog.com 查看更多信息。

dmesg

可以顯示系統的啟動信息

[root@aminglinux-123?~]#?dmesg?|head
[????0.000000]?Initializing?cgroup?subsys?cpuset
[????0.000000]?Initializing?cgroup?subsys?cpu
[????0.000000]?Initializing?cgroup?subsys?cpuacct
[????0.000000]?Linux?version?3.10.0-862.el7.x86_64?(builder@kbuilder.dev.centos.org)?(gcc?version?4.8.5?20150623?(Red?Hat?4.8.5-28)?(GCC)?)?#1?SMP?Fri?Apr?20?16:44:24?UTC?2018
[????0.000000]?Command?line:?BOOT_IMAGE=/vmlinuz-3.10.0-862.el7.x86_64?root=UUID=23c138ca-3a70-447e-9028-e002f1d0dea9?ro?crashkernel=auto?rhgb?quiet.UTF-8
[????0.000000]?Disabled?fast?string?operations
[????0.000000]?e820:?BIOS-provided?physical?RAM?map:
[????0.000000]?BIOS-e820:?[mem?0x0000000000000000-0x000000000009ebff]?usable
[????0.000000]?BIOS-e820:?[mem?0x000000000009ec00-0x000000000009ffff]?reserved
[????0.000000]?BIOS-e820:?[mem?0x00000000000dc000-0x00000000000fffff]?reserved

安全日志

[root@aminglinux-123?~]#?last?|head
root?????pts/1????????192.168.193.1????Fri?Jul?20?09:08???still?logged?in
root?????pts/0????????192.168.193.1????Thu?Jul?19?14:32???still?logged?in
root?????pts/0????????192.168.193.1????Thu?Jul?19?08:58?-?14:31??(05:32)
root?????pts/0????????192.168.193.1????Wed?Jul?18?15:46?-?21:24??(05:37)
root?????pts/0????????192.168.193.1????Tue?Jul?17?11:11?-?18:21??(07:09)
root?????pts/1????????192.168.193.1????Mon?Jul?16?18:49?-?20:41??(01:52)
root?????pts/0????????192.168.193.1????Mon?Jul?16?18:44?-?18:49??(00:04)
root?????pts/0????????192.168.193.1????Mon?Jul?16?18:37?-?18:43??(00:06)
root?????pts/1????????192.168.193.1????Mon?Jul?16?18:16?-?18:37??(00:21)
root?????tty1??????????????????????????Mon?Jul?16?18:14???still?logged?in

xargs應用

查找當前目錄創建時間大于10天的文件,然后再刪除。

[root@aminglinux-123?~]#?find?.?mtime?+10?|xargs?rm
[root@aminglinux-123?~]#?mkdir?test
[root@aminglinux-123?~]#?cd?test
[root@aminglinux-123?test]#?touch?1.txt?2.txt?3.txt?4.txt?5.txt
[root@aminglinux-123?test]#?ls
1.txt??2.txt??3.txt??4.txt??5.txt
[root@aminglinux-123?test]#?ls?*.txt?|xargs?-n1?-i{}?mv?{}?{}_bak
[root@aminglinux-123?test]#?ls
1.txt_bak??2.txt_bak??3.txt_bak??4.txt_bak??5.txt_bak

screen工具介紹

使用nohup

先寫一個sleep.sh腳本,放到后臺執行。

[root@aminglinux-123?test]#?cat?/usr/local/sbin/sleep.sh
!?/bin/bash
[root@aminglinux-123?test]#?nohup?sh?/usr/local/sbin/sleep.sh?&
[1]?40760

screen工具

screen是一個可以在多個進程之間多路復用一個物理終端的窗口管理器。

安裝screen命令yum install -y screen

-bash-4.2#?screen?-ls
There?is?a?screen?on:40865.pts-1.aminglinux-123??????(Detached)
1?Socket?in?/var/run/screen/S-root.