分类目录归档:生活

Kong基础

介绍

技术特性适用场景说明
Kong– 基于OpenResty编写
– 高可用
– 易扩展
– 支持Cassandra存储
– 支持PostgreSQL存储
– restfull 方式 管理admin api
– 插件化支持
– 集群中的节点通过gossip协议自动发现其它节点
网关– 官网
– Kong Community Edition (CE)
– Github
– Docs
– Install Kong Community Edition
– Quickstart
– 入门
– FAQS
– Kong插件
konga– 多用户管理
– 管理多个Kong节点
– 电子邮件异常信息通知
– 管理所有Kong Admin API
– 使用快照备份,还原和迁移Kong节点
– 使用运行状况检查监控节点和API状态
– 轻松的数据库集成(MySQL、postgresSQL、MongoDB)
Kong GUI– 官网
– Github
– Doc
Kong dashboard– 基于node.jsKong GUI官方推荐UI管理工具
– Github
kongdash– 支持windows、MacOS、Ubuntu、Fedoradesktop client for Kong Admin API– 官网
– Github
– 下载

基本概念

名称说明
serviceupstream services的抽象。
Service的主要属性是它的URL。
服务与路由相关联(服务可以有许多与之关联的路由)
Route路由是进入Kong的入口点,并为要匹配的请求定义规则,并路由到给定的Service。
Route定义匹配客户端请求的规则。每个Route与一个服务相关联,一个服务可能有多个与之关联的路由。匹配给定路由的每个请求都将代理到其关联的服务。
upstream service这是指位于Kong后面的您自己的API /服务,转发客户端请求。
target
consumerAPI可能没有用户概念,会出现随意调用的情况。为此Kong提供了一种consumer对象(全局共用),如某API启用了key-auth,没有身份的访问者将无法调用该API。
api用于表示上游服务的旧实体。不推荐使用。

安装Kong

先决条件

安装PostgreSQL

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
$ yum -y install https://download.postgresql.org/pub/repos/yum/11/redhat/rhel-7-x86_64/pgdg-centos11-11-2.noarch.rpm
$ yum -y install postgresql11
$ yum -y install postgresql11-server
$ /usr/pgsql-11/bin/postgresql-11-setup initdb
$ systemctl enable postgresql-11
$ systemctl start postgresql-11
$ su – postgres
$ psql
$ CREATE USER kong;
$ CREATE DATABASE kong OWNER kong;
$ alter user kong with encrypted password ‘123456’;
\q
$ find / -name “postgresql.conf”
$ vi /var/lib/pgsql/11/data/postgresql.conf
# 修改 listen_addresses项值设定为“*”
$ find / -name “pg_hba.conf”
$ vi /var/lib/pgsql/11/data/pg_hba.conf
# 添加以下内容
host all all 0.0.0.0/0 md5
$ systemctl restart postgresql-11

CentOS7中RPM方式安装

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
# 下载
$ cd /usr/local
$ wget https://bintray.com/kong/kong-rpm/download_file?file_path=centos/7/kong-1.3.0.el7.amd64.rpm

# 安装
$ yum localinstall kong-1.3.0.el7.amd64.rpm

# 配置kong的配置文件
$ whereis kong
$ cd /etc/kong/
$ cp kong.conf.default kong.conf
##### 内容开始 #####
database = postgres
pg_host = 10.10.1.179
pg_port = 5432
pg_user = kong
pg_password = 123456
pg_database = kong
##### 内容结束 #####

# 初始化kong的数据库
$ kong migrations up -c /etc/kong/kong.conf

# 启动kong
$ kong start -c /etc/kong/kong.conf

# 测试是否安装成功
$ curl -i http://localhost:8001/

kong的默认值

说明
kong默认的代理地址proxy_listen = 0.0.0.0:8000, 0.0.0.0:8443
默认的管理地址admin_listen = 127.0.0.1:8001, 127.0.0.1:8444 ssl

安装kong-dashboard

npm安装

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# 安装npm
$ yum -y install npm

# 安装kong-dashboard
$ npm install -g kong-dashboard

##### 启动kong-dashboard #####
# 查看启动选项的完整列表
$ kong-dashboard start –help
# 启动Kong Dashboard
$ kong-dashboard start –kong-url http://127.0.0.1:8001
# 在自定义端口上启动Kong Dashboard
kong-dashboard start \
–kong-url http://kong:8001 \
–port [port]
# 使用基本身份验证启动Kong Dashboard
kong-dashboard start \
–kong-url http://kong:8001 \
–basic-auth user1=password1 user2=password2
##### 启动kong-dashboard #####

