rsync 通过服务的方式同步 linux系统日志 screen工具

 

rsync 通过服务的方式同步

 

俩台机器传文件IP地址交叉编写。

 

 

主机1:

要编辑配置文件 /etc/rsyncd.conf

rsyncd.conf样例

port=873                     #端口

log file=/var/log/rsync.log

pid file=/var/run/rsyncd.pid

address=10.211.55.16            #(本机IP)

[test]

path=/tmp/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=10.211.55.40     #远程机器IP

 

 

 

 

主机2:

要编辑配置文件 /etc/rsyncd.conf

rsyncd.conf样例

port=873                     #端口

log file=/var/log/rsync.log

pid file=/var/run/rsyncd.pid

address=10.211.55.40            #(本机IP)

[test]

path=/tmp/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=10.211.55.16     #远程机器IP

 

配置文件讲解:

port 指定rsync哪个端口,默认873

log file 指定日志文件

pid file指定pid文件,这个文件的作用设计服务的启动、停止等进程管理操作

address指定启动rsync服务的IP,假如机器有多个IP,可以指定其中一个启动rsync服务,如果不指定该参数,默认在全部IP 上启动

[]指定模块名,里面内容自定义

path指定数据存放的路径

use chroot tru|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

 

 

启动服务rsync --daemon

[root@centos7 ~]# rsync --daemon

查看是否启动服务进程:

[root@centos7 ~]# ps aux|grep rsync

root      1358  0.0  0.0 114652   520 ?        Ss   00:37   0:00 rsync --daemon

root      1368  0.0  0.0 112676   984 pts/0    S+   00:37   0:00 grep --color=auto rsync

[root@centos7 ~]# netstat -lntp

tcp        0      0 10.211.55.16:873        0.0.0.0:*               LISTEN      780/rsync      

[root@centos7 ~]# chmod 777 /tmp/rsync/

 

 

检测端口是否通的命令:[root@centos7 ~]# yum install -y telnet

两台机器分别telnet

telnet 10.211.55.16 873

telent  10.211.55.40  873

 

如果开启了iptables服务和firewalld防火墙服务,先关闭firewalld服务

停止firewalld

[root@centos7 ~]# systemctl stop firewalld.service 

[root@centos7 ~]# systemctl disable  firewalld.service 

 

 

格式:rsync -av test1/     192.168.133.130::module/dir/

 

::mdule 表示配置文件的模块名

 

rsync -avP  test1/     192.168.133.130::test/dir/

 

[root@centos7 ~]# rsync -avP test1/ 10.211.55.40::test/

sending incremental file list

./

1.txt

       32822 100%   52.73kB/s    0:00:00 (xfer#1, to-check=17/19)

 

 

test/ 包含的路径是/tmp/rsync/  这是在test模块中定义的path决定。

 

也可以指定端口

rsync -avLP --port 873  192.168.133.130::test/    /tmp/test/

 

[root@centos7 ~]# rsync -avLP --port 873 10.211.55.40::test/ /tmp/test/

receiving incremental file list

created directory /tmp/test

./

1.txt

           0 100%    0.00kB/s    0:00:00 (xfer#1, to-check=0/2)

sent 48 bytes  received 113 bytes  107.33 bytes/sec

total size is 0  speedup is 0.00

[root@centos7 ~]# ls /tmp/test/

1.txt

 

 

自动列出模块名:

[root@centos7 ~]# rsync --port=873 10.211.55.40::

test     

 

 

服务端:

传输时验证密码:

auth users=test

secrets file=/etc/rsyncd.passwd

密码文件:

vi /etc/rsyncd.passwd

格式是:

用户:密码

test:600

 

免输入密码:

[root@centos7 ~]# vi /etc/rsyncd_pass.txt

[root@centos7 ~]# chmod 600 !$

chmod 600 /etc/rsyncd_pass.txt

 

[root@centos7 ~]# rsync -avP /tmp/test/ --port 873 --password-file=/etc/rsync_pass.txt test@10.211.55.40::test/ 

sending incremental file list

sent 40 bytes  received 8 bytes  96.00 bytes/sec

total size is 0  speedup is 0.00

 

 

配置文件中也可以写多个IP

hosts allow=10.211.55.16   10.211.55.17  192.168.133.0/24(IP段)  #远程机器IP

 

 

linux系统日志

/var/log/messages

logrotate系统服务可以自动切割日志文件

[root@centos7 ~]# ls /var/log/

/etc/logrotate.conf 日志切割配置文件

 

 

dmesg命令

/var/log/dmesg 日志 保存在内存中。

情况日志:[root@centos7 ~]# dmesg -c

重启也会自动生成,记录系统日志

 

last命令,调用的文件/var/log/wtmp

二进制文件只能用last /var/log/wtmp去看。

lastb命令查看登录失败的用户,对应的文件是 /var/log/btmp

lastb /var/log/btmp

安全日志:

/var/log/secure

 

 

 screen工具

为了不让一个任务意外中断。

后台运行:nohup command &

screen是一个虚拟终端

安装包:

yum install -y screen

screen直接回车就进入了虚拟终端

vmstat 1

ctral a组合键再按d退出虚拟终端,但不是结束

[root@centos7 ~]# screen

[detached from 1380.pts-0.centos7]

screen -ls 查看虚拟终端列表

[root@centos7 ~]# screen -ls

There are screens on:

1380.pts-0.centos7 (Detached)

1324.pts-0.centos7 (Detached)

2 Sockets in /var/run/screen/S-root.

screen -r id 进入指定的终端

[root@centos7 ~]# screen -r 1380

 

但是我不知道screen里面运行了什么程序

自定义screen名字:screen -S  "test_screen"  

[root@centos7 ~]# screen -S "test_screen"

回车

Sleep 100

Sctrl + a +d

[detached from 1401.test_screen]

[root@centos7 ~]# screen -ls

There are screens on:

1401.test_screen (Detached)

 

screen -r test_screen 回到原来的屏幕。

 

 

 

 

 

 

原文地址:https://www.cnblogs.com/zhaocundang/p/8397143.html