代码部署工具syncd安装

syncd是什么?

syncd是一款开源的代码部署工具,它具有简单、高效、易用等特点,可以提高团队的工作效率.

syncd开源发布系统安装

  1. 安装GO环境,此处不表

  2. 安装Git环境,此处不表

  3. 安装Nginx/Mysql

  4. 配置部署机器ssh秘钥

    # 生成rsa秘钥
    ssh-keygen -t rsa
    
    # 将公钥发送到目标主机,需要输入密码
    ssh-copy-id -i /root/.ssh/id_rsa.pub root@your-ip
    
    Number of key(s) added: 1
    
    Now try logging into the machine, with:   "ssh 'root@your-ip'"
    and check to make sure that only the key(s) you wanted were added.
    
    # 测试是否成功
    ssh root@your-ip
    
  5. 执行curl https://raw.githubusercontent.com/dreamans/syncd/master/install.sh |bash进行源码编译安装

  6. 安装完成后在源码目录找到syncd.sql,并手动导入sql

    cd /root/go/src/github.com/dreamans/syncd
    ll
    
    # 输出如下,找到syncd.sql,导入mysql
    -rw-r--r--.  1 root root 3.8K 1月  15 21:13 api.go
    -rw-r--r--.  1 root root 1.1K 1月  15 21:13 config.go
    -rw-r--r--.  1 root root 1.3K 1月  15 21:13 db.go
    -rw-r--r--.  1 root root 1.3K 1月  15 21:13 glide.lock
    -rw-r--r--.  1 root root  507 1月  15 21:13 glide.yaml
    -rwxr-xr-x.  1 root root  860 1月  15 21:13 install.sh
    -rw-r--r--.  1 root root 1.1K 1月  15 21:13 LICENSE
    drwxr-xr-x. 13 root root 4.0K 1月  15 21:13 model
    drwxr-xr-x.  7 root root   71 1月  15 21:13 module
    drwxr-xr-x.  3 root root   36 1月  15 21:13 public
    -rw-r--r--.  1 root root 7.1K 1月  15 21:13 README.md
    -rw-r--r--.  1 root root 1.2K 1月  15 21:13 render.go
    drwxr-xr-x.  2 root root 4.0K 1月  15 21:13 resource
    drwxr-xr-x.  2 root root   38 1月  15 21:13 route
    -rw-r--r--.  1 root root 1.4K 1月  15 21:13 sendmail.go
    drwxr-xr-x. 10 root root 4.0K 1月  15 21:13 service
    drwxr-xr-x.  2 root root   47 1月  15 21:13 syncd
    -rw-r--r--.  1 root root  946 1月  15 21:13 syncd.example.ini
    -rw-r--r--.  1 root root 3.4K 1月  15 21:13 syncd.go
    -rw-r--r--.  1 root root 7.7K 1月  15 21:13 syncd.sql
    drwxr-xr-x.  5 root root   62 1月  15 21:13 vendor
    drwxr-xr-x.  4 root root 4.0K 1月  15 21:13 web
    
  7. 修改编译后执行文件所在目录的配置项 (注:我将编译后的源码放到了/www/syncd-deploy/下)
    cd /www/syncd-deploy/
    vim etc/syncd.ini
    
    # 填入配置wq即可
    
  8. 启动
    /www/syncd-deploy/bin/syncd -c /www/syncd-deploy/etc/syncd.ini
    
    # 控制台会输出如下内容
                                             __
      _____   __  __   ____     _____   ____/ /
     / ___/  / / / /  / __ \   / ___/  / __  / 
    (__  )  / /_/ /  / / / /  / /__   / /_/ /  
    /____/   \__, /  /_/ /_/   \___/   \__,_/   
           /____/                              
    
    Service:              syncd
    Version:              1.0.0
    Config Loaded:        /www/syncd-deploy/etc/syncd.ini
    Workspace:            /tmp/.syncd
    Log:                  stdout
    Database:             127.0.0.1
    Mail Enable:          0
    HTTP Service:         :8868
    Start Running...
    
    
  9. 为syncd的web面板配置nginx反向代理,提供访问
       upstream syncdServer {
           server 127.0.0.1:8868 weight=1;
       }
    
       server {
           listen       888;
           server_name  localhost 192.168.123.123; # 此处替换成你的真实域名
           access_log   logs/deploy.syncd.cc.log;
    
           location / {
               try_files $uri $uri/ /index.html;
               root /www/syncd-deploy/public/; # 此处/path请替换成真实路径
               index index.html index.htm;
           }
    
           location ^~ /api/ {
               proxy_pass          http://syncdServer;
               proxy_set_header    X-Forwarded-Host $host:$server_port;
               proxy_set_header    X-Real-IP     $remote_addr;
               proxy_set_header    Origin        $host:$server_port;
               proxy_set_header    Referer       $host:$server_port;
           }
       }
    

    浏览器访问192.168.123.123:888即可看到web面板

附:安装脚本解释

#!/bin/bash

# 定义源码位置变量
syncd_repo="github.com/dreamans/syncd"
build_repo="github.com/dreamans/syncd/syncd"

# 定义安装目录变量
install_path=$( cd `dirname $0`; pwd )/syncd-deploy

if [ -d ${install_path} ];then
    install_path=${install_path}-$( date +%Y%m%d%H%M%S )
fi

# 获取go path
if [ -z ${GOPATH} ];then
    GOPATH=`go env GOPATH`
fi

# 编译函数
build_syncd() {
    go get ${build_repo}
    cd $GOPATH/src/${build_repo}
    go run build.go
}

# 安装函数
install_syncd() {
    mkdir ${install_path}
    cd ${install_path}
    mkdir bin log etc
    cp $GOPATH/src/${build_repo}/syncd ./bin/
    cp $GOPATH/src/${syncd_repo}/syncd.example.ini ./etc/syncd.ini
    cp -r $GOPATH/src/${syncd_repo}/public ./public
}

# 执行编译
build_syncd

# 执行安装
install_syncd

echo "Installing syncd binary: ${install_path}/bin"
echo "Installing web public: ${install_path}/public"
echo "Installing syncd.ini: ${install_path}/etc"
echo "Install complete"

发表评论

电子邮件地址不会被公开。 必填项已用*标注