持续部署工具CDS部署
持续部署工具CDS上手
一、CDS简介
CDS是Go语言开发的企业级持续部署工具和开源的DevOps自动化平台,支持的特性非常的多 CDS部署方式有多种,docker-compose方式,helm安装到kubernetes,二进制安装。这里主要介绍二进制安装方式。 更多关于CDS的知识,可以访问官网CDS
Github仓库地址:https://github.com/ovh/cds
要求: redis postgresql 9.5+
二、安装依赖
1.安装redis
安装redis
1yum -y install epel-release
2yum -y install redis
运行redis
1systemctl enable --now redis
2.安装postgres
1.添加postgres源,CentOS7自带的postgres版本为9.2不满足要求
1yum -y install https://download.postgresql.org/pub/repos/yum/reporpms/EL-7-x86_64/pgdg-redhat-repo-latest.noarch.rpm
2.安装postgres96
1yum -y install postgresql96-server postgresql96
3.初始化postgres并运行
1/usr/pgsql-9.6/bin/postgresql96-setup initdb
2sed -i '/TYPE/ahost all all 0.0.0.0/0 md5' /var/lib/pgsql/9.6/data/pg_hba.conf
3sed -i "/#listen_addresses/alisten_addresses ='*'" /var/lib/pgsql/9.6/data/postgresql.conf
4systemctl enable --now postgresql-9.6
4.创建用户以及数据库
缺换到postgres用户
1su - postgres
2psql
创建cds用户和数据库
1create user cds login password 'cds';
2create database cds owner cds;
三、CDS部署
1.下载二进制文件
从github上下载最新版本的cds
1mkdir $HOME/cds
2cd cds
3
4LAST_RELEASE=$(curl -s https://api.github.com/repos/ovh/cds/releases | grep tag_name | head -n 1 | cut -d '"' -f 4)
5OS=linux # linux, darwin, windows, freebsd, openbsd
6ARCH=amd64 # 386, arm, amd64, arm64, ppc64le
7
8# 从GitHub下载二进制文件
9curl -L https://github.com/ovh/cds/releases/download/$LAST_RELEASE/cds-engine-$OS-$ARCH -o cds-engine
10curl -L https://github.com/ovh/cds/releases/download/$LAST_RELEASE/cdsctl-$OS-$ARCH -o cdsctl
11
12chmod +x cds-engine cdsctl
2.生成配置文件
默认配置文件conf.toml中默认连的redis和数据库都是localhost,数据库默认用户cds,密码cds,数据库名cds,如果不是需要修改配置文件。
1cd $HOME/cds
2./cds-engine config new > conf.toml
3sed -i '/localhost/s@localhost@127.0.0.1@' conf.toml
3.初始化数据库
1cd $HOME/cds
2# 下载sql文件
3./cds-engine download sql --config conf.toml
4# 将sql文件导入到数据库中
5./cds-engine database upgrade --db-host 127.0.0.1 --db-user cds --db-password cds --db-name cds --db-sslmode disable --db-port 5432 --migrate-dir sql
4.运行cds api
1cd $HOME/cds
2# 下载workers
3./cds-engine download workers --config conf.toml
4# 运行api
5./cds-engine start api --config conf.toml
检查服务运行是否正常
1curl http://localhost:8081/mon/version
2{"version":"0.44.0+cds.12344","architecture":"amd64","os":"linux","git_hash":"da180756ef91a2a7b87b3501bc893c6a5e0f8ee1","build_time":"02/06/20-16:24:06","db_migrate":"181"}
3
4curl http://localhost:8081/mon/status
5{"now":"0001-01-01T00:00:00Z","lines":[{"status":"OK","component":"Global/Maintenance","value":"false","type":""},{"status":"AL","component":"Global/Status","value":"3 services","type":""},{"status":"OK","component":"Global/Version","value":"0.44.0+cds.12344","type":""},{"status":"AL","component":"Global/api","value":"2","type":""},{"status":"OK","component":"Global/dbmigrate","value":"0","type":""},{"status":"OK","component":"Global/doc","value":"1","type":""},{"status":"OK","component":"Global/elasticsearch","value":"0","type":""},{"status":"OK","component":"Global/hatchery","value":"0","type":""},{"status":"OK","component":"Global/hooks","value":"0","type":""},{"status":"OK","component":"Global/repositories","value":"0","type":""},{"status":"OK","component":"Global/vcs","value":"0","type":""},{"status":"OK","component":"Version","value":"0.44.0+cds.12344","type":""},{"status":"OK","component":"Uptime","value":"2562047h47m16.854775807s","type":""},{"status":"OK","component":"Time","value":"12h6m2s","type":""},{"status":"OK","component":"Hostname","value":"node0","type":""},{"status":"OK","component":"CDSName","value":"api_musandsadhaw","type":""},{"status":"OK","component":"Nb of Panics","value":"0","type":""},{"status":"OK","component":"Event Broker","value":"⚠ ","type":""},{"status":"OK","component":"Object-Store","value":"Filesystem Storage","type":""},{"status":"AL","component":"SMTP Ping","value":"KO: No SMTP configuration","type":""},{"status":"OK","component":"Database Conns","value":"10","type":""},{"status":"OK","component":"Worker Model Errors","value":"0","type":""},{"status":"OK","component":"Nb of CDS Migrations in progress","value":"0","type":""},{"status":"OK","component":"Version","value":"0.44.0+cds.12344","type":""},{"status":"OK","component":"Uptime","value":"2562047h47m16.854775807s","type":""},{"status":"OK","component":"Time","value":"12h8m34s","type":""},{"status":"OK","component":"Hostname","value":"node0","type":""},{"status":"OK","component":"CDSName","value":"api_upbdij","type":""},{"status":"OK","component":"Nb of Panics","value":"0","type":""},{"status":"OK","component":"Event Broker","value":"⚠ ","type":""},{"status":"OK","component":"Object-Store","value":"Filesystem Storage","type":""},{"status":"AL","component":"SMTP Ping","value":"KO: No SMTP configuration","type":""},{"status":"OK","component":"Database Conns","value":"10","type":""},{"status":"OK","component":"Worker Model Errors","value":"0","type":""},{"status":"OK","component":"Nb of CDS Migrations in progress","value":"0","type":""}]}
能够正常返回数据,则说明api服务运行正常。
5.运行cds ui
1cd $HOME/cds
2./cds-engine download ui --config conf.toml
3./cds-engine start ui --config conf.toml
4
创建管理员账户
密码需要符合复杂度要求
1export INIT_TOKEN=`./cds-engine config init-token --config conf.toml`
2./cdsctl signup --api-url http://localhost:8081 --email admin@localhost.local --username admin --fullname admin
网页访问UI,打开浏览器,访问http://localhost:8080
6.运行本地孵化器
1./cds-engine start hatchery:local --config $HOME/cds/conf.toml
7.关于cds
一次运行所有的服务
1./cds-engine start api ui hooks hatchery:local --config conf.toml
强烈推荐单独运行各个服务
1
2./cds-engine start api --config conf.toml
3
4./cds-engine start ui --config conf.toml
5
6./cds-engine start hooks --config conf.toml
7
8./cds-engine start vcs --config conf.toml
9
10./cds-engine start hatchery:local --config conf.toml
11./cds-engine start hatchery:docker --config conf.toml
12./cds-engine start hatchery:swarm --config conf.toml
13./cds-engine start hatchery:marathon --config conf.toml
14./cds-engine start hatchery:openstack --config conf.toml
15./cds-engine start hatchery:vsphere --config conf.toml
参考
- 原文作者:黄忠德
- 原文链接:https://huangzhongde.cn/post/2020-02-27-start_cds_run_with_binaries/
- 版权声明:本作品采用知识共享署名-非商业性使用-禁止演绎 4.0 国际许可协议进行许可,非商业转载请注明出处(作者,原文链接),商业转载请联系作者获得授权。