syncd的使用和部署

簡介

syncd是一款開源的代碼部署工具,它具備簡單、高效、易用等特色,能夠提升團隊的工做效率.html

安裝

首先建立一臺服務器mysql

我使用的是centos以後使用個人centos初始化腳本初始化一下linux

curl -O https://raw.githubusercontent.com/bboysoulcn/centos/master/centos.shnginx

接着就來安裝這個玩意git

首先安裝gogithub

下載gosql

wget https://dl.google.com/go/go1.11.5.linux-amd64.tar.gz數據庫

解壓vim

tar -zxvf go1.11.5.linux-amd64.tar.gzcentos

mv go /usr/local

添加環境變量

vim /etc/profile

在文件最後添加

export PATH=$PATH:/usr/local/go/bin

以後

source /etc/profile

go 安裝完成

安裝git

yum install git

安裝nginx

安裝依賴

yum install pcre-devel zlib-devel openssl-devel

下載nginx

wget https://nginx.org/download/nginx-1.14.2.tar.gz

解壓

tar -zxvf nginx-1.14.2.tar.gz

編譯安裝

cd nginx-1.14.2 && ./configure --prefix=/usr/local/nginx/ && make -j 4 && make install

以後添加環境變量

vim /etc/profile

加入

export PATH=$PATH:/usr/local/nginx/sbin/

以後

source /etc/profile

使用systemed管理nginx

vim /etc/systemd/system/nginx.service

加入

[Unit]
Description=This is nginx service is Powered by bboysoul
After=syslog.target network.target remote-fs.target nss-lookup.target

[Service]
Type=forking
PIDFile=/usr/local/nginx/logs/nginx.pid
ExecStartPre=/usr/local/nginx/sbin/nginx -t
ExecStart=/usr/local/nginx/sbin/nginx
ExecReload=/usr/local/nginx/sbin/nginx -s reload
ExecStop=/usr/local/nginx/sbin/nginx -s stop

[Install]
WantedBy=multi-user.target

啓動nginx

systemctl restart nginx

systemctl status nginx

部署mysql

下載

wget https://dev.mysql.com/get/Downloads/MySQL-8.0/mysql-8.0.14-1.el7.x86_64.rpm-bundle.tar

解壓

tar -xvf mysql-8.0.14-1.el7.x86_64.rpm-bundle.tar

安裝

