Gitlab安装和使用gitlab-runner(一)

简介:

一、
5
本服务器1核2G,不够用 我先加 swap空间

[root@sannian /]# cd /mnt/swap/
[root@sannian swap]# dd if=/dev/zero of=swapfile bs=1M count=9999 
[root@sannian swap]# mkswap swapfile
[root@sannian swap]# swapon swapfile

添加开机自动挂

[root@sannian swap]# vim /etc/fstab 
/mnt/swap/swapfile swap swap defaults 0 0
[root@sannian swap]# top -c
查看

6

设置让系统积极使用swap空间

[root@sannian swap]# echo 100 > /proc/sys/vm/swappiness
[root@sannian swap]# vim /etc/sysctl.conf
加入
vm.swappiness=100

sysctl -p 或者重启生效

[root@sannian swap]# sysctl -p
net.ipv6.conf.all.disable_ipv6 = 1
net.ipv6.conf.default.disable_ipv6 = 1
net.ipv6.conf.lo.disable_ipv6 = 1
vm.swappiness = 0
net.ipv4.neigh.default.gc_stale_time = 120
net.ipv4.conf.all.rp_filter = 0
net.ipv4.conf.default.rp_filter = 0
net.ipv4.conf.default.arp_announce = 2
net.ipv4.conf.lo.arp_announce = 2
net.ipv4.conf.all.arp_announce = 2
net.ipv4.tcp_max_tw_buckets = 5000
net.ipv4.tcp_syncookies = 1
net.ipv4.tcp_max_syn_backlog = 1024
net.ipv4.tcp_synack_retries = 2
kernel.sysrq = 1
vm.swappiness = 100

二、下载安装gitlab
配置yum

[root@sannian swap]# vim /etc/yum.repos.d/gitlab-ce.repo
[gitlab-ce]
name=Gitlab CE Repository
baseurl=https://mirrors.tuna.tsinghua.edu.cn/gitlab-ce/yum/el$releasever/
gpgcheck=0
enabled=1

更新

[root@sannian swap]# yum makecache

安装GitLab社区版

[root@sannian swap]# yum install gitlab-ce      #自动安装最新版
[root@sannian swap]# yum install gitlab-ce-x.x.x    #安装指定版本

GitLab命令
gitlab-ctl start # 启动所有 gitlab 组件;
gitlab-ctl stop # 停止所有 gitlab 组件;
gitlab-ctl restart # 重启所有 gitlab 组件;
gitlab-ctl status # 查看服务状态;
gitlab-ctl reconfigure # 启动服务;
vim /etc/gitlab/gitlab.rb # 修改默认的配置文件;
/opt/gitlab/embedded/service/gitlab-rails/config/gitlab.yml# 修改默认的配置文件;
gitlab-rake gitlab:check SANITIZE=true --trace # 检查gitlab;
gitlab-ctl tail # 查看日志;
运行并启动:

[root@sannian swap]# gitlab-ctl  start
[root@sannian swap]# gitlab-ctl reconfigure//初始化设置

打开 url 47.99.145.156
7

更改端口为9999

[root@sannian embedded]# cd /var/opt/gitlab/nginx/conf/
[root@sannian conf]# vim gitlab-http.conf 
[root@sannian conf]# gitlab-ctl  restart

打开url
47.99.145.156:9999
修改地址

git@gitlab.example.com:front/front-erp.git
[root@sannian conf]# vim /opt/gitlab/embedded/service/gitlab-rails/config/gitlab.yml
[root@sannian conf]# gitlab-ctl restart
[root@sannian opt]# yum -y install git
[root@sannian opt]# git config --global user.name "root"
[root@sannian opt]# git config --global user.email "admin@example.com"
[root@sannian opt]# ssh-keygen -t rsa -C admin@example.com

复制密钥到gitlab上

[root@sannian front-erp]# vim /root/.ssh/id_rsa.pub 
[root@sannian opt]# cd front-erp/
[root@sannian front-erp]# git init
Initialized empty Git repository in /opt/front-erp/.git/
[root@sannian front-erp]# git remote add origin git@47.99.145.156:front/front-erp.git
[root@sannian front-erp]# git add .
[root@sannian front-erp]# git commit -m "commit"
[root@sannian front-erp]# git push -u origin master

8
三、安装gitlab-runner
安装docker

[root@sannian front-erp]# curl -fsSL https://get.docker.com | bash -s docker --mirror Aliyun
配置镜像加速器
针对Docker客户端版本大于 1.10.0 的用户

您可以通过修改daemon配置文件/etc/docker/daemon.json来使用加速器
mkdir -p /etc/docker
tee /etc/docker/daemon.json <<-'EOF'
{
"registry-mirrors": ["https://v2ltjwbg.mirror.aliyuncs.com"]
}
EOF

[root@sannian front-erp]# systemctl daemon-reload
[root@sannian front-erp]# systemctl restart docker
[root@sannian front-erp]# docker search gitlab-runner

下载gitlab-runner

[root@sannian front-erp]# docker pull gitlab/gitlab-runner

