(本人在作业部落上的原文:https://www.zybuluo.com/lovemiffy/note/418758)
本文主要记录在Ubuntu 16.04操作系统中搭建GitLab服务器的操作记录,以下是操作步骤(主要参考资料:https://about.gitlab.com/downloads/#ubuntu1604)。
1.安装依赖包,运行命令
sudo apt-get install curl openssh-server ca-certificates postfix
- 1
执行完成后,出现邮件配置,选择Internet那一项(不带Smarthost的)
2.利用清华大学的镜像(https://mirror.tuna.tsinghua.edu.cn/help/gitlab-ce/)来进行主程序的安装。
首先信任 GitLab 的 GPG 公钥:
curl https://packages.gitlab.com/gpg.key 2> /dev/null | sudo apt-key add - &>/dev/null
- 1
利用root用户1(不是sudo,而是root),vi打开文件/etc/apt/sources.list.d/gitlab-ce.list,加入下面一行:
deb https://mirrors.tuna.tsinghua.edu.cn/gitlab-ce/ubuntu xenial main
- 1
安装 gitlab-ce:
sudo apt-get update sudo apt-get install gitlab-ce
- 1
- 2
3.执行命令
sudo gitlab-ctl reconfigure
- 1
如果报错
================================================================================ Recipe Compile Error in /opt/gitlab/embedded/cookbooks/gitlab/recipes/default.rb ================================================================================ RuntimeError ------------ External URL must include a FQDN Cookbook Trace: --------------- /opt/gitlab/embedded/cookbooks/gitlab/libraries/gitlab.rb:95:in `parse_external_url' /opt/gitlab/embedded/cookbooks/gitlab/libraries/gitlab.rb:191:in `generate_config' /opt/gitlab/embedded/cookbooks/gitlab/recipes/default.rb:34:in `from_file' Relevant File Content: ---------------------- /opt/gitlab/embedded/cookbooks/gitlab/libraries/gitlab.rb: 88: 89: def parse_external_url 90: return unless external_url 91: 92: uri = URI(external_url.to_s) 93: 94: unless uri.host 95>> raise "External URL must include a FQDN" 96: end 97: Gitlab['user']['git_user_email'] ||= "gitlab@#{uri.host}" 98: Gitlab['gitlab_rails']['gitlab_host'] = uri.host 99: Gitlab['gitlab_rails']['gitlab_email_from'] ||= "gitlab@#{uri.host}" 100: 101: case uri.scheme 102: when "http" 103: Gitlab['gitlab_rails']['gitlab_https'] = false 104: when "https"
解决:http://stackoverflow.com/questions/26660084/external-url-must-include-a-fqdn
有可能是创建了git账户,git账户设置的和gitlab不一致,导致次错误,需要删除git账户后,在进行安装。
vim /opt/gitlab/embedded/cookbooks/gitlab/libraries/gitlab.rb
99 def parse_external_url 100 return unless external_url 101 102 uri = URI("http://whatever.example.com") //just change external_url line here 103 104 unless uri.host 105 raise "External URL must include a FQDN" 106 end 107 Gitlab['user']['git_user_email'] ||= "gitlab@#{uri.host}" 108 Gitlab['gitlab_rails']['gitlab_host'] = uri.host 109 Gitlab['gitlab_rails']['gitlab_email_from'] ||= "gitlab@#{uri.host}" 110 111 case uri.scheme 112 when "http" 113 Gitlab['gitlab_rails']['gitlab_https'] = false 114 when "https" 115 Gitlab['gitlab_rails']['gitlab_https'] = true 116 Gitlab['nginx']['ssl_certificate'] ||= "/etc/gitlab/ssl/#{uri.host}.crt" 117 Gitlab['nginx']['ssl_certificate_key'] ||= "/etc/gitlab/ssl/#{uri.host}.key" 118 else 119 raise "Unsupported external URL scheme: #{uri.scheme}" 120 end 121 122 unless ["","/"].include?(uri.path) 123 raise "Unsupported external URL path: #{uri.path}" 124 end 125 126 Gitlab['gitlab_rails']['gitlab_port'] = uri.port 127 end
and then do
gitlab-ctr reconfigure
everything is ok!
4.打开 sshd 和 postfix 服务
service sshd start service postfix start
- 2
5.了使 GitLab 社区版的 Web 界面可以通过网络进行访问,我们需要允许 80 端口通过防火墙,这个端口是 GitLab 社区版的默认端口。为此需要运行下面的命令
sudo iptables -A INPUT -p tcp -m tcp --dport 80 -j ACCEPT
- 1
6.检查GitLab是否安装好并且已经正确运行,输入下面的命令
sudo gitlab-ctl status
- 1
如果得到类似下面的结果,则说明GitLab运行正常
run: gitlab-workhorse: (pid 1148) 884s; run: log: (pid 1132) 884s run: logrotate: (pid 1150) 884s; run: log: (pid 1131) 884s run: nginx: (pid 1144) 884s; run: log: (pid 1129) 884s run: postgresql: (pid 1147) 884s; run: log: (pid 1130) 884s run: redis: (pid 1146) 884s; run: log: (pid 1133) 884s run: sidekiq: (pid 1145) 884s; run: log: (pid 1128) 884s run: unicorn: (pid 1149) 885s; run: log: (pid 1134) 885s
- 2
- 3
- 4
- 5
- 6
- 7
7.在浏览器地址栏中输入:http://127.0.0.1,即可访问GitLab的Web页面
8.首次使用时,浏览器Web页面会提示设置密码,如下图所示。
9.设置密码password后,点击按钮“Change your password”后,跳转到登录/注册页面,如下图所示。
登录名为root,密码为前面设置的password,登录后进入欢迎页面,如下图所示。
10.登录进入系统后,创建一个Group,创建后如下图所示。
11.创建用户,进入http://127.0.0.1/users/sign_in,进入首页创建一个新用户,如下图所示。
12.创建好了用户后,会自动引导至用户的主页,点击左边菜单栏中的Profile Settings,进入配置界面,再点击导航栏中的SSH Keys进入密钥的输入界面,如下图所示。
如果不知道如何获取密钥,可以按照这个链接来进行操作:http://127.0.0.1/help/ssh/README
得到了密钥后,将其输入即可
13.在用户主页中创建项目,如下图所示。
14.创建好了项目后,引导至项目的主页
15.至此,基于Ubuntu 16.04 x64操作系统的GitLab服务器搭建工作就完成了。
- sudo passwd root,su root