yum install ./*.rpm

設置root密碼,首先查看如今root密碼

systemctl start mysqld

➜  ~ cat /var/log/mysqld.log
2019-01-30T09:32:42.986730Z 0 [System] [MY-013169] [Server] /usr/sbin/mysqld (mysqld 8.0.14) initializing of server in progress as process 6081
2019-01-30T09:32:49.182874Z 5 [Note] [MY-010454] [Server] A temporary password is generated for root[@localhost](https://my.oschina.net/u/570656): &%/JDroDY8KB
2019-01-30T09:32:50.263850Z 0 [System] [MY-013170] [Server] /usr/sbin/mysqld (mysqld 8.0.14) initializing of server has completed
2019-01-30T09:32:52.485123Z 0 [System] [MY-010116] [Server] /usr/sbin/mysqld (mysqld 8.0.14) starting as process 6128
2019-01-30T09:32:53.079695Z 0 [Warning] [MY-010068] [Server] CA certificate ca.pem is self signed.
2019-01-30T09:32:53.101782Z 0 [System] [MY-010931] [Server] /usr/sbin/mysqld: ready for connections. Version: '8.0.14'  socket: '/var/lib/mysql/mysql.sock'  port: 3306  MySQL Community Server - GPL.
2019-01-30T09:32:53.139743Z 0 [System] [MY-011323] [Server] X Plugin ready for connections. Socket: '/var/run/mysqld/mysqlx.sock' bind-address: '::' port: 33060

mysql_secure_installation

按照流程操做

以後重啓一下mysql的服務

systemctl restart mysqld

安裝syncd

首先下載二進制包

wget https://github.com/dreamans/syncd/releases/download/1.1.2/Syncd-v1.1.2-linux-amd64.tar.gz

解壓

tar -zxvf Syncd-v1.1.2-linux-amd64.tar.gz

mv Syncd-v1.1.2-linux-amd64 /usr/local/syncd

導入數據庫

wget https://raw.githubusercontent.com/dreamans/syncd/master/syncd.sql

➜  ~ mysql -u root -p
Enter password:
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 8
Server version: 8.0.14 MySQL Community Server - GPL

Copyright (c) 2000, 2019, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> create database syncd;
Query OK, 1 row affected (0.01 sec)

mysql> use syncd
Database changed
mysql> source /root/syncd.sql;
Query OK, 0 rows affected (0.03 sec)

Query OK, 0 rows affected (0.03 sec)

Query OK, 0 rows affected (0.03 sec)

Query OK, 0 rows affected (0.03 sec)

Query OK, 0 rows affected (0.02 sec)

Query OK, 0 rows affected (0.03 sec)

Query OK, 0 rows affected (0.02 sec)

Query OK, 0 rows affected (0.02 sec)

Query OK, 0 rows affected (0.04 sec)

Query OK, 1 row affected (0.01 sec)

Query OK, 0 rows affected (0.02 sec)

Query OK, 1 row affected (0.01 sec)

Query OK, 0 rows affected (0.02 sec)

mysql>

修改配置文件

vim /usr/local/syncd/etc/syncd.ini

個人配置文件就不貼了,都是中文配置起來很簡單的

啓動

輸入下面的命令就能夠啓動

./bin/syncd -c ./etc/syncd.ini

➜  syncd ./bin/syncd -c ./etc/syncd.ini
                                          __
   _____   __  __   ____     _____   ____/ /
  / ___/  / / / /  / __ \   / ___/  / __  /
 (__  )  / /_/ /  / / / /  / /__   / /_/ /
/____/   \__, /  /_/ /_/   \___/   \__,_/
        /____/

Service:              syncd
Version:              1.1.0
Config Loaded:        ./etc/syncd.ini
Workspace:            /tmp/.syncd
Log:                  "/usr/local/syncd/log/syncd.log"
Database:             127.0.0.1
Mail Enable:          0
HTTP Service:         :8868
Start Running...

若是你想後臺的話那就使用screen這個命令好了

以後修改nginx的配置

vim /usr/local/nginx/conf/nginx.conf

在最後的括號以前加上

include ./vhosts/*.conf;

以後添加新的配置文件

mkdir /usr/local/nginx/conf/vhosts

vim /usr/local/nginx/conf/vhosts/syncd.conf

加入

upstream syncdServer {
    server 127.0.0.1:8868 weight=1;
}
server {
    listen       8080;
    server_name  localhost; # 此處替換成你的真實域名
    access_log   /usr/local/syncd/log/syncd-nginx.log;

    location / {
        try_files $uri $uri/ /index.html;
        root /usr/local/syncd/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;
    }
}

以後直接瀏覽器打開ip:8080就能夠訪問了

默認

更新git

目前爲止centos的官方倉庫的git版本是1.8.3.1

若是使用這個版本會出現下面這個問題,這個花了我十分鐘找問題緣由,後來做者一秒鐘就回答我緣由了,是git版本過低的問題,那麼就從新安裝git就能夠了

刪除本地git

yum remove git

安裝依賴

yum install curl-devel expat-devel gettext-devel openssl-devel zlib-devel

下載

wget https://github.com/git/git/archive/v2.20.1.tar.gz

解壓

tar -zxvf v2.20.1.tar.gz

編譯安裝

cd git-2.20.1/

make all

make install

看下版本

git --version

使用

第一步咱們添加一個服務器

點擊集羣管理->新建集羣->輸入集羣名字

以後咱們添加服務器,注意服務器和syncd這臺機器要能夠免密登陸,我syncd這臺服務器的ip是192.168.17.65要部署項目的服務器是192.168.17.96,因此要在192.168.17.65執行

ssh-keygen

ssh-copy-id root@192.168.17.96

點擊服務器管理->新增服務器->輸入相關信息

以後的步驟仍是看做者的流程圖吧,很簡單的,若是寫要一大堆,懶得寫了

歡迎關注Bboysoul的博客www.bboysoul.com

Have Fun

相關文章
相關標籤/搜索