安装配置gitlab

来源:互联网 发布:数字油画 知乎 编辑:程序博客网 时间:2024/05/22 02:04

本文档根据官方文档进行整理

1.安装依赖包
yum install curl openssh-server postfix cronie
/etc/init.d/postfix start
chkconfig postfix --level 35 on

2.安装gitlab
curl https://packages.gitlab.com/install/repositories/gitlab/gitlab-ce/script.rpm.sh | sudo bash
yum install gitlab-ce
如果上面方法安装不了,只能下载rpm包安装(在我的百度网盘里面已经下载好了gitlab-ce-8.2.1-ce.0.el6.x86_64.rpm)
https://packages.gitlab.com/gitlab/gitlab-ce?filter=rpms
rpm -ivh gitlab-ce-7.14.3-ce.0.el6.x86_64.rpm

修改配置文件
vim /etc/gitlab/gitlab.rb
修改为内网IP地址
external_url 'http://192.168.20.222'
修改仓库路径
git_data_dir "/data/gitlab/git-data"

创建用户
groupadd git
useradd -g git -s /sbin/nologin -M git

创建目录
mkdir /data/gitlab/git-data
chown -R git.git /data/gitlab/git-data

3.配置和启动gitlab常用命令
gitlab-ctl reconfigure
gitlab-ctl status
gitlab-ctl start
gitlab-ctl stop
gitlab-ctl restart

4.使用下面的账号登录
http://192.168.20.222
Username: root
Password: 5iveL!fe

GITLAB服务器迁移

1.登录到原gitlab服务器备份所有数据
#备份gitlab所有数据
gitlab-rake gitlab:backup:create


2. 登录到新的服务器恢复数据
# 停止相关数据连接服务
gitlab-ctl stop unicorn
gitlab-ctl stop sidekiq

# 从1393513186编号备份中恢复
gitlab-rake gitlab:backup:restore BACKUP=1393513186

# 启动Gitlab
gitlab-ctl start



GIT常用命令

配置GIT
git config --global user.name xxx
git config --global user.email xxx@xxx.com
git config --global color.ui true
git config --global commit.template /root/.gitmessage
git config --global commit.template /root/.gitmessage
vim /root/.gitmessage


克隆代码库
git clone git@gitlab.365ime.com:zhaoruixiong/test1.git

进入代码目录
cd test1

将工作文件修改提交到本地暂存区
git add

将所有修改过的工作文件提交暂存区
git add .

从版本库中删除文件
git rm file2

提交到本地仓库
git commit -m "commit log" -a

查看状态
git status

查看提交日志
git log

将本地主分支推到远程主分支
git push origin master

查看远程服务器地址和仓库名称
git remote -v


查看远程分支
git branch -r

查看各个分支最后提交信息
git branch -v

查看当前分支
git branch

创建分支并切换过去
git checkout -b <new_branch>

基于branch创建新的new_branch
git checkout -b <new_branch> <branch>

切换到某个分支
git checkout <branch>

删除分支
git branch -d branch1

强制删除分支
git branch -D branch1

抓取远程仓库所有分支更新并合并到本地
git pull

创建附注标签
git tag -a v1.0.0 -m "make tag v1.0.0"

删除标签
git tag -d v1.0.0

查看当前分支下的标签
git tag

把标签提交到远程git服务器
git push origin v1.0.0

将本地所有标签一次性提交到git服务器
git push origin --tags



安装gitlab-ci
参考地址 https://gitlab.com/gitlab-org/omnibus-gitlab/blob/master/doc/gitlab-ci/README.md
在另外一台服务器安装gitlab-ci
1.先重复上面安装gitlab的1,2步

2.生成认证的秘钥
admin area-Application-Create a new application
填写http://192.168.20.223/user_sessions/callback
复制Application ID and Secret给下一步的app_id和app_secret用


3.修改配置文件
# external_url '这一行要注释掉'

ci_external_url 'http://192.168.20.223'

# Tell GitLab CI to integrate with gitlab.example.com

gitlab_ci['gitlab_server'] = { 'url' => 'http://192.168.20.222', 'app_id' => "1234", 'app_secret' => 'qwertyuio'}

4. 生成配置
gitlab-ctl reconfigure
yum -y install git

5. 安装runner
wget https://packages.gitlab.com/install/repositories/runner/gitlab-ci-multi-runner/script.rpm.sh
bash script.rpm.sh
yum install gitlab-ci-multi-runner

6. 在项目的跟目录添加yml文件

run_tests:  script:      - /root/a.sh



提交代码到远端


0 0