# 访问kong-dashboard
$ curl http://127.0.0.1:8080

Docker安装

1
2
3
4
5
6
7
8
9
10
11
12
13
# 查看启动选项的完整列表
docker run –rm -p 8080:8080 pgbi / kong-dashboard start –help

# 启动Kong Dashboard
$ docker run –rm -p 8080:8080 pgbi / kong-dashboard start –kong-url http:// kong:8001

# 在自定义端口上启动Kong Dashboard
$ docker run –rm -p [port]:8080 pgbi / kong-dashboard start –kong-url http:// kong:8001

# 使用基本身份验证启动Kong Dashboard
$ docker run –rm -p 8080:8080 pgbi / kong-dashboard start \
–kong-url http:// kong:8001
–basic-auth user1 = password1 user2 = password2

安装konga

先决条件

  • 安装node.js 8.0+
  • 安装npm

CentOS7安装

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
##### 安装node.js 8+ ######
$ cd /usr/local
$ wget https://nodejs.org/dist/v10.14.2/node-v10.14.2-linux-x64.tar.xz
$ tar -xJvf node-v10.14.2-linux-x64.tar.xz
$ mv node-v10.14.2-linux-x64 node
$ vi /etc/profile
##### 在末尾处添加如下
export NODEJS_HOME=/usr/local/node
export PATH=$NODEJS_HOME:$PATH
##### 使环境变量生效
$ source /etc/profile
$ node –version
##### 安装bower ######
$ npm install bower -g
$ bower -v
##### 安装gulp ######
$ npm install gulp -g
$ gulp -v
##### 安装grunt ######
$
##### 安装konga ######
$ git clone https://github.com/pantsel/konga.git
$ cd konga
$ npm i

# 启动
$ npm start
$ curl http://localhost:1337

Admin API

节点信息

查询节点信息

1
$ curl http://localhost:8001
字段说明
node_id正在运行的kong节点的uuid,当kong启动时随机生成,每次kong重启时这个uuid都会变
availabel_on_serverkong节点上安装的plugins的名称
enabled_in_clusterkong节点中启用的插件,即在数据库中生成了对应存储表

查询节点状态

1
$ curl http://localhost:8001/status
字段说明
total_requests客户端请求总数
connections_active包括等待连接的活动客户端连接的当前数量
connections_accepted接受的客户端连接的总数
connections_handled处理连接的总数。一般来说,除非达到一定的资源限制,否则参数值与接受值相同
connections_reading当前Kong正在读取请求头的连接数
connections_writingNGINX将响应写入客户端的连接的当前数量
connections_waiting等待请求的空闲客户端连接的当前数量
reachable反映数据库连接状态的布尔值。注意,此标志不反映数据库本身的健康状况。

Service

添加Service

1
2
$ curl -i -X POST http://localhost:8001/services -d “name=test.service” -d “url=http://后端服务域名/api”
$ curl -i -X POST http://localhost:8001/services -d “name=test.service” -d “protocol=http” -d “host=hxonline.hxsd.cn” -d “path=/api”
字段说明
name服务名称
protocol协议:http or https 默认是 http
host后端服务域名
port后端服务端口
path后端服务子路径;没有就填 ‘/‘
retries重试次数:默认 5次
connect_timeout请求后端服务的超时时间:默认60000 ms
write_timeout写超时时间:默认60000 ms
read_timeout读超时时间:默认60000 ms
url后端服务url地址

示例:

1
2
3
4
5
6
7
8
9
10
11
12
13
$ curl -i -X POST \
–url http://localhost:8001/services/ \
–data ‘name=example-service’ \
–data ‘url=http://mockbin.org’
HTTP/1.1 201 Created
Date: Thu, 13 Dec 2018 07:36:57 GMT
Content-Type: application/json; charset=utf-8
Connection: keep-alive
Access-Control-Allow-Origin: *
Server: kong/0.14.1
Content-Length: 259

