Taek's blog


  • Home

  • Archives

  • Tags

  • About

Docker + Gogs + SSH + Drone.io + Nginx

Posted on 2018-08-12

Gogs是Go语言编写的轻量级开源Git Platform

搭建契机

我在职的公司在韩国,运营的服务是针对中国用户。
目前使用阿里云服务器 + 代码托管Gogs + Drone来处理自动部署。

之前代码托管使用Bitbucket,发现自动部署的时候很慢。
而且Drone因代码pull的时候频繁发生Zombie Process,针对这样的现象
也想过搭建vpn服务,不过与Drone相应用的时候没有找到合理的方法,
所以弃之,开始自行搭建代码托管所。也考虑过大名鼎鼎的Gitlab,
在比较之下Gitlab会比较占用服务器资源,就打消了念头,直接奔向Gogs了。
也有Gitae的开源项目但是还是选择了Gogs,支持国产,
而且目前使用的Drone也可以直接与Gogs相配合使用。

未完待续 …

CI/CD Open Source Platform - Drone

Posted on 2018-07-09

Drone是Go语言编写的轻量级CI/CD工具

体验感受

简单说明的话,Drone Server用于接受bitbucket/github等代码托管所发出的webHook并解析代码Root上的.drone.yml文件所配置的自定义程序并传达给连接Server的Agent
来执行实际的测试与部署。
测试与部署的速度很快,而且占用服务器资源很少,这点非常喜欢,不过可惜的是没有并行,比方说api 与 bms 两个项目同时push之后,FIFO的进行处理。

配置说明

DRONE_SECRET: 约定与agent的密钥
8000 端口: WEB Service 端口, 用来看部署情况
9909 端口: Drone Server 端口,用来agent连接
DRONE_SERVER: 指定Drone Server的监听端口

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
// run.sh 创建server 与 agent
docker run -d \
-e DRONE_BITBUCKET=true \
-e DRONE_BITBUCKET_CLIENT=Vs4pNdLp4y7CLCEBRs \
-e DRONE_BITBUCKET_SECRET=8zXEkmzfrRKSTbcCJRcpdzkDCWSeeVpH \
-e DRONE_SECRET=41F386 \
-e DRONE_OPEN=true \
-e DRONE_HOST=https://deployment.example.com \
-e DRONE_ADMIN=kimtaek \
-v /home/ec2-user/workspace/drone:/var/lib/drone \
-p 9909:9000 \
-p 9900:8000 \
--restart=always \
--name=drone \
drone/drone:latest

docker run -d \
-e DRONE_SECRET=41F386 \
-e DRONE_SERVER=被部署IP:9909 \
-v /var/run/docker.sock:/var/run/docker.sock \
-v /www:/www \
--restart=always \
--name=agent \
drone/agent:latest

项目Root下的配置文件

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
workspace:
base: /www/
path: bms

clone:
git:
image: plugins/git
depath: 50
tags: true
when:
branch: master

pipeline:
restore-cache:
image: drillster/drone-volume-cache
restore: true
when:
branch: master
mount:
- dist
- node_modules
volumes:
- bms:/cache

build:
image: node:8.3.0
privileged: true
when:
branch: master
commands:
- npm install
- npm run build
- cp -R /www/bms/dist /drone
- find /www/bms/dist ! -newermt `date '+%Y-%m-%d'` | xargs rm -rf
volumes:
- /www/bms:/drone

rebuild-cache:
image: drillster/drone-volume-cache
rebuild: true
when:
branch: master
mount:
- dist
- node_modules
volumes:
- bms:/cache

MySQL change root password

Posted on 2018-05-24

操作环境

OS: Ubuntu 16.04
MySQL: 5.7.22

停止MySQL服务与进入安全模式

1
2
3
4
5
6
7
8
# 停止MySQL服务
service mysql stop

# 进入安全模式,越过表权限和网络
mysqld_safe --skip-grant-tables --skip-networking &

# 越过输入密码进入
mysql -uroot mysql

进入安全模式更新root用户密码

1
2
# 更新新密码
UPDATE mysql.user SET authentication_string=PASSWORD('YOURNEWPASSWORD'), plugin='mysql_native_password' WHERE User='root' AND Host='%';

开启MySQL服务即可用新密码登录

1
2
# 开启MySQL服务
service mysql start

MariaDB: 10.0.34

同上一样,只是用户表中的列名不一样

1
2
# 更新新密码
UPDATE mysql.user set Password=PASSWORD('YOURNEWPASSWORD') WHERE User='root' AND Host='%';

