在Linux上搭建GitLab的自動化運維涉及多個步驟,以下是一個基本的指南:
sudo apt-get update
sudo apt-get install -y curl openssh-server ca-certificates tzdata
sudo yum install -y curl openssh-server openssh-clients postfix
sudo yum install -y https://download.docker.com/linux/centos/docker-ce.repos
sudo yum install -y docker-ce docker-ce-cli containerd.io
sudo systemctl start docker
sudo systemctl enable docker
sudo ufw allow 80/tcp
sudo ufw allow 443/tcp
sudo ufw enable
sudo systemctl stop firewalld
sudo systemctl disable firewalld
sudo systemctl mask firewalld
sudo yum -y install iptables-services
sudo vi /etc/sysconfig/iptables
# 配置iptables規則
sudo systemctl enable iptables
sudo systemctl restart iptables
sudo rm -rf /etc/localtime
sudo ln -s /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
sudo vi /etc/sysconfig/clock
# 配置時區
sudo timedatectl set-local-rtc 0
sudo hwclock --systohc -u
curl -sS https://packages.gitlab.com/install/repositories/gitlab/gitlab-ce/script.rpm.sh | sudo bash
curl -sS https://packages.gitlab.com/install/repositories/gitlab/gitlab-ce/script.rpm.sh | sudo bash
sudo yum install gitlab-ce
sudo gitlab-ctl reconfigure
sudo gitlab-ctl start
/etc/gitlab/gitlab.rb
文件,設置external_url
為你的服務器IP或域名。external_url 'http://your_server_ip'
/etc/gitlab/gitlab.rb
文件,配置郵件服務。gitlab_rails['gitlab_shell_ssh_port'] = 2222
postfix['smtp_enable'] = "true"
postfix['smtp_address'] = "smtp.example.com"
postfix['smtp_port'] = 587
postfix['smtp_user_name'] = "gitlab"
postfix['smtp_password'] = "your_password"
postfix['smtp_authentication'] = "login"
postfix['smtp_enable_starttls_auto'] = "true"
sudo gitlab-ctl reconfigure
sudo gitlab-ctl restart
docker pull gitlab/gitlab-ce:latest
sudo docker run --detach --hostname gitlab.example.com --publish 443:443 --publish 80:80 --publish 22:22 --name gitlab --restart always --volume GITLAB_HOME/config:/etc/gitlab --volume GITLAB_HOME/logs:/var/log/gitlab --volume GITLAB_HOME/data:/var/opt/gitlab --volume /etc/localtime:/etc/localtime:ro gitlab/gitlab-ce:latest
.gitlab-ci.yml
文件,定義CI/CD管道。stages:
- build
- test
- deploy
build:
stage: build
script:
- echo "Building the application"
test:
stage: test
script:
- echo "Running tests"
deploy:
stage: deploy
script:
- echo "Deploying the application"
通過以上步驟,你可以在Linux上搭建一個基本的GitLab自動化運維環境。根據具體需求,你可以進一步配置和擴展GitLab的功能。