{“host”:”mockbin.org”,”created_at”:1544704617,”connect_timeout”:60000,”id”:”c7be1fbd-c8dc-42a5-9397-a494514db290″,”protocol”:”http”,”name”:”example-service”,”read_timeout”:60000,”port”:80,”path”:null,”updated_at”:1544704617,”retries”:5,”write_timeout”:60000}

查询所有Service

1
$ curl -i -X GET http://localhost:8001/services

示例:

1
2
3
4
5
6
7
8
9
10
$ curl -i -X GET http://localhost:8001/services/
HTTP/1.1 200 OK
Date: Thu, 13 Dec 2018 07:42:02 GMT
Content-Type: application/json; charset=utf-8
Connection: keep-alive
Access-Control-Allow-Origin: *
Server: kong/0.14.1
Content-Length: 282

{“next”:null,”data”:[{“host”:”mockbin.org”,”created_at”:1544704617,”connect_timeout”:60000,”id”:”c7be1fbd-c8dc-42a5-9397-a494514db290″,”protocol”:”http”,”name”:”example-service”,”read_timeout”:60000,”port”:80,”path”:null,”updated_at”:1544704617,”retries”:5,”write_timeout”:60000}]}

查询某个Service

1
$ curl -i -X GET http://localhost:8001/services/{服务名称 or 服务id}

示例:

1
2
3
4
5
6
7
8
9
10
$ curl -i -X GET http://localhost:8001/services/example-service
HTTP/1.1 200 OK
Date: Thu, 13 Dec 2018 08:02:24 GMT
Content-Type: application/json; charset=utf-8
Connection: keep-alive
Access-Control-Allow-Origin: *
Server: kong/0.14.1
Content-Length: 247

{“host”:”mockbin.org”,”created_at”:1544704617,”connect_timeout”:60000,”id”:”c7be1fbd-c8dc-42a5-9397-a494514db290″,”protocol”:”http”,”name”:”example-service”,”read_timeout”:60000,”port”:80,”updated_at”:1544704617,”retries”:5,”write_timeout”:60000}

获取某个路由下的Service

1
2
$ curl -i -X GET http://localhost:8001/routes/{路由ID}/service
$ curl -i -X GET http://localhost:8001/routes/xxxx-xxx-xxx-xx/service

更新Service

1
$ curl -i -X PUT http://localhost:8001/services/{服务名称或ID} -d “name=test.service” -d “protocol=http” -d “host=hxonline.hxsd.cn” -d “path=/api”

删除Service

1
2
$ curl -i -X DELETE http://localhost:8001/services/{服务名称或ID}
$ curl -i -X DELETE http://localhost:8001/services/test.service

Route

添加Route

1
2
3
4
$ curl -i -X POST –url http://localhost:8001/routes/ \
-d ‘protocols[]=http&protocols[]=https’ \
-d ‘paths=/test’ \
-d ‘service.id=xxx-xxxx-xxxx-xx’

示例:

1
2
3
4
5
6
7
8
9
10
11
12
$ curl -i -X POST \
–url http://localhost:8001/services/example-service/routes \
–data ‘hosts[]=example.com’
HTTP/1.1 201 Created
Date: Thu, 13 Dec 2018 08:06:10 GMT
Content-Type: application/json; charset=utf-8
Connection: keep-alive
Access-Control-Allow-Origin: *
Server: kong/0.14.1
Content-Length: 290

{“created_at”:1544688370,”strip_path”:true,”hosts”:[“example.com”],”preserve_host”:false,”regex_priority”:0,”updated_at”:1544688370,”paths”:null,”service”:{“id”:”c7be1fbd-c8dc-42a5-9397-a494514db290″},”methods”:null,”protocols”:[“http”,”https”],”id”:”076d68f8-47fd-47aa-af48-40e71677aa9c”}

访问接口:

1
2
3
$ curl -i -X GET \
–url http://localhost:8000/ \
–header ‘Host: example.com’

可以在/etc/hostsname中将example.com地址配置为kong所在的机器的地址:

1
10.10.192.35 example.com

然后就可以通过example.com:8000打开http://mockbin.org。

字段是否必填说明
protocols必填协议列表,http、https。设置:protocols[]=http&protocols[]=https
methods半选填
默认是二者都行
接受请求的方法:GET 或 POST ,二者都行。设置 methods[]=GET&methods[]=POST
hosts半选填与此路由匹配的域名列表。例如:example.com。用作form-encode, 设置:hosts[]= Foo.com和hosts[]= BAR.com
paths必填与此路由匹配的路径列表。
例如:/test
strip_path选填
preserve_host选填
service必填与此路由绑定的服务。
设置:service.id=

