1. 安装必要的依赖服务
安装postfix邮件服务器
sudo yum install postfix -y
sudo service postfix start
sudo chkconfig postfix on
sudo lokkit -s http -s ssh //如果没有lokkit,可以自己用 yum install lokkit 安装。事实上 lokkit 也只是设定 iptables 把 http 和 ssh 打开,如果原本就有开了也不用执行或手动自己设置 iptables 也可以。
2. 安装gitlab
curl -sS https://packages.gitlab.com/install/repositories/gitlab/gitlab-ce/script.rpm.sh | sudo bash
sudo yum install gitlab-ce -y
国内安装的话可以使用清华的源
新建 /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
再执行
sudo yum makecache
sudo yum install gitlab-ce -y
3. Configure and start GitLab
sudo gitlab-ctl reconfigure
4. 启用https
生成自签名证书
sudo mkdir /etc/gitlab/ssl/
cd ssl
sudo openssl req -newkey rsa:2048 -x509 -nodes -days 3560 -out gitlab.crt -keyout gitlab.key
修改配置,开启https
vi /etc/gitlab/gitlab.rb
修改 external_url
external_url "https://git.abc.com" //有域名用域名,没有域名用ip
nginx['redirect_http_to_https'] = true
nginx['ssl_certificate'] = "/etc/gitlab/ssl/gitlab.crt"
nginx['ssl_certificate_key'] = "/etc/gitlab/ssl/gitlab.key"
sudo gitlab-ctl reconfigure重建配置
使用gitlab-ctl restart来重启所有服务, 即可使用HTTPS访问GitLab了
5. 如果要把ip改成域名,需要改一下几个地方
vi /etc/gitlab/gitlab.rb
external_url "https://git.abc.com" //有域名用域名
server {
listen *:80;
server_name git.abc.com;
server_tokens off; ## Don't show the nginx version number, a security best practice
return 301 https://www.abc.com:443$request_uri; //改成域名
access_log /var/log/gitlab/nginx/gitlab_access.log gitlab_access;
error_log /var/log/gitlab/nginx/gitlab_error.log;
}
vi /var/opt/gitlab/gitlab-rails/etc/gitlab.yml
host:git.abc.com
sudo gitlab-ctl restart
6. 把已有仓库导入到gitlab
sudo cp -r /data/repo/test.git /var/opt/gitlab/git-data/repositories/test-group/test.git
sudo chown -R git:git /var/opt/gitlab/git-data/repositories/test-group/
sudo gitlab-rake gitlab:import:repos
7. 测试通知邮件是否能正常发送
echo "Test mail from postfix" | mail -s "Test Postfix" linxiaofang@pwrd.com
-bash: mail: command not found
yum -y install mailx
8. 克隆项目
首先,生成ssh key
ssh-keygen -t rsa -C "name@mail.com" -b 4096
执行克隆
git clone git@git.abc.com:test-group/test.git
Cloning into 'test'...
warning: You appear to have cloned an empty repository.
git clone https://git.abc.com/test-group/test.git
Cloning into 'test'...
mac: fatal: unable to access 'https://git.abc.com/test-group/test.git/': SSL certificate problem: Invalid certificate chain
解决办法:
git -c http.sslVerify=false clone https://git.abc.com/test-group/test.git
windows:
fatal: unable to access 'https://username:password@git.abc.com/test-grou p/editors.git/': SSL certificate problem: self signed certificate
解决办法:
SourceTree->设置->选项->git->禁用ssl验证
Git Bash->执行git config http.sslVerify false,禁用SSL验证
9.参考
https://docs.gitlab.com/ce/raketasks/import.html
http://samwize.com/2014/07/24/how-to-setup-git-server-gitlab-with-ssl/