CAPTAINS - CI&CD
type: channel
link: https://www.captains.top/index.php/category/CI-CD/
description: 持续集成 持续开发
items: SONARQUBE 之PDF报告生成
items: SONARQUBE 基于postgresql裸机安装
items: sonar基于docker-compose安装
items: Jenkins基于centos部署
items: GITLAB 备份与恢复
items: GITLAB 部署之物理服务器
items: GIT使用

SONARQUBE 之PDF报告生成
type: item
date: 2021-08-23T06:48:00+00:00
description: 1、本次sonarqube检测报告生成基于sonarqube-8.9.1-community2、插件下载路径：https://gitee.com/zzulj/sonar-pdf-plugin需要编译根据开发者要求编译3、配置sonarqube4、配置jenkins略

SONARQUBE 基于postgresql裸机安装
type: item
date: 2021-08-13T07:07:00+00:00
description: SONARQUBE 基于postgresql裸机安装1、系统要求1.1、服务器配置要求1.2、系统参数配置2、postgresql2.1、postgresql源配置3、sonar安装3.1、创建用户3.2、导入安装包3.3、修改配置3.4、启动3.5、查看日志3.6、访问SONARQUBE 基于postgresql裸机安装1、系统要求1.1、服务器配置要求centos7cpu：2内存：8G存储：20G以上1.2、系统参数配置资源限制$ vim /etc/security/limits.conf * soft nofile 65535 * hard nofile 65535 * hard nproc 4096 * soft nproc 4096内核参数配置$ vim /etc/sysctl.conf vm.max_map_count=262144 fs.file-max=65535 net.ipv4.ip_forward = 12、postgresql2.1、postgresql源配置参考官网地址https://www.postgresql.org/download/linux/redhat/配置# Install the repository RPM: sudo yum install -y https://download.postgresql.org/pub/repos/yum/reporpms/EL-7-x86_64/pgdg-redhat-repo-latest.noarch.rpm # Install PostgreSQL: sudo yum install -y postgresql12-server # Optionally initialize the database and enable automatic start: sudo /usr/pgsql-12/bin/postgresql-12-setup initdb sudo systemctl enable postgresql-12 sudo systemctl start postgresql-12修改postgresql配置# 修改监听地址及端口 $ /var/lib/pgsql/12/data $ vim postgresql.conf 60 listen_addresses = '0.0.0.0' # what IP address(es) to listen on; 61 # comma-separated list of addresses; 62 # defaults to 'localhost'; use '*' for all 63 # (change requires restart) 64 port = 5432 # (change requires restart) # 重启postgresql $ systemctl restart postgresql-12.service创建sonar库# 切换postgres用户 $ su - postgres # 登陆 -bash-4.2$ psql -U postgres psql (12.8) Type "help" for help. # 创建数据库并进行授权普通用户访问 postgres=# CREATE DATABASE sonar; # 创建数据库 CREATE DATABASE postgres=# CREATE USER sonar WITH ENCRYPTED PASSWORD '1qaz@WSX'; # 创建数据库 CREATE ROLE postgres=# GRANT ALL PRIVILEGES ON DATABASE sonar TO sonar; # 授权用户 GRANT postgres=# ALTER DATABASE sonar OWNER TO sonar; # 执行变更 ALTER DATABASE postgres=# \q开启远程访问$ pwd /var/lib/pgsql/12/data $ vim pg_hba.conf 83 # "local" is for Unix domain socket connections only 84 local all all peer 85 local all postgres peer 86 # IPv4 local connections: 87 host all all 0.0.0.0/0 md5 88 # IPv6 local connections: 89 host all all ::1/128 md5 90 # Allow replication connections from l…

