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

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

2018-11-02 14:56:33安装部署 阅读 9097
创建用于运行程序的普通用户
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小时内删除,请勿用于其它用途,因此产生的任何问题由您自行承担。

猜你喜欢

  • php7编译安装mcrypt

    最近在部署一个第三方消息的时候,发现需要 mcrypt_get_block_size ,因此产生了 mcrypt的编译安装. cd /usr/tmp wget http://pecl.php.net...

    2023-04-25 12:23:02 1098
  • nginx实现waf运行环境lua扩展的部署

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

    2023-04-25 12:09:24 1123
  • RTX3080显卡本机部署通义万相教程,文本生成视频实战

    RTX3080显卡本机部署通义万相教程,文本生成视频实战

    通义万相1.3B文生视频效果图一 通义万相1.3B文生视频 效果图二 通义万相本地部署 #基于conda创建python环境 conda create -n wanxiang_new python=...

    2025-03-01 12:14:04 988
  • pytroch AI机器学习环境部署,RTX3080显卡

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

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

    2023-04-24 12:37:24 1601
  • Ubuntu 22.4 服务器版安装3090显卡驱动与CUDA

    Ubuntu 22.4 服务器版安装3090显卡驱动与CUDA

    安装cuda成果展示 解决GCC问题 根据遇到的过的坑,我的笔记里第一步就是解决系统gcc问题。 可通过  https://docs.nvidia.com/cuda/archive/12....

    2024-10-02 12:44:49 1261
  • linux下syncthing同步工具的部署记录,自启动

    创建用于运行程序的普通用户 useradd -m -s /bin/bash syncthing_user passwd syncthing_user #创建密码 安装:解压后放到相应目录即可,这里wg...

    2018-11-02 14:56:33 9097
  • Centos7 Python3.10安装部署

    Python3.10需要openssl1.11,而默认的不是,如果忽略这个,之后在跑Python会报错 (Caused by SSLError("Can't connect to HTTPS URL...

    2023-04-27 13:35:04 1708
  • 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 2561