0%

非root安装rsync(使用密码而不是RSA密钥)

2019年11月12日 下午5:31
Linux rsync环境搭建(非ROOT搭建)
手动安装m4, autoconf, automake, libtool

  • 这篇文章中的版本太老,安装inotify会出错,下面的shell我已更新到了合适的版本

需要备份的一端:

auto_install_inotify_rsync.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# 共需修改一项
# 1.声明绝对地址
ab_path=/home/chenzhiheng18/
chmod 777 ~/installed

# 下载地址:https://blog.csdn.net/tanningzhong/article/details/90034371
# 安装rsync
cd ~/software_install/rsync
tar xvzf rsync-3.1.3.tar.gz
cd rsync-3.1.3
./configure --prefix=$ab_path"installed/"
make && make install

# 设置密码
cd ~/installed/
echo "123123" > rsync.passwd
chmod 600 rsync.passwd

# 下载地址:https://blog.csdn.net/qq_30549833/article/details/72955881
# 安装m4
cd ~/software_install/rsync_depend
tar -xzvf m4-1.4.13.tar.gz
cd ~/software_install/rsync_depend/m4-1.4.13
./configure --prefix=$ab_path"installed/"
make && make install

# 安装autoconf
cd ~/software_install/rsync_depend
tar -xzvf autoconf-2.65.tar.gz
cd ~/software_install/rsync_depend/autoconf-2.65
./configure --prefix=$ab_path"installed/"
make && make install

# 安装automake
cd ~/software_install/rsync_depend
tar xzvf automake-1.16.tar.gz
cd ~/software_install/rsync_depend/automake-1.16
./configure --prefix=$ab_path"installed/"
make && make install

# 安装libtool
cd ~/software_install/rsync_depend
tar xzvf libtool-2.4.6.tar.gz
cd ~/software_install/rsync_depend/libtool-2.4.6
./configure --prefix=$ab_path"installed/"
make && make install

# 安装inotify
cd ~/software_install/rsync
tar xvzf inotify-tools-3.20.1.tar.gz
cd inotify-tools-3.20.1
./autogen.sh
./configure --prefix=$ab_path"installed"
make && make install
rsync.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
#!/bin/bash

# 1.当前用户地址
ab_path=/home/chenzhiheng18/
# 2.目标地址
user_host="chenzhiheng18@124.16.75.227"
# 3.需要备份的目录
src=/home/chenzhiheng18/tmp/

des=web
$ab_path"installed/bin/inotifywait" -mrq --timefmt '%d/%m/%y %H:%M' --format '%T %w%f%e' -e modify,delete,create,attrib $src | while read files
do
/usr/bin/rsync --port=30001 -vzrtopg --delete --progress --password-file=$ab_path"installed/rsync.passwd" $src $user_host::$des
echo "${files} was rsynced" >>$ab_path"rsync.log" 2>&1
done

注:chmod 764 rsync.sh

备份到的服务器

auto_install_rsync.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
# 绝对地址
ab_path=/home/chenzhiheng18/
chmod 777 ~/installed

# 安装rsync
cd ~/software_install/rsync
tar xvzf rsync-3.1.3.tar.gz
cd rsync-3.1.3
./configure --prefix=$ab_path"installed/"
make && make install

# 备份服务器需要账户和密码: 这里的路径必须手动更改
user_name=chenzhiheng18
ab_path="/home/"$user_name"/"
cd ~/installed
echo $user_name":123123" > rsync.passwd
chmod 600 rsync.passwd
rsync.conf :是文件 不是shell

文件中需要指明:

  1. 用户绝对路径:用于 pid lock log secrets
  2. port :端口
  3. path:接受文件的文件夹
  4. hosts allow :允许的传送方的ip
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    # 建立rsync.conf配置文件,保存到installed/bin/目录
    use chroot = no
    max connections = 10
    strict modes = yes
    pid file = /home/chenzhiheng18/run/rsyncd.pid
    lock file = /home/chenzhiheng18/run/rsync.lock
    log file = /home/chenzhiheng18/logs/rsyncd.log
    port = 30001
    [web]
    path = /home/chenzhiheng18/tmp/
    comment = web file
    ignore errors
    read only = no
    write only = no
    hosts allow = 124.16.75.219
    hosts deny = *
    list = false
    #auth users = webuser
    secrets file = /home/chenzhiheng18/installed/rsync.passwd
启动rsync
1
2
# 启动rsync
$ab_path"installed/bin/rsync" --daemon --config=$ab_path"installed/bin/rsync.conf"

其他注意事项:

1
2
3
4
5
6
7
# 复制make install 的输出
/bin/mkdir -p /home/chenzhiheng18/installed/bin
/usr/bin/install -c -m 755 rsync /home/chenzhiheng18/installed/bin
/bin/mkdir -p /home/chenzhiheng18/installed/share/man/man1
/bin/mkdir -p /home/chenzhiheng18/installed/share/man/man5
if test -f rsync.1; then /usr/bin/install -c -m 644 rsync.1 /home/chenzhiheng18/installed/share/man/man1; fi
if test -f rsyncd.conf.5; then /usr/bin/install -c -m 644 rsyncd.conf.5 /home/chenzhiheng18/installed/share/man/man5; fi