首页 / 安装部署 / linux下syncthing同步工具的部署记录,自启动

linux下syncthing同步工具的部署记录,自启动

2018-11-02 14:56:33安装部署 阅读 7580
创建用于运行程序的普通用户
useradd -m -s /bin/bash syncthing_user
passwd syncthing_user #创建密码
安装:解压后放到相应目录即可,这里wget所使用的url为 v1.26版本
wget https://github.com/syncthing/syncthing/releases/download/v1.26.0/syncthing-windows-amd64-v1.26.0.zip
tar -zxvf syncthing-linux-amd64-v1.26.0.tar.gz
mv syncthing-linux-amd64-v1.26.0 /usr/local/syncthing
#编写一个自启动脚本
vim /usr/local/syncthing/check_start.py
#!/usr/bin/python
#coding:utf-8
import os,time
#当前文件路径
current_path = os.getcwd()
log_file = current_path+'/check.log'
def is_runing(process_name):
        try:
                process = len(os.popen('ps aux | grep "' + process_name + '" | grep -v grep').readlines())
                if process > 0:
                        return 1
                else:
                        return 0
        except:
                return 0

def log(message):
        os.popen('echo ['+time.strftime("%Y-%m-%d %H:%M:%S", time.localtime(time.time()))+'] '+message+' >> '+log_file)

proc_tag = '/usr/local/syncthing/syncthing'

if is_runing(proc_tag) == 0:
        log('syncthing 进程没有运行或已停止!')
        os.popen('/sbin/runuser -l syncthing_user -c '+proc_tag.replace('$','')+' >> /dev/null &')
else:
        log('syncthing 正常')


chmod +x ./check_start.py
添加到定时任务,一分钟检查一次脚本运行情况
* * * * * python /usr/local/syncthing/check_start.py

此刻如果运行没问题,本机访问 http://127.0.0.1:8384/ 就能进到到syncthing的gui了,对要同步的目录要给于相应的读写权限才能正常运行任务。

如果是无桌面Linux,要访问webui只有通过外网ip访问,即服务器的 http://服务器ip:8384 ,则涉及到防火墙端口放行、https加密、以及使用用户名密码登录gui。


配置syncthing的非本机访问,即局域网或公网访问。

1、编辑配置文件,配置文件在程序第一次运行时会自动创建,存放在用户目录的.config/syncthing/config.xml下


vim /home/syncthing_user/.config/syncthing/config.xml


找到
<gui enabled="true" tls="false" debugging="false" sendBasicAuthPrompt="false">
        <address>127.0.0.1:8384</address>
        <apikey>xxxxxxxxxxxxxxxxxxxxx</apikey>
        <theme>default</theme>
</gui>

修改为
<gui enabled="true" tls="true" debugging="false" sendBasicAuthPrompt="false">
<address>0.0.0.0:8384</address>
<user>myusername</user>
<password></password>
<apikey>xxxxxxxxxxxxxxxxxxxxx</apikey>
<theme>default</theme>
</gui>

以上变动的地方为
<gui ... tls="true" ..>  启用了https
<address>0.0.0.0:8384</address> 监听
<user>myusername</user> 用户名
<password></password> 密码


password一定为用空,因为这里写明文是不对的,登录会一直密码错误,保持为空在登录后通过gui设置


2、防火墙根据业务需求开启端口 8384 和 22000,端口开放一般建议白名单,尤其还是无密码的情况下。


firewall-cmd --zone=public --permanent --add-rich-rule='rule family="ipv4" source address="192.168.10.22" port protocol="tcp" port="8384" accept'
firewall-cmd --zone=public --permanent --add-rich-rule='rule family="ipv4" source address="192.168.10.22" port protocol="tcp" port="22000" accept'
firewall-cmd --reload


3、目录权限,由于需要同步的目录一定是其它应用程序权限,因此需要增加syncthing用户的权限或直接设置为77X等

setfacl -R  -m u:syncthing_user:rxw /web/public_html/agentmanage
setfacl -R  -d -m u:syncthing_user:rxw /web/public_html/agentmanage

#其中参数-n 为不重新计算mask ,移除参考如下

setfacl -R -x u:www /web/public_html/agentmanage/data/runtime/log #移除www用户的facl权限
4、关于软件升级,可以尝试先升级,升级的时候不要运行
[root@localhost]# ./syncthing --upgrade
13:37:25 INFO: Default folder created and/or linked to new config
13:37:27 INFO: Upgrade available (current "v0.14.43" < latest "v1.1.1")
13:37:35 INFO: Upgraded to "v1.1.1"

本文《linux下syncthing同步工具的部署记录,自启动》由爱思考吧 isres.com 分享,转载请注明出处。本文网址:https://www.isres.com/bushu/10.html

本站主要收集测评能够节省时间和提升效率的软件工具并分享使用与学习的过程和感受,任何情况下用户都需遵守所使用软件资源的相关协议。与《linux下syncthing同步工具的部署记录,自启动》有关的本站文章及资源仅供个人学习交流使用,相关资源请下载后24小时内删除,请勿用于其它用途,因此产生的任何问题由您自行承担。

猜你喜欢

  • Centos kvm以及kvm gui管理工具部署

    yum install -y qeum-kvm qemu-kvm-tools virt-manager libvirt virt-install yum -y install https://dl....

    2023-04-25 12:16:26 544
  • Centos7minimal安装playwright和firefox、chromium,终于跑起来了

    Centos7minimal安装playwright和firefox、chromium,终于跑起来了

    系统环境为CentOS Linux release 7.9.2009 (Core) 最小安装,考虑到playwright的安装需要python3.7+,本次直接选择安装python3.10...

    2023-07-18 11:19:30 923
  • 2分钟快速安装部署mysql5.7

    今天分享mysql5.7在Linux的安装部署,服务器运维工作都会涉及到安装部署mysql5.7。 mysql5.7在Linux的安装一般有三个方法,分别是: 1、源码编译安装 2、rpm包安装 3、...

    2023-04-24 11:53:13 537
  • windows server 2012 r2激活工具

    windows server 2012 r2激活工具

    最近倒腾下windows server 2012 r2,一直没成功激活,放了大半个月,今天睡觉前再看下,找到了个能用的激活工具,就记录下。 工具名称应该是 KMSpico ,从https://www....

    2020-04-14 15:21:24 8963
  • Linux安装php imagick扩展

    yum install autoconf gcc gcc-c++ ImageMagick-devel wget https://pecl.php.net/get/imagick-3.4.4.tgz ...

    2023-03-23 16:18:16 511
  • pytroch AI机器学习环境部署,RTX3080显卡

    pytroch AI机器学习环境部署,RTX3080显卡

    网上关于机器学习环境部署的文章资料很多,有些可能只是一部分过程,有些则写得很长很长,遇到一些比较好的但要专业知识才能看得懂。 个人曾经看了一个80分钟环境部署视频,事实上只需要一页文档就能说清楚的,视...

    2023-04-24 12:37:24 626
  • Centos一键安装部署vsftp

    Centos一键安装部署vsftp

    每次给不同的人配置ftp,都手工搞一次,决定简化这一步操作。 1、自动安装vsftp 2、自动设置被动模式、并打开iptables端口 3、支持自动创建ftp目录 帐号 密码 4、安装后,以后每次运行...

    2016-10-31 14:22:13 2914
  • LuaJIT-2.1.0相关以及ngx_lua_waf防火墙配置相关

    wget https://www.isres.com/file/LuaJIT-2.1.0-beta3.tar.gz tar -zxvf LuaJIT-2.1.0-beta3.tar.gz cd Lu...

    2018-01-20 14:44:41 3184