运行gitlab-runner

[root@sannian front-erp]# docker images
[root@sannian front-erp]# docker run -d -v /data-ci:/data-ci -v /home:/home --name gitlab-runner gitlab/gitlab-runner 
246408751beaf0baaf0d0231bbdea8d5ec5f3c78f32e723a9f6d2312e8802a74
[root@sannian front-erp]# docker ps
CONTAINER ID        IMAGE                  COMMAND                  CREATED             STATUS              PORTS               NAMES
246408751bea        gitlab/gitlab-runner   "/usr/bin/dumb-init …"   33 seconds ago      Up 31 seconds                           gitlab-runner

9
注册 runner

[root@sannian front-erp]# docker exec -it 246408751bea gitlab-runner --help//帮助
[root@sannian front-erp]# docker exec -it 246408751bea gitlab-runner register
Runtime platform                                    arch=amd64 os=linux pid=20 revision=cf91d5e1 version=11.4.2
Running in system-mode.                            
                                                   
Please enter the gitlab-ci coordinator URL (e.g. https://gitlab.com/):
http://47.99.145.156:9999/
Please enter the gitlab-ci token for this runner:
XFomoe1rfzCPx7e6Ng_y
Please enter the gitlab-ci description for this runner:
[246408751bea]: front-erp-ci
Please enter the gitlab-ci tags for this runner (comma separated):
front-erp-ci
Registering runner... succeeded                     runner=XFomoe1r
Please enter the executor: shell, docker+machine, docker-ssh+machine, kubernetes, docker-ssh, parallels, ssh, virtualbox, docker:
shell
Runner registered successfully. Feel free to start it, but if it's running already the config should be automatically reloaded!

然后查看:

10
四、配置 .gitlab-ci.yml

stages:
  - test
  - deploy

构建开发环境:
  stage: test
  script:
    - /data-ci/front-erp.sh
  only:
    - develop

vim front-erp.sh

#!/bin/sh


#env

        if [[ $CI_BUILD_REF_SLUG == 'develop' ]]; then

                hostlist=""
                if [[ $CI_JOB_STAGE == 'test' ]]; then
                        hostlist="47.99.89.247"
                fi
                if [[ $CI_JOB_STAGE == 'master' ]]; then
                        hostlist="47.99.89.247"
                fi

                projectdir="/work/front/${CI_PROJECT_NAME}"
                for i in $hostlist
                do
                        echo
                        echo 
                        echo "-----------------------------------------------------------------------"
                        echo "发布 主机: $i  项目: $CI_PROJECT_NAME "
                        cd $CI_PROJECT_DIR
                        yarn
                        if [ $? = 0 ];then
                             npm run build
                             echo scp -r $CI_PROJECT_DIR/dist/\* root@${i}:${projectdir}/
                             rsync -avztH --delete $CI_PROJECT_DIR/dist/ root@${i}:${projectdir}/
                        else
                               echo "mvn 构建失败...."
                               exit 100
                        fi

                        echo
                        echo
                done
fi
相关文章
|
3月前
|
缓存 数据安全/隐私保护 Docker
安装gitlab
安装gitlab
140 0
|
6月前
|
Prometheus 监控 Cloud Native
私有仓库Gitlab的安装与汉化
私有仓库Gitlab的安装与汉化
102 0
|
5月前
|
网络安全 开发工具 数据安全/隐私保护
Gitlab的安装
Gitlab的安装
79 0
|
8月前
|
JSON 网络安全 数据安全/隐私保护
gitlab--安装和配置
gitlab--安装和配置
|
4月前
|
存储 网络安全 数据安全/隐私保护
docker 安装gitlab,配置邮件,备份全流程
docker 安装gitlab,配置邮件,备份全流程
127 0
|
17天前
|
Linux 网络安全 开发工具
linux安装gitlab
linux安装gitlab
21 2
|
24天前
|
Devops 开发工具 数据安全/隐私保护
Docker Swarm总结+CI/CD Devops、gitlab、sonarqube以及harbor的安装集成配置(3/5)
Docker Swarm总结+CI/CD Devops、gitlab、sonarqube以及harbor的安装集成配置(3/5)
40 0
|
25天前
|
NoSQL 关系型数据库 MySQL
Docker安装详细步骤及相关环境安装配置(mysql、jdk、redis、自己的私有仓库Gitlab 、C和C++环境以及Nginx服务代理)
Docker安装详细步骤及相关环境安装配置(mysql、jdk、redis、自己的私有仓库Gitlab 、C和C++环境以及Nginx服务代理)
175 0
|
2月前
|
数据安全/隐私保护 Docker 容器
【Docker】安装gitlab 傻瓜式复制安装
【Docker】安装gitlab 傻瓜式复制安装
58 0
|
2月前
|
数据安全/隐私保护 Docker 容器
百度搜索:蓝易云【Docker中gitlab以及gitlab-runner的安装与使用】
现在,你已经成功在Docker中安装和使用了GitLab以及GitLab Runner。祝你使用愉快!
32 1