linux toolsDevOps开源项目

gitlab 服务器搭建及使用

2019-03-30  本文已影响210人  云龙789

安装

1.安装并配置必要的依赖关系

在Ubuntu 16.04(推荐)上,以下命令还将在系统防火墙中打开HTTP和SSH访问。

sudo apt-get update
sudo apt-get install -y curl openssh-server ca-certificates

接下来,安装Postfix以发送通知电子邮件。如果要使用其他解决方案发送电子邮件,请跳过此步骤并在安装GitLab后配置外部SMTP服务器

sudo apt-get install -y postfix

在Postfix安装期间,可能会出现配置屏幕。选择“Internet Site”并按Enter键。使用服务器的外部DNS作为“邮件名称”,然后按Enter键。如果出现其他屏幕,请继续按Enter键接受默认值。

2.添加GitLab软件包存储库并安装软件包

添加GitLab包存储库。

curl https://packages.gitlab.com/install/repositories/gitlab/gitlab-ee/script.deb.sh | sudo bash

接下来,安装GitLab包。将http://homestead.test.com(这个名字自定义即可)更改为您要访问GitLab实例的URL。安装将自动配置并启动该URL的GitLab。HTTPS 在安装后需要其他配置

sudo EXTERNAL_URL="http://homestead.test.com" apt-get install gitlab-ee

使用 gitlab 需要关闭 nginx 。它也是使用的 nginx 不知道为什么会与开发环境的 nginx 冲突
如果你是使用的本地虚拟机,这个 url 需要在 hosts 文件做站点配置。

如果修改了配置文件sudo vi /etc/gitlab/gitlab.rb,需要重新配置Gitlab以使更改生效

sudo gitlab-ctl reconfigure

重新启动服务

sudo gitlab-ctl restart

有时候启动后,需要等个十几秒钟,站点才能有反正

这时候就可以使用配置的站点 http://homestead.test.com/ 访问 gitlab 了。首次方式使用的是 root 用户,你需要自己设置密码

卸载 gitlab

# 停止gitlab
sudo gitlab-ctl stop

# 查看进程
ps -e | grep gitlab

# Stop gitlab and remove its supervision process
sudo gitlab-ctl uninstall

# Debian/Ubuntu
sudo dpkg -r gitlab-ce

# Redhat/Centos
sudo rpm -e gitlab-ce

三、汉化Gitlab

使用xhang提供的汉化

https://gitlab.com/xhang/gitlab
对应版本的汉化包选择

图片.png
点击下载,就能看到下载地址
图片.png
# 查看gitlab版本
cat /opt/gitlab/embedded/service/gitlab-rails/VERSION

# 下载汉化包
wget方式(指定版本)
wget https://gitlab.com/xhang/gitlab/-/archive/11-9-stable/gitlab-11-9-stable.tar.gz

# 解压
tar -axvf gitlab-11-9-stable.tar.gz 
解压后可以直接删除下载的压缩文件了

# 查看版本号   gitlab-11-9-stable  是我的解压文件,你自己要看下你的是什么
cat gitlab-11-9-stable/VERSION
或者
cat gitlab/VERSION

# 备份gitlab
cd /opt/gitlab/embedded/service
mv gitlab-rails  pre  // 将原配置文件更名为 pre
mv /home/vagrant/gitlab-11-9-stable/   gitlab-rails   // 将下载的汉化包,移动过来,并更名

# 重启配置及重启gitlab
sudo gitlab-ctl reconfigure
sudo gitlab-ctl restart

其他配置

(可选)如果缺少资源,可以使用以下命令关闭Unicorn和Sidekiq,暂时释放一些内存:

sudo gitlab-ctl stop unicorn
sudo gitlab-ctl stop sidekiq
图片.png

创建项目

图片.png

配置选项这个官方的配置文件,我建议大家好好看看,看不懂的话,是可以直接用谷歌浏览器,直接翻译的

git 对应的数据仓库位置

/var/opt/gitlab/git-data/repositories/

你也可以在仓库中使用 git 的一些列指令


图片.png

你可以写个脚本,执行将仓库 /var/opt/gitlab/git-data/repositories 的数据同步到服务器站点对应的目录上。我不知道是否需要 stop start 这样的操作。我是看文档这么写的。回头我尝试了更好的方法后,再做更新

# Prevent users from writing to the repositories while you move them.
sudo gitlab-ctl stop

# Note there is _no_ slash behind 'repositories', but there _is_ a
# slash behind 'git-data'.
sudo rsync -av /var/opt/gitlab/git-data/repositories /var/www/data/

# Start the necessary processes and run reconfigure to fix permissions
# if necessary
sudo gitlab-ctl upgrade

# Double-check directory layout in /mnt/nas/git-data. Expected output:
# repositories
sudo ls /var/www/data/

# Done! Start GitLab and verify that you can browse through the repositories in
# the web interface.
sudo gitlab-ctl start
图片.png
上一篇下一篇

猜你喜欢

热点阅读