1.基于docker部署
1.1 安装gitlab
docker run -d \ --hostname gitlab.navysummer.top \ -p 443:443 -p 80:80 -p 222:22 \ --name gitlab \ gitlab/gitlab-ce:latest
gitlab的初始密码在/etc/gitlab/initial_root_password
docker exec -it gitlab cat /etc/gitlab/initial_root_password
1.2 安装gitlab-runner
docker run -d --name gitlab-runner gitlab/gitlab-runner:latest
1.3 注册runer
1.3.1 进入gitlab里,然后进入项目里,找到项目的token
1.3.2 注册项目的runner
docker exec -it gitlab-runner gitlab-ci-multi-runner register
gitlab-ci-multi-runner register:执行注册命令 Please enter the gitlab-ci coordinator URL:输入 ci 地址 Please enter the gitlab-ci token for this runner:输入 ci token Please enter the gitlab-ci description for this runner:输入 runner 名称 Please enter the gitlab-ci tags for this runner:设置 tag Whether to run untagged builds:这里选择 true ,代码上传后会能够直接执行 Whether to lock Runner to current project:直接回车,不用输入任何口令 Please enter the executor:选择 runner 类型,这里我们选择的是 shell
可以在项目的设置的ci/cd里找到这个项目的runner
点击上图框选部分的铅笔可以修改runner
点击save changes就可以保存改变了
1.4 编写.gitlab-ci.yml文件
1.4.1 下载项目添加.gitlab-ci.yml
1.4.2 在gitlab的项目里修改.gitlab-ci.yml,也可以在上一步编写完成直接上传上去
点击下图三个里的任意一个都可以修改
1.4.3 编写.gitlab-ci.yml文件
stages: - .pre - build - test - deploy - clean job1: stage: .pre script: - echo "pre" job2: stage: build script: - echo "build" job3: stage: test script: - echo "test" job4: stage: deploy script: - echo "deploy" job5: stage: clean script: - echo "clean"
1.4.4 查看各个任务执行情况
1.4.5 点击job名称即可查看任务的执行的详细情况
2.服务器部署
2.1 安装gitlab
2.1.1 安装依赖
centos:
yum install firewalld systemd -y # 安装防火墙 systemctl restart firewalld # 重启防火墙 yum install -y curl policycoreutils-python openssh-server # 安装ssh systemctl enable sshd && systemctl start sshd # 设置开机自启并启动sshd服务 yum install postfix -y # 安装邮件服务 systemctl start postfix # 启动邮件服务
ubuntu/deepin:
sudo apt-get install postfix # 安装邮件服务 sudo systemctl restart firewalld # 重启防火墙 sudo apt install openssh-server # 安装ssh sudo systemctl enable sshd && sudo systemctl start sshd # 设置开机自启并启动sshd服务
2.1.2 安装gitlab
源地址:https://packages.gitlab.com/gitlab/gitlab-ce
centos:
wget https://packages.gitlab.com/gitlab/gitlab-ce/packages/ol/7/gitlab-ce-14.3.6-ce.0.el7.x86_64.rpm rpm -i gitlab-ce-14.3.6-ce.0.el7.x86_64.rpm vim /etc/gitlab/gitlab.rb
external_url 'gitlab所在服务器的地址或者域名' gitlab_rails['time_zone'] = 'Asia/Shanghai' gitlab_rails['gitlab_email_from'] = 'root帐号的邮箱地址' gitlab_rails['smtp_enable'] = true gitlab_rails['smtp_address'] = "邮箱服务器" gitlab_rails['smtp_port'] = 邮箱端口 gitlab_rails['smtp_user_name'] = "root帐号的邮箱用户名" gitlab_rails['smtp_password'] = "111111" # 客户端授权密码 gitlab_rails['smtp_domain'] = "邮箱域名" gitlab_rails['smtp_authentication'] = "login" gitlab_rails['smtp_enable_starttls_auto'] = true user["git_user_email"] = "用户邮箱地址"
gitlab-ctl reconfigure
ubuntu/deepin
wget https://packages.gitlab.com/gitlab/gitlab-ce/packages/ubuntu/bionic/gitlab-ce_14.3.6-ce.0_amd64.deb sudo dpkg -i gitlab-ce_14.3.6-ce.0_amd64.deb vim /etc/gitlab/gitlab.rb
external_url 'gitlab所在服务器的地址或者域名' gitlab_rails['time_zone'] = 'Asia/Shanghai' gitlab_rails['gitlab_email_from'] = 'root帐号的邮箱地址' gitlab_rails['smtp_enable'] = true gitlab_rails['smtp_address'] = "邮箱服务器" gitlab_rails['smtp_port'] = 邮箱端口 gitlab_rails['smtp_user_name'] = "root帐号的邮箱用户名" gitlab_rails['smtp_password'] = "111111" # 客户端授权密码 gitlab_rails['smtp_domain'] = "邮箱域名" gitlab_rails['smtp_authentication'] = "login" gitlab_rails['smtp_enable_starttls_auto'] = true user["git_user_email"] = "用户邮箱地址"
sudo gitlab-ctl reconfigure
2.1.3 安装gitlab-runner和注册runner
centos:
curl -L https://packages.gitlab.com/install/repositories/runner/gitlab-ci-multi-runner/script.rpm.sh | sudo bash yum install gitlab-runner -y gitlab-runner register
ubuntu/deepin
curl -L https://packages.gitlab.com/install/repositories/runner/gitlab-runner/script.deb.sh | sudo bash sudo apt-get install gitlab-runner -y sudo gitlab-runner register