获取全部Route

1
$ curl -i -X GET http://localhost:8001/routes/

获取某个Route

1
2
# xxx-xxx-xxx 路由ID
$ curl -i -X GET http://localhost:8001/routes/xxx-xxx-xxx

获取某Service下的Route

1
$ curl -i -X GET http://localhost:8001/services/{服务名或服务ID}/routes

更新Route

可以用 PATCH 和 PUT,PATCH可以修改已存在的路由,PUT 如果路由不存在则新建一个。

1
2
3
4
# xxx-xxx-xxx 路由ID
$ curl -i -X PUT http://localhost:8001/routes/xxx-xxx-xxx \
-d ‘protocols[]=http&protocols[]=https’ \
-d ‘paths=test’ \

删除Route

1
2
# xxx-xxx-xxx 路由ID
$ curl -i -X DELETE http://localhost:8001/routes/xxx-xxx-xxx

配置upstream

1
$ curl -X POST http://localhost:8001/upstreams –data “name=helloUpstream”

配置 target

1
$ curl -X POST http://localhost:8001/upstreams/hello/targets –data “target=localhost:3000” –data “weight=100”

配置Consumer

添加Consumer

1
2
3
4
5
6
7
8
# 创建一个consumer
$ curl -X POST \
–data “username=oauthadmin” \
–data “custom_id=personapi” \
http://127.0.0.1:8001/consumers/
# 在key-auth插件中为此consumer生成key
$ curl -X POST \
http://127.0.0.1:8001/consumers/oauthadmin/key-auth

配置插件

为 hello 服务添加50次/秒的限流

1
2
3
$ curl -X POST http://localhost:8001/services/hello/plugins \
–data “name=rate-limiting” \
–data “config.second=50”

为 hello 服务添加 jwt 插件

1
2
$ curl -X POST http://localhost:8001/services/login/plugins \
–data “name=jwt”

将插件安装在路由上

1
2
3
4
5
6
$ curl -X POST http://localhost:8001/routes/{routeId}/plugins \
–data “name=rate-limiting” \
–data “config.second=50”

$ curl -X POST http://localhost:8001/routes/{routeId}/plugins \
–data “name=jwt”

配置Certificates

1
$

kong与Consul集成

您可以通过指定dns_resolver属性(在kong.conf配置文件中)指向Consul服务器(或通过设置KONG_DNS_RESOLVER=环境变量)使Kong与Consul一起使用。 通过这样做,迫使Kong使用Consul来解析upstream_url API 中的主机名地址。 参考

运维

管理kong

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# 查看版本
$ kong version

# 启动
$ kong start -c /etc/kong/kong.conf

# 停止
$ kong stop

# 重新加载
$ kong reload

# 重启
$ kong restart

# 验证配置
$ kong check /etc/kong/kong.conf

# 健康检查
$ kong health

# 初始化数据库配置
$ kong migrations up -c /etc/kong/kong.conf

配置集群

配置健康检查

配置断路器

配置监控

插件

认证

Basic Authentication

JWT

Key Authentication

LDAP Authentication

OAuth 2.0 Authentication

OKTA

Upstream HTTP Basic Authentication

安全

Bot Detection

CORS

IP Restriction

Cleafy plugin for Kong

Kong Spec Expose

Kong Upstream JWT

Signal Sciences

Wallarm

流控

ACL

Rate Limiting

Request Termination

Response Rate Limiting

Kong Response Size Limiting

Kong Service Virtualization

Request Size Limiting

分析和监控

Datadog

Prometheus

Zipkin

Moesif API Insights

SignalFx

日志

TCP、UDP、HTTP、File、Syslog、StatsD、Loggly等

常见问题

附录

数据字典

acls

字段名类型默认值说明
iduuid
consumer_iduuid
grouptext

apis

字段名类型默认值说明
iduuid
nametext
upstream_urltext
preserve_hostbool
created_attimestamp(6)
retriesint25
https_onlybool
http_if_terminatedbool
hoststext
uristext
methodstext
strip_uribool
upstream_connect_timeoutint4
upstream_send_timeoutint4
upstream_read_timeoutint4

basicauth_credentials

