做为专业程序员,必需要有学习网络!加速学习之路!php
须要的在这里:学习网络linux
lsb_release -a
本笔记系统环境:git
LSB Version: :core-4.1-amd64:core-4.1-noarch Distributor ID: CentOS Description: CentOS Linux release 7.5.1804 (Core) Release: 7.5.1804 Codename: Core
# 执行 git --version
# 显示老版本 git version 1.8.1
yum install curl-devel expat-devel gettext-devel openssl-devel zlib-devel asciidoc yum install gcc perl-ExtUtils-MakeMaker
yum remove git
git 官网程序员
cd /usr/local/src/ wget https://www.kernel.org/pub/software/scm/git/git-2.9.5.tar.xz tar -vxf git-2.9.5.tar.xz cd git-2.9.5
# 编译时发生错误,可能未安装依赖软件包 make prefix=/usr/local/git all make prefix=/usr/local/git install
Root 用户shell
# 添加环境变量 echo "export PATH=$PATH:/usr/local/git/bin" >> /etc/profile # 生效环境变量 source /etc/profile
其余用户,apache
登陆该用户,配置该用户下的环境变量缓存
echo "export PATH=$PATH:/usr/local/git/bin" >> ~/.bashrc source ~/.bashrc
git --version
git version 2.9.5
根据官方文档可快速安装,本文只修了安装
路径,并手动受权。markdown
/gitlab/
为安装路径,gitlab-runner
为执行文件
# sudo wget -O /保存路径 https://网址 sudo wget -O /gitlab/gitlab-runner https://gitlab-runner-downloads.s3.amazonaws.com/latest/binaries/gitlab-runner-linux-amd64
sudo chmod +x /gitlab/gitlab-runner
sudo useradd --comment 'GitLab Runner' --create-home gitlab-runner --shell /bin/bash
# 因为没有设置为全局变量,添加为服务时须要指定绝对路径 # 因为该服务指定用户 gitlab-runner 执行,因此须要给该用户配置相关文件夹权限 # --working-directory 参数为配置缓存地址,可自定义,注意须要文件夹权限 sudo /gitlab/gitlab-runner install --user=gitlab-runner --working-directory=/gitlab/work
/gitlab/work
该目录会生成一些 gitlab-runner
的配置文件,与高速缓存仓库,须要受权权限。
chmod
分配:chmod 777 /gitlab/work/
ps:该权限方案适合快速使用,web 站点目录,都须要权限。
ACL
分配制定用户:# 给用户 gitlab-runner 设置 /gitlab/work 文件夹 rwx 权限 setfacl -m u:gitlab-runner:rwx -R /gitlab/work # 设置后期添加的子目录和文件继承父目录权限 setfacl -m d:u:gitlab-runner:rwx -R /gitlab/work
ps:该方案须要必定的权限分配能力
本文使用 apache
代理网站。
apache
用户添加至 gitlab-runner
组,容许 apache
有权读写 gitlab-runner
生成的文件usermod -a -G 'gitlab-runner' apache
[root@127.0.0.1 /]# usermod -a -G 'gitlab-runner' apache [root@127.0.0.1 /]# id apache uid=48(apache) gid=48(apache) groups=48(apache),1000(gitlab-runner) [root@127.0.0.1 /]# id gitlab-runner uid=1000(gitlab-runner) gid=1000(gitlab-runner) groups=1000(gitlab-runner)
文档很是详细,自行查找
本文使用 shell
常规执行,功能有限,更多高级功能查看官方文档
运行程序
sudo /gitlab/gitlab-runner start
更多功能
使用简单的shell
与git
代码,实现拉取仓库文件至指定位置
# 工做类型标签 stages: # 自定义工做类名称 - 同步 # 自定义工做名 dev: tags: # 注册 gitlab-runner 时填写的机器人标签 - gitlab stage: 同步 script: # 打开目录 - cd /Web # 判断是否存在 .git 文件 true 状态 - if [ ! -d ".git" ];then # 初始化仓库 - git init - else # 已经存在,跳过 git 仓库初始化 - echo 'skip git int' - fi # 执行 git 根据仓库路径拉取文件 - git pull $CI_PROJECT_DIR environment: # 环境名称 name: dev only: # 只有指定分支推送时才执行 - dev