10.32/10.33 rsync通过服务同步 10.34 linux系统日志 screen工具

通过后台服务的方式

在远程主机上建立一个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 {
    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是一个可以在多个进程之间多路复用一个物理终端的窗口管理器。

安装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.


猜你喜欢

转载自blog.51cto.com/13107353/2147500