10.32/10.33 rsyncサービス同期10.34 linuxシステムログscreenツール


バックグラウンドサービスによる方法
リモートホスト上にrsyncのサーバを確立し、サーバ上にrsyncの様々なアプリケーションを構成し、ホストをrsyncのクライアントとしてリモートのrsyncサーバに接続します.
128ホスト上でrsyncのプロファイル/etc/rsyncdを作成して構成する.君の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 {
    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.

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 ([email protected]) (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は、複数のプロセス間で1つの物理端末を多重化できるウィンドウマネージャです.
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.