前期准备

https://mirrors.tuna.tsinghua.edu.cn/ 清华大学镜像源
https://mirrors.tuna.tsinghua.edu.cn/gitlab-ce/yum/el7/gitlab-ce-14.0.0-ce.0.el7.x86_64.rpm
https://mirrors.tuna.tsinghua.edu.cn/gitlab-runner/yum/el7/gitlab-runner-14.4.0-1.x86_64.rpm
https://mirrors.edge.kernel.org/pub/software/scm/git/git-2.34.1.tar.gz
image.png

rpm -ivh 安装

安装git

tar包安装

  1. cd /usr/local/src/
  2. wget https://mirrors.edge.kernel.org/pub/software/scm/git/git-2.34.1.tar.gz
  3. tar -vxf git-2.34.1.tar.xz
  4. cd git-2.34.1
  5. make prefix=/usr/local/git all
  6. make prefix=/usr/local/git install
  7. echo "export PATH=$PATH:/usr/local/git/bin" >> /etc/profile
  8. source /etc/profile
  9. git --version

yum安装(推荐)

  1. #安装源
  2. yum install http://opensource.wandisco.com/centos/7/git/x86_64/wandisco-git-release-7-2.noarch.rpm
  3. #安装git
  4. yum install git
  5. #更新
  6. yum update git

安装gitlabl

image.png
image.png

  1. vim /etc/gitlab/gitlab.rb
  2. #
  3. external_url 'http://192.168.75.95'
  4. gitlab_rails['smtp_enable'] = true
  5. gitlab_rails['smtp_address'] = "smtp.qq.com"
  6. gitlab_rails['smtp_port'] = 465
  7. gitlab_rails['smtp_user_name'] = "1015962444@qq.com"
  8. gitlab_rails['smtp_password'] = "wxaxewsnboxwbfhf"
  9. gitlab_rails['smtp_domain'] = "qq.com"
  10. gitlab_rails['smtp_authentication'] = :login
  11. gitlab_rails['smtp_enable_starttls_auto'] = true
  12. gitlab_rails['smtp_tls'] = true
  13. gitlab_rails['smtp_pool'] = false
  14. gitlab_rails['gitlab_email_from'] = '1015962444@qq.com'

wxaxewsnboxwbfhf
fkghlaiyfbzebcce

配置

  1. gitlab-ctl reconfigure&&gitlab-ctl start

重置密码

  1. gitlab-rake "gitlab:password:reset[root]"
  2. Enter password:
  3. Confirm password:


gitlab常用命令

  1. gitlab-ctl reconfigure #更新配置
  2. gitlab-ctl start #启动全部服务
  3. gitlab-ctl restart #重启全部服务
  4. gitlab-ctl stop #停止全部服务
  5. gitlab-ctl restart nginx #重启单个服务
  6. gitlab-ctl status #查看全部组件的状态
  7. gitlab-ctl show-config #验证配置文件
  8. gitlab-ctl uninstall #删除gitlab(保留数据)
  9. gitlab-ctl cleanse #删除所有数据,重新开始
  10. gitlab-ctl tail <svc_name> #查看服务的日志
  11. gitlab-rails console production #进入控制台,可以修改root的密码

image.png

安装gitlab runner

  1. #安装gitlab-runner
  2. rpm -ivh gitlab-runner-14.4.0-1.x86_64.rpm
  3. systemctl start gitlab-runner
  4. systemctl status gitlab-runner

image.png

注册runner

  1. gitlab-runner register \
  2. --non-interactive \
  3. --executor "shell" \
  4. --url "http://192.168.75.95/" \
  5. --registration-token "yA5s2yv-_2hh6wWg_eex" \
  6. --description "deveops-runner" \
  7. --tag-list "build, deploy" \
  8. --run-untagged="true" \
  9. --locked="false" \
  10. --access-level="not_protected"

设置管理员权限

  1. gitlab-runner用户设置root权限
  2. runner执行过程中大多数是文件夹不存在,无权限。
  3. sudo gitlab-runner uninstall #删除gitlab-runner
  4. gitlab-runner install --working-directory /home/gitlab-runner --user root #安装并设置-user(设置为root)
  5. sudo service gitlab-runner restart #重启gitlab-runner
  6. ps aux| grep gitlab-runner#查看当前 runner用户

image.png

安装sonarqube

  1. docker pull mysql:5.7
  2. docker run -p 3306:3306 --name mysql -v /opt/docker/mysql/conf:/etc/mysql -v /opt/docker/mysql/log:/var/log/mysql -v /opt/docker/mysql/data:/var/lib/mysql -e MYSQL_ROOT_PASSWORD=12345678 -d mysql:5.7
  3. 参数说明
  4. -p 3306:3306 将容器的端口号3306映射到主机的336端口号
  5. -v /opt/docker/mysq1/log:/ar/log/mysql \ 将配置文件夹挂载到主机
  6. -v /opt/docker/mysql/data:/var/lib/mysql \ 将日志文件夹挂载到主机
  7. -v /opt/docker/mysql/conf:/etc/mysql \ 将配置文件夹挂载到主机
  8. -e MYSQL_ROOT_PASSWORD=12345678 \ 初始化root的密码
  9. vim /opt/docker/mysql/conf/my.cnf
  10. [client]
  11. #对本地的msq1客户端的配置
  12. default-character-set = utf8
  13. #对其他远程连接的mysq1客户端的配置
  14. [mysql]
  15. default-character-set = utf8
  16. #本地msq1服务的配置
  17. [mysqld]
  18. init_connect= 'SET collation_connection = utf8_unicode_ci'
  19. init_connect= 'SET NAMES utf8'
  20. character-set-server=utf8
  21. collation-server=utf8_unicode_ci
  22. skip-character-set-client-handshake
  23. skip-name-resove
  24. docker restart mysql
  25. 查看配置文件
  26. 进入mysq1
  27. docker exec -it mysql /bin/bash
  28. cat /etc/mysql/my.cnf

创建sonar的用户

  1. create user 'sonar'@'%' identified by '12345678';
  2. grant all privileges on *.* to 'sonar'@'%' with grant option;
  3. flush privileges;


sonarqube汉化包
https://github.com/xuhuisheng/sonar-l10n-zh/releases

修改sonar的配置

  1. sonar.jdbc.username=sonar
  2. sonar.jdbc.password=12345678
  3. sonar.jdbc..url=jdbc:mysql://192.168.75.95:3306/sonar?useUnicode=true&characterEncoding=utf8&rewriteBatchedStatements=true&Useconfigs=maxPerformance&usessl=false

登录

  1. 默认用户名和密码都是 admin
  2. 配置 token后保留响应
  3. mvn sonar:sonar \
  4. -Dsonar.host.url=http://192.168.75.95:9000 \
  5. -Dsonar.login=08d4b2be0950c9606f46f560f0ocf16bf9d62410

安装sonar-scanner

修改配置

  1. sonar.host.url=http://192.168.75.95:9000
  2. sonar.login=b446601096689e2e25fc1bf96ac681501270799

image.png

gitlab-runner register \
—non-interactive \
—executor “shell” \
—url “http://10.24.42.244/“ \
—registration-token “A2x65BbwShuhPnJVeyVo” \
—description “deveops” \
—tag-list “build, deploy” \
—run-untagged=”true” \
—locked=”false” \
—access-level=”not_protected”

image.png