GitLab_本地GitLab服务器搭建
文章目录
GitLab 是一个用于仓库管理系统的开源项目,使用Git作为代码管理工具,并在此基础上搭建起来的web服务
系统要求
系统:centos7 x86_64 (必须要64位系统,32位系统不能安装gitlab)
内存:4G
硬盘:10G就差不多了,没有要求
Gitlab下载
官网:https://about.gitlab.com/installation/#centos-7
由于官网很慢,故用国内的镜像源:https://mirrors.tuna.tsinghua.edu.cn/gitlab-ce/yum/el7/
目前rpm包最新版本:gitlab-ce-10.5.1-ce.0.el7.x86_64.rpm
安装
官方说明:
1. Install and configure the necessary dependencies
On CentOS 7 (and RedHat/Oracle/Scientific Linux 7), the commands below will also open HTTP and SSH access in the system firewall.
sudo yum install -y curl policycoreutils-python openssh-server
sudo systemctl enable sshd
sudo systemctl start sshd
sudo firewall-cmd --permanent --add-service=http
sudo systemctl reload firewalld
Next, install Postfix to send notification emails. If you want to use another solution to send emails please skip this step and configure an external SMTP server after GitLab has been installed.
sudo yum install postfix
sudo systemctl enable postfix
sudo systemctl start postfix
During Postfix installation a configuration screen may appear. Select ‘Internet Site’ and press enter. Use your server’s external DNS for ‘mail name’ and press enter. If additional screens appear, continue to press enter to accept the defaults.
2. Add the GitLab package repository and install the package
在线安装
Add the GitLab package repository.
curl https://packages.gitlab.com/install/repositories/gitlab/gitlab-ee/script.rpm.sh | sudo bash
Next, install the GitLab package. Change http://gitlab.example.com
to the URL at which you want to access your GitLab instance. Installation will automatically configure and start GitLab at that URL. HTTPS requires additional configuration after installation.
sudo EXTERNAL_URL="http://gitlab.example.com" yum install -y gitlab-ee
离线rpm包安装
由于在线安装很慢,故使用上面下载的rpm包安装
rpm -ivh gitlab-ce-10.5.1-ce.0.el7.x86_64.rpm
3.Configure and start GitLab
sudo gitlab-ctl reconfigure
4.Browse to the hostname and login
On your first visit, you’ll be redirected to a password reset screen to provide the password for the initial administrator account. Enter your desired password and you’ll be redirected back to the login screen. The default account’s username is root. Provide the password you created earlier and login. After login you can change the username if you wish. For configuration and troubleshooting options please see the Omnibus GitLab documentation If you are located in China, try using https://mirror.tuna.tsinghua.edu.cn/help/gitlab-ce/
问题
出现页面502
原因:由于unicorn默认使用的是8080端口,可能有其他程序占用了8080端口。
解决办法:打开/etc/gitlab/gitlab.rb,打开# unicorn[‘port’] = 8080 的注释,将8080修改为9090,保存后运行
sudo gitlab-ctl reconfigure
修改默认80端口
vim /etc/gitlab/gitlab.rb
修改external_url ‘http://localhost:8888’ 保存退出。 刷新配置:
sudo gitlab-ctl reconfigure
如果端口修改后无法访问,请检查防火墙是否关闭。
另附gitlab重启命令(可以不执行)。
sudo gitlab-ctl restart
配置邮件发送
官方说明:https://docs.gitlab.com/omnibus/settings/smtp.html
修改gitlab.rb
sudo vi /etc/gitlab/gitlab.rb
gitlab_rails['smtp_enable'] = true
gitlab_rails['smtp_address'] = "smtp.server"
gitlab_rails['smtp_port'] = 465
gitlab_rails['smtp_user_name'] = "smtp user"
gitlab_rails['smtp_password'] = "smtp password"
gitlab_rails['smtp_domain'] = "example.com"
gitlab_rails['smtp_authentication'] = "login"
gitlab_rails['smtp_enable_starttls_auto'] = true
gitlab_rails['smtp_openssl_verify_mode'] = 'peer'
# If your SMTP server does not like the default 'From: gitlab@localhost' you
# can change the 'From' with this setting.
gitlab_rails['gitlab_email_from'] = 'gitlab@example.com'
gitlab_rails['gitlab_email_reply_to'] = 'noreply@example.com'
SMTP without SSL
gitlab_rails['smtp_enable'] = true;
gitlab_rails['smtp_address'] = 'localhost';
gitlab_rails['smtp_port'] = 25;
gitlab_rails['smtp_domain'] = 'localhost';
gitlab_rails['smtp_tls'] = false;
gitlab_rails['smtp_openssl_verify_mode'] = 'none'
gitlab_rails['smtp_enable_starttls_auto'] = false
gitlab_rails['smtp_ssl'] = false
gitlab_rails['smtp_force_ssl'] = false
修改完,重新配置
sudo gitlab-ctl reconfigure
查看日志
sudo gitlab-ctl tail
日志查看
unicorn日志查看:gitlab-ctl tail unicorn
gitlab日志查看:gitlab-ctl tail
gitlab汉化
停止gitlab
gitlab-ctl stop
查看版本
cat /opt/gitlab/embedded/service/gitlab-rails/VERSION
10.5.1
yum -y install git
克隆获取汉化版本库
git clone https://gitlab.com/xhang/gitlab.git
查看该汉化补丁的版本
cat gitlab/VERSION
10.5.1
打汉化补丁
cd /root/gitlab/
git diff v10.5.1 v10.5.1-zh >/tmp/10.5.1-zh.diff
yum install patch -y
patch -d /opt/gitlab/embedded/service/gitlab-rails -p1 < /tmp/10.5.1-zh.diff
启动gitlab
gitlab-ctl start
重新配置gitlab
gitlab-ctl reconfigure
git仓库迁移
使用git push –mirror命令迁移仓库而不丢失log
先了解一些git的基本参数介绍 git clone –bare
GIT-CLONE(1) Git Manual GIT-CLONE(1)
NAME
git-clone - Clone a repository into a new directory
SYNOPSIS
git clone [--template=<template_directory>]
[-l] [-s] [--no-hardlinks] [-q] [-n] [--bare] [--mirror]
[-o <name>] [-b <name>] [-u <upload-pack>] [--reference <repository>]
[--depth <depth>] [--recursive] [--] <repository> [<directory>]
--bare
Make a bare GIT repository. That is, instead of creating <directory> and placing the administrative files
in <directory>/.git, make the <directory> itself the $GIT_DIR. This obviously implies the -n because there
is nowhere to check out the working tree. Also the branch heads at the remote are copied directly to
corresponding local branch heads, without mapping them to refs/remotes/origin/. When this option is used,
neither remote-tracking branches nor the related configuration variables are created.
git push –mirror
--mirror
Instead of naming each ref to push, specifies that all refs under refs/ (which includes but is not limited
to refs/heads/, refs/remotes/, and refs/tags/) be mirrored to the remote repository. Newly created local
refs will be pushed to the remote end, locally updated refs will be force updated on the remote end, and
deleted refs will be removed from the remote end. This is the default if the configuration option
remote.<remote>.mirror is set.
- 克隆代码库
git clone --bare git://192.168.10.XX/git_repo/project_name.git
- 然后到新的 Git 服务器上创建一个新项目,比如 GitCafe,亦或是本地的私有仓库,如192.168.20.XX
su - git
cd /path/to/path/
mkdir new_project_name.git
git init --bare new_project_name.git
- 以镜像推送的方式上传代码到 GitCafe 服务器上。请确保已经添加了公钥到新的机器上。
cd project_name.git
git push --mirror git@192.168.20.XX/path/to/path/new_project_name.git
- 删除本地代码
cd ..
rm -rf project_name.git
- 到新服务器上找到 Clone 地址,直接Clone到本地就可以了。
git clone git@192.168.20.XX/path/to/path/new_project_name.git
这种方式可以保留原版本库中的所有内容。