字段名类型默认值说明
iduuid
consumer_iduuid
usernametext
passwordtext
created_attimestamp(6)

certificates

id | uuid | | |
cert | text | | |
key | text | | |
created_at | timestamptz | | – |

cluster_events

字段名类型默认值说明
iduuid
node_iduuid
attimestamp(6)
nbftimestamp(6)
expire_attimestamp(6)
channeltext
datatext

consumers

字段名类型默认值说明
iduuid
custom_idtext
usernametext
created_at

hmacauth_credentials

字段名类型默认值说明
iduuid
consumer_iduuid
usernametext
secrettext
created_attimestamp(6)

jwt_secrets

字段名类型默认值说明
iduuid
consumer_iduuid
keytext
secrettext
created_attimestamp(6)
algorithmtext
rsa_public_keytext

keyauth_credentials

字段名类型默认值说明
iduuid
consumer_iduuid
keytext
created_attimestamp(6)

oauth2_authorization_codes

字段名类型默认值说明
iduuid
codetext
authenticated_useridtext
scopetext
created_attimestamp(6)
credential_iduuid
api_iduuid
service_iduuid

oauth2_credentials

字段名类型默认值说明
iduuid
nametext
consumer_id
client_idtext
client_secrettext
redirect_uritext
created_attimestamp(6)

oauth2_tokens

字段名类型默认值说明
iduuid
credential_iduuid
access_tokentext
token_typetext
refresh_tokentext
expires_inint4
authenticated_useridtext
scopetext
created_attimestamp(6)
api_iduuid
service_iduuid

plugins

字段名类型默认值说明
iduuid
nametext
api_iduuid
consumer_iduuid
configjson
enabledbool
created_attimestamp(6)
route_iduuid
service_iduuid

ratelimiting_metrics

字段名类型默认值说明
iduuid
identifiertext
periodtext
period_datetimestamp(6)
valueint4
route_iduuid
service_iduuid

response_ratelimiting_metrics

字段名类型默认值说明
iduuid
identifiertext
periodtext
period_datetimestamp(6)
valueint4
route_iduuid
service_iduuid

routes

字段名类型默认值说明
iduuid
created_attimestamp(6)
updated_attimestamp(6)
protocolstext[]
methodstext[]
hoststext[]
pathstext[]
regex_priorityint8
strip_pathbool
preserve_hostbool
service_iduuid

schema_migrations

字段名类型默认值说明
iduuid
migrationsvarchar(100)[]

services

字段名类型默认值说明
iduuid
created_attimestamp(6)创建时间
updated_attimestamp(6)更新时间
nametextServiceName
retriesint8代理失败时要执行的重试次数。默认值为5。
protocoltext协议。http/https
hosttextThe host of the upstream server
portint8The upstream server port. Defaults to 80
pathtextThe path to be used in requests to the upstream server. Empty by default.
connect_timeoutint8The timeout in milliseconds for establishing a connection to the upstream server. Defaults to 60000.
write_timeoutint8The timeout in milliseconds between two successive write operations for transmitting a request to the upstream server. Defaults to 60000.
read_timeoutint8The timeout in milliseconds between two successive read operations for transmitting a request to the upstream server. Defaults to 60000.

snis

字段名类型默认值说明
iduuid
nametext
certificate_iduuid
created_attimestamp(6)

targets

字段名类型默认值说明
iduuid
targettext
weightint4
upstream_iduuid
created_attimestamp(6)

ttls

字段名类型默认值说明
primary_key_valuetext
primary_uuid_valueuuid
table_nametext
primary_key_nametext
expire_attimestamp(6)

upstreams

字段名类型默认值说明
iduuid
nametext
slotsint4
created_attimestamp(6)
healthchecksjson
hash_ontext
hash_fallbacktext
hash_on_headertext
hash_fallback_headertext
hash_on_cookietext
hash_on_cookie_pathtext

参考

开源

文档

Kong系列

文章

Jenkins那些常用插件

Jenkins插件大师

作为CI/CD的调度中心,Jenkins具有十八般武艺,目前已有1700多个插件,功能强大到似乎有点过分了。本文主要列出平时我们常用的插件。

以下这两个网站是Jenkins所有的插件及说明

Jenkins Plugins https://plugins.jenkins.io

Jinkins Plugins Wiki https://wiki.jenkins.io


Git Parameter