sonar基于docker-compose安装
type: item
date: 2021-08-13T07:02:00+00:00
description: sonar基于docker-compose安装1、环境准备2、系统及内核参数配置3、安装docker4、安装docker-compose5、创建sonar数据目录6、启动sonar基于docker-compose安装1、环境准备centos7cpu：2内存：8G磁盘：20G以上2、系统及内核参数配置# 内核参数优化 $ vim /etc/sysctl.conf vm.max_map_count=262144 fs.file-max=65535 net.ipv4.ip_forward = 1 $ sysctl -p # 资源限制 $ vim /etc/security/limits.conf * soft nofile 65535 * hard nofile 65535 * hard nproc 4096 * soft nproc 40963、安装docker略，参照阿里云https://developer.aliyun.com/mirror/docker-ce?spm=a2c6h.13651102.0.0.3e221b11WzR3944、安装docker-compose在线安装$ sudo yum install epel-release -y $ sudo yum install docker-compose -y5、创建sonar数据目录创建sonar数据目录$ mkdir /hdata/sonarqube_data/{data,extensions,logs} -pv创建postgresql数据目录$ mkdir /hdata/postgresql/{postgresql,postgresql_data} -pv6、书写docker-compose文件参照官网文档，提供yaml文件https://docs.sonarqube.org/8.9/setup/install-server/本次部署yaml文件内容$ cd /hdata # 创建docker network sonar $ sudo docker network create --subnet=172.20.0.0/16 sonar # 编写docker-compose文件 $ vim docker-compose.yaml version: "3" networks: sonar: external: name: sonar services: sonarqube: image: sonarqube:8.9.2-community networks: sonar: ipv4_address: 172.20.0.11 depends_on: - db environment: SONAR_JDBC_URL: jdbc:postgresql://172.20.0.12:5432/sonar SONAR_JDBC_USERNAME: sonar SONAR_JDBC_PASSWORD: sonar volumes: - /hdata/sonarqube_data/data:/opt/sonarqube/data - /hdata/sonarqube_data/extensions:/opt/sonarqube/extensions - /hdata/sonarqube_data/logs:/opt/sonarqube/logs ports: - "9000:9000" db: image: postgres:12 networks: sonar: ipv4_address: 172.20.0.12 ports: - "5432:5432" environment: POSTGRES_USER: sonar POSTGRES_PASSWORD: sonar volumes: - /hdata/postgresql/postgresql:/var/lib/postgresql - /hdata/postgresql/postgresql_data:/var/lib/postgresql/data6、启动启动服务# 必须在yaml文件同目录执行 $ cd /hdata # 此命令会自动从互联网，拉取镜像 $ sudo docker-compose create $ sudo docker-compose start

Jenkins基于centos部署
type: item
date: 2021-07-20T15:59:00+00:00
description: 1. 环境2. 基于rpm包安装2.1 下载rpm包2.2 安装2.3配置插件加速1. 环境centos74Gcpu2c2. 基于rpm包安装2.1 下载rpm包jenkins包wget https://mirrors.tuna.tsinghua.edu.cn/jenkins/redhat-stable/jenkins-2.249.2-1.1.noarch.rpmjdk包# 安装jdk 略2.2 安装安装jenkinsyum localinstall jenkins-2.249.2-1.1.noarch.rpm配置文件# 可修改端口，数据目录等 grep -v "#" /etc/sysconfig/jenkins |grep -v "^$"启动jenkins服务systemctl start jenkins systemctl enable jenkins修改国内地址，初始化加快# 修改地址 为清华源 vim /var/lib/jenkins/hudson.model.UpdateCenter.xml <?xml version='1.1' encoding='UTF-8'?> default https://mirrors.tuna.tsinghua.edu.cn/jenkins/updates/update-center.json 2.3配置插件加速安装nginx# 端口不要跟jenkins冲突设置nginx反向代理vim /etc/nginx/nginx.conf

