跳至主要内容

利用rsync同步本地图片文件到服务器(完结篇)

各位看官本文章为特色要求服务,国内服务器版本请按照七牛同步文件夹文章制作.

为什么这里Sandy要用到这个技能呢?因为打怪的路上很墙.....有备案墙拉,GFW墙拉....太多怪了!所以需要用到这个技能

例如:

本地采集器服务器:192.168.1.2 (windows 7)

本地图片服务器:192.168.1.3 (ubuntu 16)

网络图片服务器:191.1.1.1 (ubuntu 16)

rsync -avz -e ssh /home/wwwroot/default/pic/ root@191.1.1.1:/home/wwwroot/pic

我们在执行这段代码的时候会要求你输入密码,不利于自动化.

所以我们需要无密码登录SSH

应该怎么做呢?如下操作:

1.首先我们在ubuntu设置无密码登录SSH
现在我们来配置ssh使得通过ssh执行rsync时不再索要密码。在本地服务器上使用ssh-keygen生成公钥和秘钥,如下命令:

$ ssh-keygen 
Enter passphrase (empty for no passphrase): 
Enter same passphrase again:

注意:当它要求您输入passphrase按下enter键,不需要给任何密码

使用ssh-copy-id命令将公钥拷贝至远程主机

$ ssh-copy-id -i ~/.ssh/id_rsa.pub 191.1.1.1

注:执行以上操作时会要求你输入远程主机帐户和密码,然后就会自动将公钥拷贝至远程目录。

现在,你可以不需要密码通过ssh连接到远程主机

再次执行rsync,它将不再要求你输入密码

$ rsync -avz -e ssh /home/wwwroot/default/pic/ root@191.1.1.1:/home/wwwroot/pic

ubuntu 通过rsync同步到服务器

 2.利用crontab定时执行同步

crontab -e
#每三分执行一下图片同步
*/3 * * * * rsync -avz -e ssh /home/wwwroot/default/pic/ root@191.1.1.1:/home/wwwroot/pic

这样就完成了Rsync部分了

但是问题又来了,我不想在本地图片服务器装个LNMP或者FTP之类的.也不想通过采集器去上传到本地图片服务器(采集东西多了太慢),于是Samba来了

3.本地图片服务器建立Samba

安装Samba

sudo apt-get install samba samba-common-bin

打开Samba配置文件:

vi /etc/samba/smb.conf 

在其最后添加:

[share]  
    path = /home/wwwroot/default/pic
    valid users = share
    available = yes  
    browseable = yes  
    writable = yes  
    public = no  

创建Samba用户

sudo useradd username
sudo smbpasswd -a username 

重启Samba

sudo service smbd restart

测试
在Ubuntu的Files底部的Network中选择Connect to Server, 然后在弹出来的对话框中深入smb://192.168.1.3/share, 然后点击右下角的Connect按钮. 此时会提示输入密码(在第3步中创建),输入密码后即可进入共享目录。

在Windows电脑上,输入“\\192.168.1.3\share”,然后输入用户名(share)和密码后,既可以访问了! 或者通过我的电脑右键映射服务器也可以

然后把采集器图片保存目录指向网络共享盘即可.这样采集数据就会快很多了

 

评论

此博客中的热门博文

阿里云通过Nginx中转Linode/digitalocean/AWS的V2ray协议,实现负载均衡

开篇文的废话.原因是Sandy做站服务器太多了,发现利用率不高,皮又痒了又想折腾了.v2ray是利器但是给人的感觉就是只能用一台服务器,官方也说不支持负载均衡,不会A服务器挂机,自动跳转到B服务器.这里就有点折磨人了.每个服务器挂了都要自己去改配置文件. 我们访问国外的服务器,如果没CN2的线路是非常慢的,起码不快!哈哈~现在VPS都便宜起码人手一个人有5台以上吧?这样的话我们就可以开整. 开整条件:国内VPS或者阿里云有CN2线路的机器最好是100MB-200MB的带宽的.保证你爽歪歪.但是Sandy在阿里云HK30MB下也测试了也可以达到30000KB以上,羡慕吧~我们可以开始了! 老规则工具先出: 没被gwf和谐的服务器1台(下文统称:主服务器) 国外服务器2台以上(下文统称:从服务器) nginx 1.9.5版本以上(推荐:lnmp1.4) v2ray croe 第一步: 在 主服务器 安装lnmp1.4,这里就不细说教程了.直接去 官方 看教程 安装完毕以后我们来升级Nginx让他支持stream模块 cd lnmp1.4 vi lnmp.conf 在Nginx_Modules_Options=‘’里面加入--with-stream Nginx_Modules_Options='--with-stream’ 然后执行升级命令 ./upgrade.sh nginx  第二步 修改nginx.conf文件 cd /usr/local/nginx/conf/nginx.conf 在 events { use epoll; worker_connections 51200; multi_accept on; } 下面加入 stream{ server{ listen 0.0.0.0:8080; proxy_pass v2ray_backend; proxy_timeout 10m; proxy_connect_timeout 5000ms; } upstream v2ray_backend{ server ...

利用haproxy来做V2RAY负载均衡

Sandy在之前有说过 阿里云通过Nginx中转Linode/digitalocean/AWS的V2ray协议,实现负载均衡 ,有些学童不想折腾nginx,那么我们可以用haproxy来折腾,不管是haproxy还是Nginx都可以在树莓派和局域网的PC机器折腾! 安装haproxy的教程就移步到-> haproxy安装教程 apt-get install haproxy 安装完毕,我们来修改haproxy的配置 vi /etc/haproxy/haproxy.cfg 里面内容全部删除,加入下面的内容 global ulimit-n 51200 log /dev/log local0 log /dev/log local1 notice chroot /var/lib/haproxy pidfile /var/run/haproxy.pid user haproxy group haproxy daemon defaults log global mode tcp retries 3 option dontlognull option redispatch #上游TCP服务器连接等待时间 timeout connect 5s timeout client 24h timeout server 24h #以下为Web管理页面设置,如不需要可以删除 listen admin_stats bind 0.0.0.0:8888 mode http log 127.0.0.1 local0 err stats refresh 30s stats uri /haproxy stats realm welcome login\ Haproxy stats auth admin:admin stats hide-version stat...

ssh over socks5:通过socks5 proxy来连接ssh服务器[转载]

最近因为不可描述的原因,我在aws soul的云主机访问不了,ssh、80、ss全部都被禁掉了。 80端口在chrome配置SwitchyOmega就可以了,但ssh不太好办,shell上配置http_proxy对ssh没什么用。 其实ssh自己就支持proxy。 注意这跟在ssh端口转发:远程和本地中介绍过使用ssh作为proxy的方法不同,ssh -D是为了用ssh做proxy,而不是通过proxy来连接ssh服务器。 TL;DR ssh -o ProxyCommand='nc -x 192.0.2.0:1080 %h %p' user@awshost 原理解析 $ man ssh_config ProxyCommand Specifies the command to use to connect to the server. The command string extends to the end of the line, and is executed using the user's shell ‘exec’ directive to avoid a lingering shell process. In the command string, any occurrence of ‘%h’ will be substituted by the host name to connect, ‘%p’ by the port, and ‘%r’ by the remote user name. The command can be basically anything, and should read from its standard input and write to its standard output. It should eventually connect an sshd(8) server running on some machine, or execute sshd -i somewhere. Host key management will be done using the HostName of the host being connected (defa...