这是一个参数构建扩展,可以在构建的时候选择git的某一个分支来构建服务。

Docker

利用Docker容器动态创建Jenkins Slave。如果有了Kubernetes/Openshift集群,就不需要这个插件了。直接使用下面的Kubernetes插件。
jenkins非root启动的话,为了运行docker需要执行sudo chmod 777 /var/run/docker.sock

Kubernetes

这个插件可以将Jenkins Slave Node动态配置为Kubernetes集群上的pod。

Openshift

这个插件支持调度Openshift的对象,包括触发 BuildConfig、Deployment、Scale up a Deployment,给ImageStream打新的Tag,以及创建新的对象、删除已有对象等。


GitLab

配置Gitlab的相关认证,同时也支持GitLab的Webhook触发。

GitLab Hook

支持GitLab更好的触发。

Gogs WebHook

支持Gogs代码仓库的触发。


Maven

这个插件为Maven 2 / 3项目提供了高级集成功能。

Pyenv Pipeline

方便对python进行项目级别的环境隔离。
jenkins机器上需要安装python、pip、virtualenv

Python

这个插件支持在Jenkins的构建过程中执行Python脚本。

SonarQube Scanner

支持SonarQube的代码扫描。

Ansible

在构建任务中可以执行Ansible任务。

Publish Over SSH

通过SSH拷贝文件到目标机器,同时可以在目标机器上执行脚本

Publish Over SSH

事先要在设置中添加目标机器的访问方式。


Job Generator

定义一个参数化的模板,通过这个模板快速的在 Jenkins 上创建出任务。

Job Generator

Pipeline:Job

添加一个新的Job类型:Pipeline。

Pipeline:Job

Multijob

把多个Job组织起来。

Parameterized Trigger

这是一个扩展型的插件,使各个job连接的时候可以传递一些job相关的信息。

Join

这也是一个触发job的插件,亮点在于它触发job的条件是等待所有当前job的下游的job都完成才会发生。

Build Pipeline

这个插件提供一个构建流水线的视图。同时它提供了一个任务的手动触发器。

Build Pipeline

Build Monitor View

将Jenkins项目以一块看板的形式呈现。

Build Monitor View


JUnit

展示JUnit单元测试报告。

TestNG Results

导出TestNG的测试报告。

JaCoCo

生成测试覆盖率的报告。

Performance

生成性能测试报告
需要在Jenkins机器上安装Taurus(开源负载测试工具和功能测试工具自动化框架)

Performance

Html Publisher

生成报告文档。参考资料:https://www.jianshu.com/p/8fb776f83243

Email Extension

扩展了发送告警邮件的控制力度。可以定义邮件触发器、邮件内容、收件人。

Mailer

每次不稳定的构建都发送邮件通知。
单独发送邮件给对构建造成不良影响的责任人,会从SCM提交者人的信息中,拼出邮箱。

Sounds

这个插件能让Jenkins通过播放声音来发出通知。

Workspace Cleanup

每次build之前删除workspace目录下指定的文件

Workspace Cleanup


Role-based Authorization Strategy 用户角色

给Jenkins用户权限管理添加了角色组。

Matrix Authorization Strategy Plugin

为每个项目设置用户权限

Disk Usage

对Jenkins节点服务器磁盘的监控。

Disk Usage

Monitoring监控

监控Jenkins节点的CPU、系统负载、平均响应时间和内存使用。

Monitoring监控

Backup备份Jenkins

自定义备份Jenkins Home目录。

Backup备份Jenkins

ThinBackup轻量备份Jenkins

轻量备份Jenkins上的配置与Job

ThinBackup轻量备份Jenkins

SCM Sync Configuration

SCM Sync Configuration

预先要在全局配置中设置代码版本控制库的配置,每次创建或更新job配置时都会提示是否同步配置


参考文章
jenkins常用插件汇总
Jenkins插件大全

SVN仓库迁移(将一个仓库从一台机器上上转移到另一台机器上)

No.1 将准备要迁移的仓库导出 命令: svnadmin dump 仓库名 > svn_dump

No.2 在新的服务器上创建心的仓库 命令: svnadmin create SVNROOT

No.3 导入刚导出的文件svn_dump 命令: svnadmin load SVNROOT < svn_dump

// 注意,以上操作会导致所有的配置丢失,比如密码、权限控制等,只要将原有的conf文件覆盖新的就可以了