GITLAB 备份与恢复
type: item
date: 2021-07-20T15:56:00+00:00
description: gitlab.jpggitlab数据备份与恢复1. 停止gitlab数据服务2. 手动备份数据3. 查看要恢复的文件4. 执行恢复5. 启动服务gitlab数据备份与恢复1. 停止gitlab数据服务[root@gitlab ~]# gitlab-ctl stop unicorn ok: down: unicorn: 0s, normally up [root@gitlab ~]# gitlab-ctl stop sidekiq ok: down: sidekiq: 1s, normally up2. 手动备份数据#执行gitlab数据备份 [root@gitlab ~]# gitlab-rake gitlab:backup:create # 备份完成后启动gitlab [root@gitlab ~]# gitlab-ctl start3. 查看要恢复的文件#gitlab数据备份目录，命令备份 [root@gitlab ~]# cd /var/opt/gitlab/backups/ [root@gitlab backups]# ll total 264 -rw------- 1 git git 133120 Sep 15 14:20 1600150852_2020_09_15_12.2.5_gitlab_backup.tar -rw------- 1 git git 133120 Sep 16 15:38 1600241917_2020_09_16_12.2.5_gitlab_backup.tar drwx------ 7 git git 131 Sep 15 14:54 tmp # nginx配置文件 [root@gitlab backups]# ll /var/opt/gitlab/nginx/conf/ total 12 -rw-r--r-- 1 root root 4017 Aug 26 00:27 gitlab-http.conf -rw-r--r-- 1 root root 2978 Aug 26 00:27 nginx.conf -rw-r--r-- 1 root root 603 Aug 26 00:27 nginx-status.conf # gitlab配置文件 [root@gitlab backups]# ll /etc/gitlab/gitlab.rb -rw------- 1 root root 94249 Aug 26 19:33 /etc/gitlab/gitlab.rb # key文件 [root@gitlab backups]# ll /etc/gitlab/gitlab-secrets.json -rw------- 1 root root 15611 Aug 26 19:35 /etc/gitlab/gitlab-secrets.json4. 执行恢复# 恢复数据之前停止服务 [root@gitlab backups]# gitlab-ctl stop unicorn ok: down: unicorn: 0s, normally up [root@gitlab backups]# gitlab-ctl stop sidekiq ok: down: sidekiq: 0s, normally up #恢复数据 命令+linux时间戳_年_月_日_gitkab版本号，一直yes下去 [root@gitlab backups]# gitlab-rake gitlab:backup:restore BACKUP=1600241917_2020_09_16_12.2.55. 启动服务[root@gitlab backups]# gitlab-ctl start sidekiq ok: run: sidekiq: (pid 10475) 0s [root@gitlab backups]# gitlab-ctl start unicorn ok: run: unicorn: (pid 10501) 1s

GITLAB 部署之物理服务器
type: item
date: 2021-07-20T15:54:00+00:00
description: 1. 环境要求2. 安装3. 设置git配置文件4. 生效配置文件5. 修改中文6. 测试gitlab邮件系统7. gitlab相关目录8. 常用的命令1. 环境要求#最小环境centos系统安装依赖环境 yum install vim gcc gcc-c++ wget net-tools lrzsz iotop lsof iotop bash-completion -y yum install curl policycoreutils openssh-server openssh-clients postfix -y2. 安装yum install https://mirrors.tuna.tsinghua.edu.cn/gitlab-ce/yum/el7/gitlab-ce-12.2.5-ce.0.el7.x86_64.rpm -y3. 设置git配置文件vim /etc/gitlab/gitlab.rb # 设置域名 13 external_url 'http://192.168.31.101' # 设置邮件配置 557 gitlab_rails['smtp_enable'] = true 558 gitlab_rails['smtp_address'] = "smtp.qq.com" 559 gitlab_rails['smtp_port'] = 465 560 gitlab_rails['smtp_user_name'] = "xxxxxxx@qq.com" 561 gitlab_rails['smtp_password'] = "xxxxxx" 562 gitlab_rails['smtp_domain'] = "smtp.qq" 563 gitlab_rails['smtp_authentication'] = "login" 564 gitlab_rails['smtp_enable_starttls_auto'] = true 565 gitlab_rails['smtp_tls'] = true 566 gitlab_rails['gitlab_email_from']="xxxxxxx" 567 user["git_user_email"]="xxxxxx"4. 生效配置文件 gitlab-ctl reconfigure5. 修改中文#停止服务 gitlab-ctl stop #下载中文包 https://gitlab.com/xhang/gitlab #备份源英文版 cp -rp /opt/gitlab/embedded/service/gitlab-rails /opt/gitlab-rails.bak #把中文版复制到源文件内 \cp -rf gitlab-vX.Y.Z-zh/* /opt/gitlab/embedded/service/gitlab-rails/ # 配置变量文件 gitlab-ctl reconfigure # 启动gitlab gitlab-ctl start6. 测试gitlab邮件系统# 收到就是成功否则失败，重新配置邮件 [root@gitlab gitlab]# gitlab-rails console -------------------------------------------------------------------------------- GitLab: 12.2.5 (09f8edbc29a) GitLab Shell: 9.3.0 PostgreSQL: 10.9 -------------------------------------------------------------------------------- Loading production environment (Rails 5.2.3) irb(main):001:0> Notify.test_email('xxxxx@163.com','sssss','aaaa').deliver_now7. gitlab相关目录/etc/gitlab #配置文件目录 /run/gitlab #运行pid目录 /opt/gitlab #安装目录 /var/opt/gitlab #数据目录 /var/log/opt/gitlab #日志目录8. 常用的命令#gitlab-ctl gitlab-ctl start #开启 gitlab-ctl stop #停止 gitlab-ctl restart #重启 gitlab-ctl status #状态 gitlab-ctl tail nginx #查看某个组件的日志 gitlab-rake #数据备份

