为了账号安全,请及时绑定邮箱和手机立即绑定

gitlab部署

标签:
PHP
配置环境

下载官网node二进制安装包
#下载二进制包
cd /usr/local/src/  
wget https://nodejs.org/dist/v8.11.3/node-v8.11.3-linux-x64.tar.xz  

#解压二进制安装包
tar -xvf node-v8.11.3-linux-x64.tar.xz 

#更改文件名
mv node-v8.11.3-linux-x64 node-v8.11.3 

#配置NODE_HOME,进入profile编辑环境变量
vim /etc/profile

#设置nodejs环境变量,在 export PATH USER LOGNAME MAIL HOSTNAME HISTSIZE HISTCONTROL 一行的上面添加如下内容:

#set for nodejs
export NODE_HOME=/usr/local/src/node-v8.11.3
export PATH=$NODE_HOME/bin:$PATH

#编译重启
source /etc/profile
如需php执行gulp命令需填写gulp绝对路径
which gulp
解决 /usr/bin/env: node: No such file or directory(配置软链)
ln -s 'gulp绝对路径' /usr/bin/node

例:ln -s /usr/local/src/node-v8.11.3/bin/node /usr/bin/node
  • 编辑反向代理服务器配置文件
# vi /etc/hosts 文件下写入如下内容:
192.168.16.24   gitlab.example.com

例: cd /usr/local/nginx/conf/vhost #进入nginx配置文件目录
    vi gitlab-runner.conf #新建配置

#gitlab-runner.conf 写入如下内容
server
{
    listen 80;
    server_name gitlab.example.com;
    location / {
        proxy_redirect off;
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_pass http://gitlab.example.com:8080;
    }
    access_log logs/gitlab-example.com.tk_access.log;
}

systemctl restart nginx #重启nginx 
搭建Gitlab CI Runner (作业环境下配置)
下载安装包并设置执行权限(linux安装包)
sudo curl --output /usr/local/bin/gitlab-runner https://gitlab-ci-multi-runner-downloads.s3.amazonaws.com/latest/binaries/gitlab-ci-multi-runner-linux-amd64
给gitlab-runner赋可执行权限
sudo chmod +x /usr/local/bin/gitlab-runner
创建Gitlab CI(gitlab-runner)用户
sudo useradd --comment 'GitLab Runner' --create-home gitlab-runner --shell /bin/bash
注册runner
  • 运行命令 sudo gitlab-runner register

  • 按照如下示例配置

# 填写gitlab ci地址
Please enter the gitlab-ci coordinator URL (e.g. https://gitlab.com )
http://gitlab.example.com:8080/
# 输入您获得的注册Runner的令牌:
Please enter the gitlab-ci token for this runner
GaSz************H1QL

# 输入Runner的描述,你可以稍后在GitLab的UI中进行更改:
Please enter the gitlab-ci description for this runner
[hostame] my-runner

# 输入与Runner关联的标签,稍后可以在GitLab的UI中进行更改:
Please enter the gitlab-ci tags for this runner (comma separated):
my-deploy,another-deploy

# 选择Runner是否应该选择没有标签的作业,可以稍后在GitLab的UI中进行更改(默认为false):
Whether to run untagged jobs [true/false]:
[false]: true


选择是否将Runner锁定到当前项目,稍后可以在GitLab的UI中进行更改。Runner特定时有用(默认为true):

Whether to lock Runner to current project [true/false]:
[true]: true

# 输入Runner执行者:
Please enter the executor: ssh, docker+machine, docker-ssh+machine, kubernetes, docker, parallels, virtualbox, docker-ssh, shell:
shell
安装并启动服务
sudo gitlab-runner install --user=gitlab-runner --working-directory=/home/gitlab-runner
sudo gitlab-runner start
编写一个发布脚本deploy(克隆更新master分支) ,放在/usr/local/bin/目录下
#!/bin/bash
if [ $# -ne 2 ]
then
        echo "arguments error!"
        exit 1
else
        deploy_path="/usr/local/$1/$2"
        if [ ! -d "$deploy_path" ]
        then
                project_path="ssh://git@gitlab.example.com:2222/root/$2.git"
                git clone -b master $project_path $deploy_path
        else
                cd $deploy_path
                git stash && git pull origin master:master
        fi
fi

#添加脚本文件可执行权限chmod +x /usr/local/bin/deploy
ssh公钥添加
1、su gitlab-runner #切换Gitlab CI用户
2、cd /home/gitlab-runner/.ssh #进入ssh
3、将id_rsa.pub 公钥添加到gitlab项目ssh配置中

注:CI作业报 Host key verification failed. 错误解决方案

'删除known_hosts中对应ip的相关rsa信息,手动在服务器执行一次ssh操作。'
点击查看更多内容
TA 点赞

若觉得本文不错,就分享一下吧!

评论

作者其他优质文章

正在加载中
PHP开发工程师
手记
粉丝
104
获赞与收藏
364

关注作者,订阅最新文章

阅读免费教程

  • 推荐
  • 评论
  • 收藏
  • 共同学习,写下你的评论
感谢您的支持,我会继续努力的~
扫码打赏,你说多少就多少
赞赏金额会直接到老师账户
支付方式
打开微信扫一扫,即可进行扫码打赏哦
今天注册有机会得

100积分直接送

付费专栏免费学

大额优惠券免费领

立即参与 放弃机会
意见反馈 帮助中心 APP下载
官方微信

举报

0/150
提交
取消