在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的功能。