Go dependency management tool - Dep

Posted on 2018-03-17

使用homebrew安装golang

1
brew install go

设置Golang官方默认GOPATH、GOROOT

1
2
export GOPATH=$HOME/go
export GOROOT="/usr/local/Cellar/go/1.10.1/libexec"
  • 安装时的最新版本是 1.10.1
  • 使用 *.pkg安装时GOROOT将是 /usr/local/go
  • 关于更多的环境变量设置请参照 go help gopath

在项目中初始化

1
dep init $HOME/go/src/github.com/kimtaek/socar

  • 在已有项目根目录执行初始化命令时,会分析应用程序所需要(使用)的所有依赖包,得出依赖包清单并生成vendor目录、Gopkg.toml、Gopkg.lock文件

  • 创建项目并执行初始化,会得出空vendor目录、Gopkg.toml、Gopkg.lock文件 (如上例子:创建并初始化)

在项目中添加包

1
2
3
4
5
# 添加指定依赖包的最新版本
dep ensure -add github.com/aws/aws-lambda-go/events

# 添加指定具有特定约束(指定版本)的依赖包
dep ensure -add github.com/aws/aws-lambda-go/events@^1.0.0

升级项目的依赖包至最新版本

1
2
# 将Gopkg.lock中的约定依赖项更新为到最新版本至Gopkg.toml
dep ensure -update

Blocking or allowing IP-addresses in Nginx

Posted on 2018-03-16

Nginx Config

1
2
3
4
5
6
7
8
9
10
11
12
13
14
server {
listen 80;
server_name kimtaek.github.io;
charset utf-8;
client_max_body_size 75M;

location / {
deny 192.168.1.1; # Blocking specific IP
allow 192.168.1.0/24; # Your specific IP
allow 10.1.1.0/16;
allow 2001:0db8::/32;
deny all;
}
}

Use Certbot Let's Encrypt SSL Certificates

Posted on 2018-03-15

使用Certbot 3个月免费SSL Certificates

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
server {
listen 80;
server_name egou.co.kr;
return 301 https://$host$request_uri;
}

server {
listen 443 ssl http2;
server_name egou.co.kr;
access_log /var/log/nginx/access.log vhost;
client_max_body_size 0;

ssl_certificate /etc/letsencrypt/live/egou.co.kr/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/egou.co.kr/privkey.pem;

ssl_prefer_server_ciphers on;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_ciphers ECDHE-RSA-AES256-GCM-SHA384:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-SHA:ECDHE-RSA-RC4-SHA:AES128-GCM-SHA256:HIGH:!RC4:!MD5:!aNULL:!EDH:!CAMELLIA;

ssl_session_cache shared:SSL:10m;
ssl_session_timeout 10m;

add_header Strict-Transport-Security max-age=15638400;

# only used certbot
root /var/www/egou.co.kr/;
location /.well-known/acme-challenge/ {
root /var/www/egou.co.kr/;
}

error_page 497 https://$host:$server_port$request_uri;

location / {
proxy_pass http://172.17.0.4;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header X-Forwarded-Host $http_host;
proxy_read_timeout 90;
proxy_redirect off;
}
}

更新 Certificates

废弃 Certificates

How to change mysql time_zone

Posted on 2018-03-14

System Timezone 确认

1
2
3
date +%Z

// KST
1
2
3
cat /etc/sysconfig/clock

// ZONE=”Asia/Seoul”

System Timezone 设置

1
tzselect
1
ln -sf /usr/share/zoneinfo/Asia/Seoul /etc/localtime

MySQL Timezone 确认

1
2
3
4
mysql> SELECT @@global.time_zone, @@session.time_zone;

// @@global.time_zone | @@session.time_zone
// SYSTEM | SYSTEM
1
2
3
4
5
mysql> show variables like '%time_zone%';

// Variable_name | Value
// system_time_zone | KST
// time_zone | SYSTEM

MySQL Timezone 设置

1
2
3
4
5
mysql> set @@global.time_zone='Asia/Seoul';
mysql> set global time_zone='Asia/Seoul';
mysql> set @@session.time_zone="+09:00";
mysql> set session time_zone ='Asia/Seoul';
mysql> set time_zone = "+09:00";

MySQL Timezone 常用列表

1
2
3
CST
UTC
Asia/Seoul
Kim Taek

Kim Taek

7 posts
11 tags
© 2018 Kim Taek
Powered by Hexo
Theme - NexT.Pisces