自己搭建git服务器:linux自己Gitlab服务

github只能保存开源项目,私有项目要收费。

公司的git不想上传个人项目,比如我的博客: 、

个人代码如果本地只是commit ,不上传服务器,还是不安全。

所以想在搭建自己的git服务器(想在与服务器也非常便宜

服务器快速搭建gitlab方法

centos、ununtu、Debian、AlmalLinux 官方镜像

如果是 centos、ununtu、Debian、AlmalLinux 官方镜像,直接参考官方教程安装就好,具体参看官方教程:

安装私有化部署版极狐GitLab

非官方镜像

比如tlinx,虽然是centos的内核,但是无法通过 脚本安装:

curl -fsSL https://packages.gitlab.cn/repository/raw/scripts/setup.sh | /bin/bash

发现脚本内容:

肯定会报:!!! Unsupported OS

手动安装gitlab

选择系统对应的安装包 使用下面的命令手动安装。 比如:清华大学开源软件镜像站

手动下载安装

wget https://mirrors.tuna.tsinghua.edu.cn/gitlab-ce/yum/el7/gitlab-ce-10.0.0-ce.0.el7.x86_64.rpm

下载完成后

rpm -i gitlab-ce-XXX.rpm

启动git服务:

gitlab-ctl reconfigure

第一次访问 GitLab,系统会重定向 url 到重置密码的页面,需要输入初始化管理员账号的密码。 设置完成后,系统会重定向到登录界面,就可以使用刚才输入的密码登录系统了。

系统默认的管理员账号为 root, 登录系统后,可以修改管理员账号为自己喜欢的账号。

yum 安装

配置yum源

vim /etc/yum.repos.d/gitlab-ce.repo

添加下面内容:

[gitlab-ce]
name=gitlab-ce
baseurl=http://mirrors.tuna.tsinghua.edu.cn/gitlab-ce/yum/e16
Repo_gpgcheck=0
Enabled=1
Gpgkey=https://packages.gitlab.com/gpg.key

更新本地yum缓存

yum makecache

安装GitLab社区版

yum intall gitlab-ce        #自动安装最新版
yum install gitlab-ce-x.x.x    #安装指定版本

这么其他依赖:curl policycoreutils openssh-server openssh-clients postfix 无需多说

GitLab常用命令

    gitlab-ctl start # 启动所有 gitlab 组件; gitlab-ctl stop # 停止所有 gitlab 组件; gitlab-ctl restart # 重启所有 gitlab 组件; gitlab-ctl status # 查看服务状态; gitlab-ctl reconfigure # 启动服务; vim /etc/gitlab/gitlab.rb # 修改默认的配置文件; gitlab-rake gitlab:check SANITIZE=true --trace # 检查gitlab; gitlab-ctl tail # 查看日志;

修改GitLab配置

不修改配置,项目地址就会是 git@gitlab.example.com:zhou/zhoulujun.co.git,这个域名肯定得修改

主要修改访问IP和端口,如果有域名可以使用域名,前提域名要解析到该服务器

vim /etc/gitlab/gitlab.rb

查找external_url,改为你自己ip地址

注意:修改完成之后要在防火墙放行你的端口号

firewall-cmd --permanent --add-port=10086/tcp

具体参看:Linux如何打开端口和设置防火墙:firewall-cmd与iptables配置

如果是腾讯云,还要去修改安全组,增加放行端口。

重启githlab

gitlab-ctl reconfigure
gitlab-ctl restart

https://GitLab快速搭建 hcldirgit.github.io/2017/11/04/Git/6.GitLab快速搭建/

CentOS 搭建 GitLab

CentOS 7搭建GitLab

在linux系统(Redhat,CentOS,Ubuntu)上搭建gitlab服务器

经验分享 程序员 微信小程序 职场和发展