cyl的博客

记录所思

使用ubuntu镜像

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
FROM ubuntu

WORKDIR /home

ENV GOPATH /go
ENV PATH /usr/local/go/bin:$GOPATH/bin:$PATH

# 换源
RUN echo "deb http://repo.huaweicloud.com/ubuntu focal main restricted\n\
deb http://repo.huaweicloud.com/ubuntu focal-updates main restricted\n\
deb http://repo.huaweicloud.com/ubuntu focal universe\n\
deb http://repo.huaweicloud.com/ubuntu focal-updates universe\n\
deb http://repo.huaweicloud.com/ubuntu focal multiverse\n\
deb http://repo.huaweicloud.com/ubuntu focal-updates multiverse\n\
deb http://repo.huaweicloud.com/ubuntu focal-backports main restricted universe multiverse\n\
deb http://security.ubuntu.com/ubuntu/ focal-security main restricted\n\
deb http://security.ubuntu.com/ubuntu/ focal-security universe\n\
deb http://security.ubuntu.com/ubuntu/ focal-security multiverse" > /etc/apt/sources.list

# 安装系统软件
RUN apt update && \
apt install -y curl unzip

# 安装 protoc
RUN curl -OL https://ghproxy.com/https://github.com/protocolbuffers/protobuf/releases/download/v3.19.1/protoc-3.19.1-linux-x86_64.zip && \
unzip -o protoc-3.19.1-linux-x86_64.zip -d /usr/local bin/protoc && \
unzip -o protoc-3.19.1-linux-x86_64.zip -d /usr/local 'include/*' && \
rm -f protoc-3.19.1-linux-x86_64.zip

# 安装 go
RUN curl -OL https://studygolang.com/dl/golang/go1.15.15.linux-amd64.tar.gz && \
tar -C /usr/local -xzf go1.15.15.linux-amd64.tar.gz && \
rm -f go1.15.15.linux-amd64.tar.gz

# go 代理 库
RUN go env -w GO111MODULE=on && \
go env -w GOPROXY=https://goproxy.cn,direct && \
go get github.com/golang/protobuf/proto && \
go get github.com/golang/protobuf/protoc-gen-go && \
go get github.com/micro/micro/v3/cmd/protoc-gen-micro && \
go get github.com/micro/micro/v3

CMD ["/bin/bash"]

1. 使用ubuntu镜像安装golang

  • 结果 失败

  • 原因 golang版本低

1
2
3
$ apt install golang-go
$ go version
go version go1.10.4 linux/amd64

2. 使用golang镜像

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
# 创建容器
$ docker run -it -d --name go --network host golang /bin/bash
# 进入容器
$ docker exec -it go /bin/bash

# 换源
$ echo "deb http://repo.huaweicloud.com/debian bullseye main
deb http://repo.huaweicloud.com/debian-security bullseye-security main
deb http://repo.huaweicloud.com/debian bullseye-updates main" > /etc/apt/sources.list
$ apt update
# 安装 unzip
$ apt install -y unzip

# 代理
$ go env -w GO111MODULE=on
$ go env -w GOPROXY=https://goproxy.cn,direct

# 安装 go 库
$ go get github.com/golang/protobuf/proto
$ go get github.com/golang/protobuf/protoc-gen-go
$ go get github.com/micro/micro/v3/cmd/protoc-gen-micro
$ go get github.com/micro/micro/v3

# 安装 protoc
$ curl -OL https://ghproxy.com/https://github.com/protocolbuffers/protobuf/releases/download/v3.19.1/protoc-3.19.1-linux-x86_64.zip
$ unzip -o protoc-3.19.1-linux-x86_64.zip -d /usr/local bin/protoc
$ unzip -o protoc-3.19.1-linux-x86_64.zip -d /usr/local 'include/*'
$ rm -f protoc-3.19.1-linux-x86_64.zip

# 退出
$ exit

# 添加镜像
$ docker commit go micro:v1
# 删除老的容器
$ docker rm -f go

# 添加服务端
$ docker run -d --name micro-server --network host micro:v1 micro server

# 添加客户端
$ docker run -d -it --name micro --network host micro:v1 /bin/bash

# 进入客户端容器
$ docker exec -it micro /bin/bash

1
alias dps='docker ps -a --format "table {{.ID}}\t{{.Names}}\t{{.Image}}\t{{.Status}}\t{{.CreatedAt}}" | sed -r "s| \+[0-9]{4} [A-Z]{3}$||"'

或者下面语句 方便以后次次都有

1
2
echo alias dps=\''docker ps -a --format "table {{.ID}}\t{{.Names}}\t{{.Image}}\t{{.Status}}\t{{.CreatedAt}}" | sed -r "s| \+[0-9]{4} [A-Z]{3}$||"'\' >> ~/.bash_profile
source ~/.bash_profile

jenkins

根据托管网站的webhook通知, 更新本地仓库, 并执行Jenkinsfile命令

  • 本地 ssh证书 上传托管网站
  • 下载对应托管网站的插件
  • 填写仓库地址
  • 生成 webHook密码
  • 托管网站添加 网址webHook密码
  • 测试

docker node

中间过程, 用于生成目标文件

docker nginx

根据配置文件 反向代理每个站点

docker etcd

注册发现 每一个站点自己运行后自己注册自己的服务器信息

docker confd

根据根据模板 按照 etcd 的信息生成 nginx 所需的 conf配置

docker loki

日志代理 记录docker中的实施日志

docker grafana

日志管理 展示loki记录的日志

服务器系统

  • centos

  • Ubuntu

博客本地搭建好后, 就想直接在云服务器跑, 但云服务器系统的选择逼死了强迫症

centos

centos 老牌 精简 软件源老

Ubuntu

Ubuntu 用的人多 软件较新

二者在软件的安装方式, 安装的软件的版本非常不同, 让人心力交瘁.

两边都尝试过后, 选择了用的人多的 Ubuntu 作为操作系统后, 同时也起了使用docker心.

0%