CentOS6安装gitlab-ce

安装必要依赖:

sudo yum install -y curl policycoreutils-python openssh-server cronie
sudo lokkit -s http -s ssh

安装邮件发送依赖

sudo yum install postfix
sudo service postfix start
sudo chkconfig postfix on

将gitlab-ce加入下载仓库

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

安装gitlab-ce

URL请根据自身设置

sudo EXTERNAL_URL="http://gitlab.adebug.com" yum -y install gitlab-ce

git仓库创建管理

Git global setup

git config --global user.name "你的用户名"
git config --global user.email "你的邮箱"

Create a new repository

git clone git@域名或ID:/仓库目录/empty.git
cd empty
touch README.md
git add README.md
git commit -m "add README"
git push -u origin master

Existing folder

cd existing_folder
git init
git remote add origin git@域名或ID:/仓库目录/empty.git
git add .
git commit -m "Initial commit"
git push -u origin master

Existing Git repository

cd existing_repo
git remote add origin git@gitlab.66580.cn:ziyo/empty.git
git push -u origin --all
git push -u origin --tagsc

仓库服务端初始化

$ cd /gitrepo
$ chown git:git gitrepo/

$ git init --bare 你的仓库项目名.git \
Initialized empty Git repository in /gitrepo/你的仓库项目名.git/

$ chown -R git:git 你的仓库项目名.git

利用hooks进行自动部署

生成sshkey

ssh-keygen -t rsa -C "admin@adebug.com"

会提示保存在什么目录下(一般在/var/opt/gitlab/.ssh/),得到两个文件:id_rsa和id_rsa.pub。注意该目录权限权限应改为700

创建公钥配对目录及文件,并将生成的公钥id_rsa.pub内容加到authorized_keys中

cd /home
mkdir -p git/.ssh/
cd git/.ssh
touch authorized_keys
chown -R git:git /home/git
chmod 600 authorized_keys
cat ~/.ssh/id_rsa.pub >> authorized_keysz

到代码仓库目录下加入post-receiv,下面目录根据自身情况切换

cd /gitrepo/test.git/hooks/
touch post-receive

文件内容为

#!/bin/sh
export LANG=zh_CN.UTF-8
unset GIT_DIR
cd /home/wwwroot/test #你服务器上发布的项目目录
git pull origin master

服务器上的项目目录需要加入到git组中,否则有权限问题

chown -R git:git /home/wwwroot/test

 

注意,如果配置了git协议拉取仓库依然需要密码,请参考:【ssh免密登录配置无效失败原因的汇总分析】_莫冲的博客-CSDN博客_ssh免密登录失败