搭建GitLab服务器
GitLab是GitHub的免费私有库替代方案,并且安装与配置都很方便。
GitLab要求最少4GB内存,支持小团队使用没问题,实测2GB内存的VPS基本没法用,开swapfile也不行,动不动就60秒超时。因此4GB内存是必须的。
关于这一点,内存大户主要是Unicorn,基于ruby的http服务器。Unicorn会在启动后预先占用大部分内存,内存会随着使用逐渐增长,并且不会释放。根据GitLab和Unicorn的官方文档,这不是它们的锅,那么这个锅可能是ruby和rails了。解决方法是unicorn-work-kill,会根据请求次数和内存占用自动重启Unicorn。Omnibus版的GitLab是默认开启的。
GitLab分为社区版和企业版,在未付费的情况下,两者的功能是一样的。并且社区版整合了CI/CD,因此可以满足绝大部分的开发需求。
安装包主要包括Omnibus整合包,Docker、AWS等的云镜像,以及一些第三方维护的版本。其中Omnibus直接整合了所有服务端组件,适合自用和练手。
安装以Omnibus整合包为例,操作系统为Ubuntu16.04。
Gitlab需要 curl,openSSH 和 ca-certificates 这几个组件:
不过服务器系统一般自带,所以是可选的。
邮件服务,用于GitLab发送找回密码的邮件:
不过如果服务器没有域名的话,大部分邮箱会拒收邮件,而管理员帐号可以直接重置其他账号的密码,所以是可选的。
官方提供的脚本:
这个脚本会自动添加源到apt 的source list,以及安全key。另外,如果自己服务器在国内,脚本会自动添加清华的镜像,速度还行。
先更新apt缓存:
推荐使用 apt 而不是 apt-get ,前者大多数情况下更简单一点。
然后是安装:
其中 EXTERNAL_URL ,改成自己的域名。没有域名的话,可以直接设置成IP的形式: ,这个推测跟nginx服务以及GitLab中的项目地址有关,所以最好正确设置。当然也可以之后在配置文件里更改。
安装完成后,可以在配置文件中修改配置 /etc/gitlab/gitlab.rb 。
比如之前的 EXTERNAL_URL :
官方还有一个关于 unicorn 的优化建议:
默认值是2,如果服务器只用于GitLab的话,官方建议是CPU核心数加一,可以提高服务器的响应速度。不过如果内存只有4G,或者服务器同时承载其他服务,就不要改了,以免内存不足。另外,这个参数最小值是2,设为1,服务器可能会卡死。
配置完成后,刷新配置:
每次修改完 gitlab.rb ,都要刷新配置。
如果没有报错的话,GitLab就配置完毕并且正常运行了。接下来可以打开浏览器开始访问了。
如何搭建linux git服务器
首先我们分别在Git服务器和客户机中安装Git服务程序(刚刚实验安装过就不用安装了):
[root@linuxprobe ~]# yum install gitLoaded plugins: langpacks, product-id, subscription-manager
This system is not registered to Red Hat Subscription Management. You can use subscription-manager to register.
Package git-1.8.3.1-4.el7.x86_64 already installed and latest version
Nothing to do
然后创建Git版本仓库,一般规范的方式要以.git为后缀:
[root@linuxprobe ~]# mkdir linuxprobe.git修改Git版本仓库的所有者与所有组:
[root@linuxprobe ~]# chown -Rf git:git linuxprobe.git/初始化Git版本仓库:
[root@linuxprobe ~]# cd linuxprobe.git/ [root@linuxprobe linuxprobe.git]# git --bare initInitialized empty Git repository in /root/linuxprobe.git/
其实此时你的Git服务器就已经部署好了,但用户还不能向你推送数据,也不能克隆你的Git版本仓库,因为我们要在服务器上开放至少一种支持Git的协议,比如HTTP/HTTPS/SSH等,现在用的最多的就是HTTPS和SSH,我们切换至Git客户机来生成SSH密钥:
[root@linuxprobe ~]# ssh-keygenGenerating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa):
Created directory \'/root/.ssh\'.
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /root/.ssh/id_rsa.
Your public key has been saved in /root/.ssh/id_rsa.pub.
The key fingerprint is:
65:4a:53:0d:4f:ee:49:4f:94:24:82:16:7a:dd:1f:28 root@linuxprobe.com
The key\'s randomart image is:
+--[ RSA 2048]----+
| .o+oo.o. |
| .oo *.+. |
| ..+ E * o |
| o = + = . |
| S o o |
| |
| |
| |
| |
+-----------------+
将客户机的公钥传递给Git服务器:
[root@linuxprobe ~]# ssh-copy-id 192.168.10.10root@192.168.10.10\'s password:
Number of key(s) added: 1
Now try logging into the machine, with: \"ssh \'192.168.10.10\'\"
and check to make sure that only the key(s) you wanted were added.
此时就已经可以从Git服务器中克隆版本仓库了(此时目录内没有文件是正常的):
[root@linuxprobe ~]# git clone root@192.168.10.10:/root/linuxprobe.gitCloning into \'linuxprobe\'...
warning: You appear to have cloned an empty repository.
[root@linuxprobe ~]# cd linuxprobe [root@linuxprobe linuxprobe]#初始化下Git工作环境:
[root@linuxprobe ~]# git config --global user.name \"Liu Chuan\" [root@linuxprobe ~]# git config --global user.email \"root@linuxprobe.com\" [root@linuxprobe ~]# git config --global core.editor vim向Git版本仓库中提交一个新文件:
[root@linuxprobe linuxprobe]# echo \"I successfully cloned the Git repository\" readme.txt [root@linuxprobe linuxprobe]# git add readme.txt [root@linuxprobe linuxprobe]# git status# On branch master
#
# Initial commit
#
# Changes to be committed:
# (use \"git rm --cached ...\" to unstage)
#
# new file: readme.txt
#
[root@linuxprobe linuxprobe]# git commit -m \"Clone the Git repository\" [master (root-commit) c3961c9] Clone the Git repositoryCommitter: root
1 file changed, 1 insertion(+)
create mode 100644 readme.txt
[root@linuxprobe linuxprobe]# git status# On branch master
nothing to commit, working directory clean
但是这次的操作还是只将文件提交到了本地的Git版本仓库,并没有推送到远程Git服务器,所以我们来定义下远程的Git服务器吧:
[root@linuxprobe linuxprobe]# git remote add server root@192.168.10.10:/root/linuxprobe.git将文件提交到远程Git服务器吧:
[root@linuxprobe linuxprobe]# git push -u server masterCounting objects: 3, done.
Writing objects: 100% (3/3), 261 bytes | 0 bytes/s, done.
Total 3 (delta 0), reused 0 (delta 0)
To root@192.168.10.10:/root/linuxprobe.git
* [new branch] master - master
Branch master set up to track remote branch master from server.
为了验证真的是推送到了远程的Git服务,你可以换个目录再克隆一份版本仓库(虽然在工作中毫无意义):
[root@linuxprobe linuxprobe]# cd ../Desktop [root@linuxprobe Desktop]# git clone root@192.168.10.10:/root/linuxprobe.gitCloning into \'linuxprobe\'...
remote: Counting objects: 3, done.
remote: Total 3 (delta 0), reused 0 (delta 0)
Receiving objects: 100% (3/3), done.
[root@linuxprobe Desktop]# cd linuxprobe/ [root@linuxprobe linuxprobe]# cat readme.txtI successfully cloned the Git repository
这篇是详细介绍Git的,中间有一部分是怎么去搭建,你可以看下
使用Gitolite搭建Git服务器
Git服务的管理工具,主要有如下几种。
Gitolite 使用perl语言编写,维护和更新比较积极,下面测试使用Gitolite搭建Git服务器。
一般新建用户 ~/.ssh/ 目录是不存在的。
生成路径会在ssh-kengen执行后给出,也可修改。windows下生成路径默认位于 C:/user/用户名/.ssh 下。
此时, gitolite 会初始化两个仓库,同时创建 authorized_keys 文件
管理库中有两个目录, conf/ 和 keydir/ 。
仓库的创建通过编辑 gitolite-admin/conf/gitolite.conf 即可,然后将配置后的文件上传服务器。
若本地已有仓库repo2,将其添加到服务器
gitolite可以通过用户组的方式进行管理
如上提示,需要输入密码。
需要安装 openssh ,并将 gitolite 用户添加在 sshusers 组中,有的服务器可能是 ssh 组。
计算机领域的Cookbook指的是实用经典案例的意思,是对一些普遍性问题的解决方案的总结和整理。
linux如何搭建git
1、环境准备
服务器:CentOS 7.3 + git (1.8.3.1)
客户端:win10 + git (2.17.0.windows.1)
2、服务器安装git
yum install -y git
3、创建git用户,管理 git服务
[root@localhost home]# useradd git [root@localhost home]# passwd git4、服务器创建git 仓库
设置/home/git/repository-git 为git 服务器仓库,然后把 git 仓库的 owner 修改为 git 用户。
复制代码
[root@localhost git]# mkdir repository-git [root@localhost git]# git init --bare repository-git/Initialized empty Git repository in /home/git/repository-gt/
[root@localhost git]# chown -R git:git repository-git/5、客户端安装git
下载 Git for Windows,地址:
安装完之后,可以使用 Git Bash 作为命令行客户端。
5.1、选择一个目录 F:\\project\\sell 作为本地仓库,右键进入Git Bash 命令行模式
初始化本地仓库:git init
5.2、尝试克隆一个服务器的空仓库到本地仓库
git clone git@192.168.116.129:/home/git/repository-gt
第一次连接到目标 Git 服务器时会得到一个提示:
The authenticity of host \'192.168.116.129(192.168.116.129)\' can\'t be established.
RSA key fingerprint is SHA256:Ve6WV/SCA059EqoUOzbFoZdfmMh3B259nigfmvdadqQ.
Are you sure you want to continue connecting (yes/no)?
选择 yes:
Warning: Permanently added \'192.168.116.129\' (RSA) to the list of known hosts.
此时 C:\\Users\\用户名\\.ssh 下会多出一个文件 known_hosts,以后在这台电脑上再次连接目标 Git 服务器时不会再提示上面的语句。
局域网内创建git服务器的简单方法
当资源有限,但是项目同时需要几个人协同开发,我们就需要配置一个简单的局域网内的git服务器,方便协同开发。
首先我们新建远端的git目录,目录名和本地仓库名一致,并且在目录下运行:
git init --bare
一个空的git仓库就建立好了。然后我们需要把本地的仓库和远端的关联起来。具体做法是,在本地git仓库的目录下执行:
git remote add origin ssh://用户名@ip/仓库路径
比如:git remote add origin ssh://android@192.168.31.72/home/android/projects/gitserver/demoproject/。完成后,本地的提交,就可以push到远端啦。比如:
git push origin master
就可以把本地的master推送到远端。协同开发的同事可以通过如下命令获取远端的仓库
git clone ssh://android@192.168.31.72/home/android/projects/gitserver/demoproject/
是不是很简单呢
ps:实际使用过程中发现了一个问题,即本机的ip地址不是静态的。如何解决这个问题呢?可以在每次ip改变以后,重置仓库的origin url:
git remote set-url origin {url}