GIT使用
type: item
date: 2021-07-20T15:51:00+00:00
description: 1. 在gitlab上添加git客户端秘钥2. 提交代码3. git常用命令解释1. 在gitlab上添加git客户端秘钥在git客户端创建秘钥[root@jenkins ~]# ssh-keygen Generating public/private rsa key pair. Enter file in which to save the key (/root/.ssh/id_rsa): Created directory '/root/.ssh'. Enter passphrase (empty for no passphrase): Enter same passphrase again: Your identification has been saved in /root/.ssh/id_rsa. Your public key has been saved in /root/.ssh/id_rsa.pub. The key fingerprint is: SHA256:2Eg6rVQRq01/4RRcuo+mJOTLaAWlS+Fpk1MPerJWXfg root@jenkins The key's randomart image is: +---[RSA 2048]----+ | o. o... | | . +o. oo | | . O=+ o+ | | &Oo=ooEo | | o=X* S + | | .+=. . o | | ...o . o . | | .o + o | | .. o . | +----[SHA256]-----+将git秘钥添加到gitlab中ssh密钥[root@jenkins ~]# cat ~/.ssh/id_rsa.pub ssh-rsa [binary] root@jenkins添加密钥测试是否可以克隆项目#安装git工具 yum install git -y #克隆项目 git clone git@192.168.31.101:dataojo/test.git2. 提交代码编辑克隆项目文件vim ./test/index.html AAAAAAA BBBBBBB AAAAAAA提交代码[root@jenkins test]# git config --global user.name "joker" [root@jenkins test]# git config --global user.email 760245899@qq.com [root@jenkins test]# git add index.html [root@jenkins test]# git commit -m "v1" [master b4d275d] v1 1 file changed, 14 insertions(+) [root@jenkins test]# git push warning: push.default is unset; its implicit value is changing in Git 2.0 from 'matching' to 'simple'. To squelch this message and maintain the current behavior after the default changes, use: git config --global push.default matching To squelch this message and adopt the new behavior now, use: git config --global push.default simple See 'git help config' and search for 'push.default' for further information. (the 'simple' mode was introduced in Git 1.7.11. Use the similar mode 'current' instead of 'simple' if you sometimes use older versions of Git) Counting objects: 5, done. Delta compression using up to 2 threads. Compressing objects: 100% (2/2), done. Writing objects: 100% (3/3), 288 bytes | 0 bytes/s, done. Total 3 (delta 0), reused 0 (delta 0) To git@192.168…