1.守护进程方式(socket)

Rsync 软件的工作方式

Rsync 软件的工作方式

 

 语法:

Access via rsync daemon:
  Pull: rsync [OPTION...] [USER@]HOST::SRC... [DEST]
        rsync [OPTION...] rsync://[USER@]HOST[:PORT]/SRC... [DEST]
  Push: rsync [OPTION...] SRC... [USER@]HOST::DEST(DEST为模块名字)
        rsync [OPTION...] SRC... rsync://[USER@]HOST[:PORT]/DEST

1.1、rsync 软件部署过程(服务端):

1.确认rsync软件服务是否存在【一般为系统自带

[root@backup ~]# ## 01: 确认rsync软件服务是否存在 
 [root@backup ~]# rpm -qa rsync
rsync-3.0.6-12.el6.x86_64
[root@backup ~]# rpm -qa|grep rsyn*
rsyslog-5.8.10-10.el6_6.x86_64
rsync-3.0.6-12.el6.x86_64

2.编辑配置文件【自己创建的

[root@backup ~]#vim /etc/rsyncd.conf
##rsyncd.conf start##
uid = rsync
gid = rsync
use chroot = no
max connections = 200             ##多少个人可以并发往服务器上传输数据
timeout = 300
pid file = /var/run/rsyncd.pid
lock file = /var/run/rsync.lock                 ##服务停止的时候会用到,不用创建也会有
log file = /var/log/rsyncd.log
[backup]                               ##模块名称
path = /backup
ignore errors
read only = false
list = false          ##当list = true
        可以看到配置文件中所有的模块信息:rsync rsync_backup@172.16.1.41::
hosts allow = 172.16.1.0/24
hosts deny = 0.0.0.0/32
auth users = rsync_backup
secrets file = /etc/rsync.password

Rsync 软件的工作方式

3.创建用户

[root@backup ~]# # 创建用户
[root@backup ~]# useradd -s /sbin/nologin -M rsync
[root@backup ~]# id rsync
uid=923(rsync) gid=923(rsync) groups=923(rsync)

4.创建目录

[root@backup ~]# # 创建目录
[root@backup ~]# mkdir /backup -p
[root@backup ~]# ll -d /backup/
drwxr-xr-x 2 root root 4096 May  4 12:00 /backup/

5、修改备份目录权限

[root@backup ~]# # 修改备份目录权限
[root@backup ~]# chown -R rsync.rsync /backup/
[root@backup ~]# ll -d /backup/
drwxr-xr-x 2 rsync rsync 4096 May  4 12:00 /backup/

6、创建认证用户密码文件

[root@backup ~]# # 创建认证用户密码文件
[root@backup ~]# echo "rsync_backup:123456" >/etc/rsync.password
[root@backup ~]# cat /etc/rsync.password
rsync_backup:123456
[root@backup ~]# chmod 600 /etc/rsync.password
[root@backup ~]# ll /etc/rsync.password
-rw------- 1 root root 20 May  4 12:04 /etc/rsync.password

7、启动rsync守护进程服务

启动rsync守护进程服务
rsync --daemon
[root@backup /]# rsync --daemon
[root@backup /]# ps -ef |grep rsync
root       1885      1  0 12:08 ?        00:00:00 rsync --daemon
root       1887   1250  0 12:09 pts/1    00:00:00 grep rsync

经过上面的配置,服务器已经配置好了,但是每次开机的时候都要开启守护进程,这个时候我们就要利用下面几种方式来实现开机自启动。

 另外,还可以将守护进程加入开机自启动,下面提供几种开机自启动的方式。

1) 利用/etc/rc.local

[root@backup ~]# echo "# rsync boot info" >>/etc/rc.local

[root@backup ~]# echo "rsync --daemon" >>/etc/rc.local

[root@backup ~]# tail -2 /etc/rc.local

# rsync boot info

rsync --daemon

2) 编写脚本文件

编写出脚本文件,可以利用rsync --daemon启动命令

将编写脚本文件,放置到/etc/init.d/ 目录下面

脚本内容信息要添加 # chkconfig: 2345 55 25

授予脚本执行权限

添加到chkconfig启动管理服务列表中

3) xinetd自启动rsync服务,添加到chkconfig启动管理服务列表中

1.如果机器上没有xinetd这个软件,要先安装
[root@backup backup]# yum install -y xinetd
Loaded plugins: fastestmirror, security
Setting up Install Process
Determining fastest mirrors
 * base: mirrors.aliyun.com
 * epel: mirrors.aliyun.com
 * extras: mirrors.aliyun.com
 * updates: mirrors.aliyun.com
(省略安装过程)
2.修改配置文件vim /etc/xinetd.d/rsync,将disable改为no
[root@backup xinetd.d]# vim /etc/xinetd.d/rsync
# default: off
# description: The rsync server is a good addition to an ftp server, as it \
#       allows crc checksumming etc.
service rsync
{
        disable = no    ##(原有的yes改成no)
        flags           = IPv6
        socket_type     = stream
        wait            = no
        user            = root
        server          = /usr/bin/rsync
        server_args     = --daemon
        log_on_failure  += USERID
}
3.开启xinetd服务
[root@backup xinetd.d]# /etc/init.d/xinetd start
Starting xinetd:                                           [  OK  ]
[root@backup xinetd.d]#
4.查看xinetd端口,看是否开启
[root@backup xinetd.d]# netstat -lntup|grep 873      ###查看xinetd
tcp        0      0 :::873                      :::*                        LISTEN      4070/xinetd         
[root@backup xinetd.d]# /etc/init.d/xinetd stop
Stopping xinetd:                                           [  OK  ]

[root@backup xinetd.d]# rsync --daemon
[root@backup xinetd.d]# netstat -lntup|grep 873
tcp        0      0 0.0.0.0:873                 0.0.0.0:*                   LISTEN      4091/rsync          
tcp        0      0 :::873                      :::*                        LISTEN      4091/rsync
5.添加到chkconfig启动管理服务列表中
[root@backup run]# chkconfig --add xinetd
[root@backup run]# chkconfig --list |grep 3:on
crond              0:off    1:off    2:on    3:on    4:on    5:on    6:off
network            0:off    1:off    2:on    3:on    4:on    5:on    6:off
rsyslog            0:off    1:off    2:on    3:on    4:on    5:on    6:off
sshd               0:off    1:off    2:on    3:on    4:on    5:on    6:off
sysstat            0:off    1:on    2:on    3:on    4:on    5:on    6:off
xinetd             0:off    1:off    2:off    3:on    4:on    5:on    6:off
[root@backup run]#
View Code

相关文章:

  • 2021-10-18
  • 2021-06-03
  • 2021-07-23
  • 2021-09-23
猜你喜欢
  • 2022-01-03
  • 2021-09-03
  • 2021-07-05
  • 2021-08-08
  • 2022-12-23
  • 2022-12-23
  • 2021-07-15
相关资源
相似解决方案