Ubuntu14.04搭建gitlab代码管理平台

Ubuntu14.04搭建gitlab版本管理平台

1.安装依赖包

sudo apt-get install curl openssh-server ca-certificates postfix

注:执行完成后,出现邮件配置,选择Internet那一项(不带Smarthost的)
然后需要填写邮箱配置。

2.添加GitLab安装包镜像源

利用清华大学的镜像(https://mirror.tuna.tsinghua.edu.cn/help/gitlab-ce/)来进行主程序的安装

2.1 首先信任 GitLab 的 GPG 公钥

curl https://packages.gitlab.com/gpg.key 2> /dev/null | sudo apt-key add - &>/dev/null

2.2 使用root用户修改配置文件

sudo gedit /etc/apt/sources.list.d/gitlab-ce.list

添加下一行内容:
deb https://mirrors.tuna.tsinghua.edu.cn/gitlab-ce/ubuntu xenial main

3 安装gitlab-ce

每次添加完软件源后要必须要update一下。

sudo apt-get update
sudo apt-get install gitlab-ce

/**注意:安装需要2GB存储空间
0 upgraded, 1 newly installed, 0 to remove and 448 not upgraded.
Need to get 799 MB of archives.
After this operation, 2,090 MB of additional disk space will be used.
********************************************************************************/

安装完成耗时半小时,出现以下界面:
It looks like GitLab has not been configured yet; skipping the upgrade script.

Thank you for installing GitLab!
GitLab was unable to detect a valid hostname for your instance.
Please configure a URL for your GitLab instance by setting external_url
configuration in /etc/gitlab/gitlab.rb file.
Then, you can start your GitLab instance by running the following command:
sudo gitlab-ctl reconfigure

For a comprehensive list of configuration options please see the Omnibus GitLab readme
https://gitlab.com/gitlab-org/omnibus-gitlab/blob/master/README.md

3.1 查看安装的gitlab版本

cat /opt/gitlab/embedded/service/gitlab-rails/VERSION

版本为:
12.10.3

4 配置GitLab IP地址

4.1 修改 externval_url 之后的域名

方法1:(使用GNU nano 2.2.6工具编辑gitlab.rb)
sudo -e /etc/gitlab/gitlab.rb
nano编辑器保存步骤:CTRL+X --> 按Y保存 --> 然后按回车
方法2:使用 vim gedit都可以。

域名值可以是本机 IP 或指向本机 IP的域名
默认未修改的值:
external_url ‘http://gitlab.example.com’
默认是端口80
修改后的值:
external_url ‘http://192.168.19.128’

其他参考配置(8080是自定义端口必须要要和 unicorn[‘port’]一致)
external_url ‘http://192.168.19.128:8080’
(这个端口同上的那个external_url 后的端口)
unicorn[‘port’] = 8080

5.启动sshd和postfix服务

5.1 安装sshd

已经安装成功了可以忽略该步骤。
sudo apt-get install openssh-server

5.2 启动sshd和postfix

sudo service sshd start 

如果无效者执行

sudo /etc/init.d/ssh start
#验证sshd是否真正开启
ps -e|grep sshd 

启动postfix

sudo service postfix start

6 添加防火墙规则

sudo iptables -A INPUT -p tcp -m tcp --dport 80 -j ACCEPT

7 启动各项服务

(只要修改 /etc/gitlab/gitlab.rb 必须执行该命令才能生效)

sudo gitlab-ctl reconfigure

前方注意: 采坑之旅开始!!!!!!!!!!!!!!

错误1:
如果安装gitlab之前已经存在用户名为git的用户,会启动失败。
解决办法:process 35138 找到对应的进程kill掉,关闭用git账号登录的终端。

Running handlers:
There was an error running gitlab-ctl reconfigure:

account[GitLab user and group] (gitlab::users line 28) had an error: Mixlib::ShellOut::ShellCommandFailed: linux_user[GitLab user and group] (/opt/gitlab/embedded/cookbooks/cache/cookbooks/package/resources/account.rb line 51) had an error: Mixlib::ShellOut::ShellCommandFailed: Expected process to exit with [0], but received '8'
---- Begin output of ["usermod", "-s", "/bin/sh", "-d", "/var/opt/gitlab", "git"] ----
STDOUT:
STDERR: usermod: user git is currently used by process 35138
---- End output of ["usermod", "-s", "/bin/sh", "-d", "/var/opt/gitlab", "git"] ----
Ran ["usermod", "-s", "/bin/sh", "-d", "/var/opt/gitlab", "git"] returned 8

Running handlers complete
Chef Client failed. 7 resources updated in 09 seconds

错误2:
There was an error running gitlab-ctl reconfigure:

Multiple failures occurred:

  • Mixlib::ShellOut::ShellCommandFailed occurred in chef run:
    由于服务器是512MB的CPU运行内存,换至1G内存仍然报错,换至2G运行内存时问题解决。所以解决办法是换至大于等于2G CPU运行内存。(无效的解决办法)
    无效的解决办法参考:https://blog.csdn.net/qq_33126131/article/details/100675460

解决办法步骤2:

sudo gitlab-ctl start 			# 启动所有 gitlab 组件;
sudo gitlab-ctl stop 			# 停止所有 gitlab 组件;
sudo gitlab-ctl restart 		# 重启所有 gitlab 组件;
sudo gitlab-ctl status	 	# 查看服务状态;
sudo gitlab-ctl reconfigure  # 重新加载配置; 每次修改 /etc/gitlab/gitlab.rb 文件之后执行
sudo vim /etc/gitlab/gitlab.rb 	# 修改默认的配置文件;
sudo gitlab-ctl tail 		# 查看日志;
sudo gitlab-ctl tail nginx/gitlab_acces.log 	查看 nginx 访问日志

参考:https://www.cnblogs.com/shikyoh/p/10688340.html

执行服务重启重新配置后任然报错:

错误3
关键信息: version `GLIBCXX_3.4.21’ not found
原因是14.04系统GCC版本是4.8太老,16.04是GCC5.4不存在该问题。
查看本地gcc版本:

gcc -v
gcc version 4.8.4 (Ubuntu 4.8.4-2ubuntu1~14.04.4)

执行以下命令检查一下动态库链接

strings /usr/lib/x86_64-linux-gnu/libstdc++.so.6 | grep GLIBC

发现没有我们所需要的 GLIBCXX_3.4.21

sudo find / -name "libstdc++.so*"

参考(该文章使用32位库,然而本机是64位的,执行会报错): https://www.cnblogs.com/sddai/p/10318086.html

7.1报错终极解决办法

7.1.1下载libstdc++6_5.4.0


下载GCC5.4.0的C++标准库替换现有的**/usr/lib/x86_64-linux-gnu/libstdc++.so.6**
64位系统的C++标准库
http://archive.ubuntu.com/ubuntu/pool/main/g/gcc-5/libstdc++6_5.4.0-6ubuntu1~16.04.12_amd64.deb


32位系统的C++标准库(不能使用 build报错ELFCLASS32
http://archive.ubuntu.com/ubuntu/pool/main/g/gcc-5/libstdc++6_5.3.1-14ubuntu2_i386.deb
STDOUT: /opt/gitlab/embedded/bin/ruby: error while loading shared libraries: libstdc++.so.6: wrong ELF class: ELFCLASS32

7.1.2安装libstdc++6_5.4.0

解压 libstdc++6_5.4.0-6ubuntu1_16.04.12_amd64.deb
拷贝libstdc++6_5.4.0-6ubuntu1_16.04.12_amd64/data/usr/lib/x86_64-linux-gnu
到 /home/userid/Downloads/


 ll /usr/lib/x86_64-linux-gnu/libstdc++.so.6  #查看文件类型 是软链接
cd /usr/lib/x86_64-linux-gnu/
ll ~/Downloadsx86_64-linux-gnu/libstdc++.so.6* -lh
sudo cp /home/userid/Downloads/x86_64-linux-gnu/libstdc++.so.6.0.21 ./ #拷贝下载的so到系统库路径
sudo mv libstdc++.so.6 libstdc++.so.6.bak 	#备份原始库以备还原
sudo ln -s libstdc++.so.6.0.21 libstdc++.so.6   #软链接到下载的libstdc++.so.6.0.21
file libstdc++.so.6.0.21  #查看文件类型是x86-64库,没问题
libstdc++.so.6.0.21: ELF 64-bit LSB  shared object, x86-64, version 1 (GNU/Linux), dynamically linked, BuildID[sha1]=ea2410532d6adcd154644705e40b941cf362bea7, stripped

7.1.3 重新配置gitlab

再次执行重新配置gitlab的命令:

sudo gitlab-ctl reconfigure

执行结果:

Running handlers:
Running handlers complete
Chef Client finished, 314/1303 resources updated in 02 minutes 52 seconds
gitlab Reconfigured!

成功解决!

8 检查gitlab所有服务是否已启动

再次查看服务状态都已经正常了!!!

sudo gitlab-ctl status

共计15个服务。

run: alertmanager: (pid 59763) 119s; run: log: (pid 59530) 173s
run: gitaly: (pid 52920) 9375s; run: log: (pid 52436) 9900s
run: gitlab-exporter: (pid 59726) 121s; run: log: (pid 59354) 193s
run: gitlab-workhorse: (pid 59707) 122s; run: log: (pid 59247) 216s
run: grafana: (pid 59793) 118s; run: log: (pid 59703) 122s
run: logrotate: (pid 59291) 206s; run: log: (pid 59303) 205s
run: nginx: (pid 59260) 212s; run: log: (pid 59282) 209s
run: node-exporter: (pid 59720) 121s; run: log: (pid 59338) 197s
run: postgres-exporter: (pid 59785) 118s; run: log: (pid 59559) 169s
run: postgresql: (pid 52945) 9374s; run: log: (pid 52534) 9892s
run: prometheus: (pid 59740) 120s; run: log: (pid 59456) 178s
run: redis: (pid 52956) 9374s; run: log: (pid 52403) 9906s
run: redis-exporter: (pid 59728) 120s; run: log: (pid 59375) 185s
run: sidekiq: (pid 59202) 224s; run: log: (pid 59214) 223s
run: unicorn: (pid 59174) 230s; run: log: (pid 59197) 229s

9 配置gitlab 服务器

9.1 设置管理员密码

首先在浏览器中输入:http://192.168.19.168 登陆本地gitlab服务器。
第一次登录必须输入两次 password 后,点击按钮 “Change your password” 按钮后,才能跳转到登录/注册页面。
管理员密码至少八个字符(1***1***):Password is too short (minimum is 8 characters)
管理员默认用户名是:root

注册
登录
登录进入系统后,创建一个 Group

9.2 添加ssh key

git仓库之间的代码传输协议主要使用ssh协议。而一般搭建gitlab的时候使用的git用户是没有密码的,因此直接ssh是不能登录的,就需要使用ssh-keygen上传公钥,使用非对称加密传输。

添加ssh key

9.2.1 执行生成公钥和私钥的命令

ssh-keygen -t rsa

9.2.2 按3下回车键生成生成一对私钥和公钥

id_rsa.pub是公钥,需要配置到git服务器以便于免密码git pull
生成一对私钥和公钥,分别存在 /.ssh/id_rsa和/.ssh/id_rsa.pub

9.2.3 添加公钥到gitlab配置

添加key到gitlab服务器配置中,Profile Settings –> SSH Keys –> Add SSH Keys。
然后把上一步中的id_rsa.pub中的内容拷贝出来粘贴到输入框中,保存。

其他

新建的git项目默认存储位置是:
默认存储位置在**/var/opt/gitlab/git-data/repositories**, 需要root权限才能查看。
管理员默认用户名是:root
默认密码必须8位以上
查看版本命令:
cat /opt/gitlab/embedded/service/gitlab-rails/VERSION

登录网址:
http://192.168.19.128/users/sign_in
在这里插入图片描述

登录成功后的界面:
在这里插入图片描述

其他安装方法
bitnami的一键安装包下载地址:
https://downloads.bitnami.com/files/stacks/gitlab/12.10.3-0/bitnami-gitlab-12.10.3-0-linux-x64-installer.run

参考链接1:https://www.jianshu.com/p/8079a9a81ef3
参考链接2:
Ubuntu 搭建本地gitlab服务器 + smartgit图形化git仓库管理工具
https://blog.csdn.net/sunny_hu92/article/details/88421601

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章