搭建gitlab-server

安装依赖

yum install -y curl policycoreutils-python openssh-server vim wget firewalld
systemctl enable sshd
systemctl start sshd
systemctl restart firewalld
firewall-cmd --permanent --add-service=http
firewall-cmd --permanent --add-service=https
systemctl reload firewalld

 安装邮箱

yum install postfix
systemctl enable postfix
systemctl start postfix

注意:sudo systemctl start postfix 如果报错

Job for postfix.service failed because the control process exited with error code. See "systemctl status postfix.service" and "journalctl -xe" for details. 

fatal: parameter inet_interfaces: no local interface found for ::1

修改postfix的设置

vim /etc/postfix/main.cf
inet_protocols = all
inet_interfaces = all

下载安装Gitlab包

curl https://packages.gitlab.com/install/repositories/gitlab/gitlab-ce/script.rpm.sh | sudo bash


EXTERNAL_URL="https://gitlab.example.com" yum install -y gitlab-ce-11.11.2-ce.0.el7

备注:这样使用的源是gitlab自己的,在国内访问较慢,测试目的下使用清华大学的源:

 

wget https://mirrors.tuna.tsinghua.edu.cn/gitlab-ce/yum/el7/gitlab-ce-11.11.2-ce.0.el7.x86_64.rpm


rpm -ivh gitlab-ce-11.11.2-ce.0.el7.x86_64.rpm

修改配置

vim /etc/gitlab/gitlab.rb
#修改配置项
external_url:http://本机ip

重新加载配置服务;

gitlab-ctl reconfigure

 重启gitlab

gitlab-ctl restart

 搭建gitlab-runner

下载gitlab-runner rpm包

curl -LJO https://gitlab-runner-downloads.s3.amazonaws.com/latest/rpm/gitlab-runner_amd64.rpm
rpm -i gitlab-runner_amd64.rpm


报错:

warning: gitlab-runner_amd64.rpm: Header V4 RSA/SHA512 Signature, key ID 880721d4: NOKEY

error: Failed dependencies:

git is needed by gitlab-runner-13.2.2-1.x86_64

 

解决方法:

yum install -y git

 

将gitlab-runner注册到gitlab-server上

gitlab-runner register

 查看gitlab-runner列表

gitlab-runner list

 下载docker 二进制包

wget https://download.docker.com/linux/static/stable/x86_64/docker-18.09.6.tgz

 解压docker包

tar -xvf docker-18.09.6.tgz
mv docker/* /usr/bin/

 配置docker的配置文件

vim /etc/systemd/system/docker.service
[Unit]
Description=Docker Application Container Engine
Documentation=http://docs.docker.io


[Service]
WorkingDirectory=/data/docker
Environment="PATH=/bin:/sbin:/usr/bin:/usr/sbin"
ExecStart=/usr/bin/dockerd
ExecReload=/bin/kill -s HUP $MAINPID
Restart=on-failure
RestartSec=5
LimitNOFILE=infinity
LimitNPROC=infinity
LimitCORE=infinity
Delegate=yes
KillMode=process


[Install]
WantedBy=multi-user.targe

创建目录

mkdir -p  /etc/docker/
mkdr -p /data/docker/

 配置docker加速源文件

vim /etc/docker/daemon.json
{
    "registry-mirrors": ["https://docker.mirrors.ustc.edu.cn","https://hub-mirror.c.163.com"],
    "insecure-registries": ["docker02:35000"],
    "max-concurrent-downloads": 20,
    "live-restore": true,
    "max-concurrent-uploads": 10,
    "debug": true,
    "data-root": "/data/docker/data",
    "exec-root": "/data/docker/exec",
    "log-opts": {
      "max-size": "100m",
      "max-file": "5"
    }
}

 启动docker服务

systemctl daemon-reload && systemctl restart docker && systemctl status docker

 测试gitlab-runner是否好用

 

构建过程中报错:

错误1:

We trust you have received the usual lecture from the local System

Administrator. It usually boils down to these three things:

   #1) Respect the privacy of others.

   #2) Think before you type.

   #3) With great power comes great responsibility.

sudo: no tty present and no askpass program specified

解决方法:

vim /etc/sudoers
gitlab-runner ALL=(ALL) ALL

 

错误2:

Got permission denied while trying to connect to the Docker daemon socket at unix:///var/run/docker.sock: Get http://%2Fvar%2Frun%2Fdocker.sock/v1.39/images/json: dial unix /var/run/docker.sock: connect: permission denied

find / -name docker.sock
路径在: /run/docker.sock

 Docker设置权限下放改普通用户

chmod a+rw /run/docker.sock