rsync 通过服务的方式同步
要编辑配置文件 / etc/rsyncd.conf
rsyncd.conf 样例
- port=873
- log file=/var/log/rsync.log
- pid file=/var/run/rsyncd.pid
- address=192.168.21.128
- [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=192.168.21.129 1.1.1.1 2.2.2.2 192.168.21.0/24
创建同步目录, 修改权限, 并启动服务
- [root@akuilinux01 ~]# vim /etc/rsyncd.conf
- [root@akuilinux01 ~]# mkdir /tmp/rsync
- [root@akuilinux01 ~]# chmod 777 /tmp/rsync/
- [root@akuilinux01 ~]# rsync --daemon
- [root@akuilinux01 ~]# ps aux |grep rsync
- root 3408 1.6 0.0 114696 540 ? Ss 22:02 0:00 rsync --daemon
- root 3410 0.0 0.0 112676 980 pts/0 S+ 22:02 0:00 grep --color=auto rsync
- [root@akuilinux01 ~]# netstat -lntp
- Active Internet connections (only servers)
- Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
- tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 880/sshd
- tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN 1080/master
- tcp 0 0 192.168.21.128:873 0.0.0.0:* LISTEN 3408/rsync
- tcp6 0 0 :::22 :::* LISTEN 880/sshd
- tcp6 0 0 ::1:25 :::* LISTEN 1080/master
rsync -avP /tmp/1.txt 192.168.21.128::test/aming02.txt 同步文件
常见错误 http://blog.51cto.com/wjw7702/1148808
密码错误的需要先注释掉
- [root@akuilinux02 ~]# rsync -avP /tmp/1.txt 192.168.21.128::test/aming02.txt
- Password:
- @ERROR: auth failed on module test
- rsync error: error starting client-server protocol (code 5) at main.c(1648) [sender=3.1.2]
- [root@akuilinux01 ~]# vim /etc/rsyncd.conf
- gid=root
- #auth users=test
- #secrets file=/etc/rsyncd.passwd
- hosts allow=192.168.21.129 1.1.1.1 2.2.2.2 192.168.21.0/24
rsync 服务配置文件详解
port: 指定在哪个端口启动 rsyncd 服务, 默认是 873 端口.
log file: 指定日志文件.
pid file: 指定 pid 文件, 这个文件的作用涉及服务的启动, 停止等进程管理操作.
address: 指定启动 rsyncd 服务的 IP. 假如你的机器有多个 IP, 就可以指定由其中一个启动 rsyncd 服务, 如果不指定该参数, 默认是在全部 IP 上启动. - []: 指定模块名, 里面内容自定义.
path: 指定数据存放的路径.
use chroot true|false: 表示在传输文件前首先 chroot 到 path 参数所指定的目录下. 这样做的原因是实现额外的安全防护, 但缺点是需要以 roots 权限, 并且不能备份指向外部的符号连接所指向的目录文件. 默认情况下 chroot 值为 true, 如果你的数据当中有软连接文件, 阿铭建议你设置成 false.
max connections: 指定最大的连接数, 默认是 0, 即没有限制.
read only ture|false: 如果为 true, 则不能上传到该模块指定的路径下.
list: 表示当用户查询该服务器上的可用模块时, 该模块是否被列出, 设定为 true 则列出, false 则隐藏. 如果没有限制 ip 其他人就可以看到模块名并上传木马
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
hosts allow 允许谁来链接, 可以是多个 ip 和 ip 段
修改 rsync 端口号
修改配置文件并重启服务
- [root@akuilinux01 ~]# killall rsync
- [root@akuilinux01 ~]# ps aux |grep rsync
- root 3642 0.0 0.0 112676 980 pts/0 S+ 22:53 0:00 grep --color=auto rsync
- [root@akuilinux01 ~]# rsync --daemon
- [root@akuilinux01 ~]# !ps
- ps aux |grep rsync
- root 3645 0.8 0.0 114696 540 ? Ss 22:54 0:00 rsync --daemon
- root 3647 0.0 0.0 112676 980 pts/0 S+ 22:54 0:00 grep --color=auto rsync
- [root@akuilinux01 ~]# !net
- netstat -lntp
- Active Internet connections (only servers)
- Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
- tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 880/sshd
- tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN 1080/master
- tcp 0 0 192.168.21.128:8730 0.0.0.0:* LISTEN 3645/rsync
- tcp6 0 0 :::22 :::* LISTEN 880/sshd
- tcp6 0 0 ::1:25 :::* LISTEN 1080/master
--port 8730 选项指定端口
[root@akuilinux02 ~]# rsync -avP --port 8730 /tmp/1.txt 192.168.21.128::test/aming02.txt
sending incremental file list
- sent 44 bytes received 12 bytes 112.00 bytes/sec
- total size is 846 speedup is 15.11
系统日志
/var/log/messages 系统的总日志, 包括网络, 系统服务, 内核的日志
系统有个自动切割机制 logrotate, 他的配置文件为 / etc/logratate.conf, 每周切割一次, 只保留四个
root@akuilinux02 ~]# ls /var/log/messages*/var/log/messages /var/log/messages-20180313 /var/log/messages-20180328 /var/log/messages-20180512
linux 写文件时找的是文件的 inode, 所以日志切割的时候需要重启下日志服务
参考 https://my.oschina.net/u/2000675/blog/908189
dmesg 命令, 查看硬件的错误日志, 存放在内存中
加 - c 清空日志
/var/log/dmesg 系统启动的日志
last 命令, 调用的文件 / var/log/wtmp. 查看用户登录信息的日志
lastb 命令查看登录失败的用户, 调用的是 / var/log/btmpwenj
/var/log/secure 安全日志, 记录登录验证成功或失败都会记录
screen 工具
为了不让一个任务意外中断
nohup command & 这个没法看到输出信息
screen 是一个虚拟终端
yum install -y screen
screen 直接回车就进入了虚拟终端
ctral a 组合键再按 d 退出虚拟终端, 但不是结束
screen -ls 查看虚拟终端列表
screen -r id 进入指定的终端
screen -S aming 自定义名字
screen -r aming 进入自定义的终端
扩展
Linux 日志文件总管 logrotate http://linux.cn/article-4126-1.html
xargs 用法详解 http://blog.csdn.net/zhangfn2011/article/details/6776925
来源: http://www.bubuko.com/infodetail-2602915.html