1.安装并配置必要的依赖
在 CentOS 7(和 RedHat/Oracle/Scientific Linux 7)上,下面的命令也会在系统防火墙中打开 HTTP、HTTPS 和 SSH 访问。这是一个可选步骤,如果您打算仅从本地网络访问 GitLab,则可以跳过它。
export PATH=/usr/local/bin:$PATH
sudo yum install -y curl policycoreutils-python openssh-server perl
如果没有启用,请启用OpenSSH服务器守护进程: sudo systemctl status sshd
sudo systemctl enable sshd
sudo systemctl start sshd
检查是否需要打开防火墙: sudo systemctl status firewalld
本地虚拟机的话直接关闭:systemctl stop firewalld.service
sudo firewall-cmd --permanent --add-service=http
sudo firewall-cmd --permanent --add-service=https
sudo systemctl reload firewalld
接下来,安装 Postfix 以发送通知电子邮件。如果您想使用其他解决方案发送电子邮件,请跳过此步骤并 在安装 GitLab 后配置外部 SMTP 服务器。
sudo yum install postfix
sudo systemctl enable postfix
sudo systemctl start postfix
2.添加GitLab包仓库并安装包
curl https://packages.gitlab.com/install/repositories/gitlab/gitlab-ee/script.rpm.sh | sudo bash
接下来,安装 GitLab 包。确保您已正确设置 DNS,并更改https://gitlab.example.com (本地安装可以使用ip:port)为您要访问 GitLab 实例的 URL。安装将在该 URL 上自动配置和启动 GitLab。
sudo EXTERNAL_URL="https://10.211.55.10:1010" yum install -y gitlab-ee
如果上面的安装方式下载失败,可以尝试手动安装。去gitlab官网下载rpm安装包
gitlab-ee 企业版 点击下载 938M
gitlab-ce 社区版 点击下载 868M
下载企业版上传到服务器
rpm -i gitlab-ee-14.1.6-ee.0.el7.x86_64.rpm
打开配置文件
vim /etc/gitlab/gitlab.rb
将第32行 external_url "http://10.211.55.10:1010" 修改为指定的地址
运行 sudo gitlab-ctl reconfigure 重新加载配置
获取安装状态
sudo gitlab-ctl status
gitlab-ctl status.png
3.浏览到主机名并登录
获取root用户的密码
cat /etc/gitlab/initial_root_password
# WARNING: This value is valid only in the following conditions
# 1. If provided manually (either via `GITLAB_ROOT_PASSWORD` environment variable or via `gitlab_rails['initial_root_password']` setting in `gitlab.rb`, it was provided before database was seeded for the first time (usually, the first reconfigure run).
# 2. Password hasn't been changed manually, either via UI or via command line.
#
# If the password shown here doesn't work, you must reset the admin password following https://docs.gitlab.com/ee/security/reset_user_password.html#reset-your-root-password.
Password: U4RWnV4d3JecTCwVaoZanXOIjlFHR7E/2ltyXUXw150=
# NOTE: This file will be automatically deleted in the first reconfigure run after 24 hours.
访问是否安装成功(无响应的话,看下防火墙)
http://10.211.55.10:1010/users/sign_in
Username or email: root
Password: 上一步获取到的 Password
gitlab-home.png
安装 gitlab-runner (客户端一般不和gitlab服务端在一台机器)
gitlab 自带安装runner教程
- 先安装
- 绑定项目
- 配置自动流水线 CI/CD
gitlab-runner-expand.png
gitlab-show-runner.png
gitlab-installed.png
下载并安装二进制文件
# Download the binary for your system
sudo curl -L --output /usr/local/bin/gitlab-runner https://gitlab-runner-downloads.s3.amazonaws.com/latest/binaries/gitlab-runner-linux-amd64
# Give it permissions to execute
sudo chmod +x /usr/local/bin/gitlab-runner
# Create a GitLab CI user
创建一个运行gitlab-runner的用户
sudo useradd --comment 'GitLab Runner' --create-home gitlab-runner --shell /bin/bash
# Install and run as service
sudo gitlab-runner install --user=gitlab-runner --working-directory=/home/gitlab-runner
sudo gitlab-runner start
注册运行程序命令(找到自己的实际项目配置)
sudo gitlab-runner register --url http://10.211.55.11:1011/ --registration-token $REGISTRATION_TOKEN
安装过程中,需要输入描述、运行方式。自己熟悉的话,就用 shell,能满足大部分需求
重启一下runner
gitlab-runner start
gitlab-runner restart.png
接下来就可以编写cicd部署脚本了