在整个操作的过程中要注意仓储路径问题,为避免出错,可以使用绝对路径来表示以上内容,仅以No.3 做实例解析

svnadmin load D:\SVNROOT < D:\svn_dump   解析:新的仓储SVNROOT就创建在D盘根目录下,而导出的文件也已将放在了本地的D盘根目录下

网上有提供一种直接将原仓库目录copy到另一台机器上,然后修改apache 的svn路径指向新的地址的做法,我也尝试过一次,发现有丢失信息,具体不详,所以不推荐

还有一个问题,我查看我的原始准备导出的仓库文件大小只有2.2G左右,而使用svnadmin 命令导出后的文件却有5G之多,中间的差别我也不甚了解,所以推荐使用svn的命令导入仓库

docker在dubbo项目中的配置

某些部署方案需要动态指定服务注册的地址。例如,docker bridge网络模式需要指定用于外部网络通信的注册主机IP。Dubbo在启动阶段提供两对系统属性,用于设置外部通信的IP和端口地址。

  • DUBBO_IP_TO_REGISTRY — 注册到注册中心的IP地址
  • DUBBO_PORT_TO_REGISTRY — 注册到注册中心的端口
  • DUBBO_IP_TO_BIND — 监听IP地址
  • DUBBO_PORT_TO_BIND — 监听端口
  1. 以上四种配置是可选的。如果没有配置,Dubbo将自动获得IP和端口。请根据部署方案灵活选择。
  2. Dubbo支持多协议。如果应用程序同时公开多个不同的协议服务,并且需要为每个服务单独指定IP或端口。请分别在上述属性之前添加协议前缀。例如:
  • HESSIAN_DUBBO_PORT_TO_BIND hessian 协议绑定端口
  • DUBBO_DUBBO_PORT_TO_BIND dubbo dubbo协议绑定端口
  • HESSIAN_DUBBO_IP_TO_REGISTRY hessian协议注册IP
  • DUBBO_DUBBO_IP_TO_REGISTRY dubbo协议注册IP
  1. PORT_TO_REGISTRY 或者 IP_TO_REGISTRY不会被用作默认 PORT_TO_BIND or IP_TO_BIND,但反之亦然。
  • 如果设置PORT_TO_REGISTRY=20881 IP_TO_REGISTRY=30.5.97.6,则 PORT_TO_BIND IP_TO_BIND不会受到影响。
  • 如果设置PORT_TO_BIND=20881 IP_TO_BIND=30.5.97.6,则 PORT_TO_REGISTRY=20881 IP_TO_REGISTRY=30.5.97.6 默认为。

dubbo-docker-sample 本地操作过程:

  1. 将项目克隆到本地
git clone git@github.com:dubbo/dubbo-docker-sample.git
cd dubbo-docker-sample
  1. 打包当地的maven
mvn clean install  
  1. 通过docker build构建一个镜像
docker build --no-cache -t dubbo-docker-sample . 

Dockerfile

FROM openjdk:8-jdk-alpine
ADD target/dubbo-docker-sample-0.0.1-SNAPSHOT.jar app.jar
ENV JAVA_OPTS=""
ENTRYPOINT exec java $JAVA_OPTS -jar /app.jar
  1. 从镜像创建和运行容器
# 由于我们使用zk注册中心,首先我们启动zk容器
docker run --name zkserver --restart always -d zookeeper:3.4.9
docker run -e DUBBO_IP_TO_REGISTRY=30.5.97.6 -e DUBBO_PORT_TO_REGISTRY=20881 -p 30.5.97.6:20881:20880 --link zkserver:zkserver -it --rm dubbo-docker-sample

假设主机IP为30.5.97.6。
设置提供程序以通过环境变量注册注册中心的IP地址和端口 DUBBO_IP_TO_REGISTRY=30.5.97.6 DUBBO_PORT_TO_REGISTRY=20881
实现端口映射-p 30.5.97.6:20881:20880, 其中 20800 是dubbo自动选择的侦听端口。没有监控IP配置,因此它将监听0.0.0.0(所有IP)。
启动后,提供者的注册地址为 30.5.97.6:20881, 容器的监听地址为: 0.0.0.0:20880

  1. 测试
    另一个主机或容器执行
telnet 30.5.97.6 20881
ls
invoke com.alibaba.dubbo.test.docker.DemoService.hello("world")