gitlab 9.3.6部署

来源:互联网 发布:java files运用失败 编辑:程序博客网 时间:2024/06/06 13:16

       GitLab,是一个利用 Ruby on Rails 开发的开源应用程序,实现一个自托管的Git项目仓库,可通过Web界面进行访问公开的或者私人项目安装。它拥有与GitHub类似的功能,能够浏览源代码,管理缺陷和注释。可以管理团队对仓库的访问,它非常易于浏览提交过的版本并提供一个文件历史库。团队成员可以利用内置的简单聊天程序(Wall)进行交流。它还提供一个代码片段收集功能可以轻松实现代码复用,便于日后有需要的时候进行查找。

      此处环境为centos7

       关闭防火墙和selinux

  1. 安装依赖软件
yum -y install policycoreutils openssh-server openssh-clients postfix
2.设置postfix开机自启,并启动,postfix支持gitlab发信功能
systemctl enable postfix && systemctl start postfix
3.下载gitlab安装包,然后安装
centos 6系统的下载地址:https://mirrors.tuna.tsinghua.edu.cn/gitlab-ce/yum/el6
centos 7系统的下载地址:https://mirrors.tuna.tsinghua.edu.cn/gitlab-ce/yum/el7

下载rpm包并安装:
wget https://mirrors.tuna.tsinghua.edu.cn/gitlab-ce/yum/el7/gitlab-ce-9.3.6-ce.0.el7.x86_64.rpm

rpm  -ivh  gitlab-ce-9.3.6-ce.0.el7.x86_64.rpm


4.修改gitlab配置文件指定服务器ip和自定义端口:
vim  /etc/gitlab/gitlab.rb

external_url 'http://192.168.8.147'

5.重置并启动GitLab
执行:
gitlab-ctl reconfigure
gitlab-ctl restart
复制代码
ok: run: gitlab-git-http-server: (pid 3922) 1sok: run: logrotate: (pid 3929) 0sok: run: nginx: (pid 3936) 1sok: run: postgresql: (pid 3941) 0sok: run: redis: (pid 3950) 0sok: run: sidekiq: (pid 3955) 0sok: run: unicorn: (pid 3961) 1s

6.访问 GitLab页面
如果没有域名,直接输入服务器ip和指定端口进行访问

初始账户: root 密码: 5iveL!fe

第一次登录修改密码

我这个图是汉化后的界面,稍后说明汉化过程


6.设置gitlab发信功能,需要注意一点:
发信系统用的默认的postfix,smtp是默认开启的,两个都启用了,两个都不会工作。
我这里设置关闭smtp,开启postfix
关闭smtp方法:vim /etc/gitlab/gitlab.rb
找到#gitlab_rails['smtp_enable'] = true 改为 gitlab_rails['smtp_enable'] = false
修改后执行gitlab-ctl reconfigure
另一种是关闭postfix,设置开启smtp,相关教程请参考官网https://doc.gitlab.cc/omnibus/settings/smtp.html
测试是否可以邮件通知:
登录并添加一个用户,我这里使用qq邮箱添加一个用户


登录qq邮箱,可以收到邮件通知(如果收不到,请查看垃圾邮箱或者检查邮件是否被拦截并删除,如果有请添加到白名单并删除用户再重新添加用户就可以收到了,否则请检查邮件日志并做好相关设置)

登录qq邮箱,找到邮箱首页--自助查询--收信查询

7、汉化

查看版本
'cat /opt/gitlab/embedded/service/gitlab-rails/VERSION'
9.3.6

当前版本为v9.3.6,并确认汉化版本库是否包含该版本的汉化标签(-zh结尾),也就是是否包含 v9.3.6-zh

 下载汉化包并汉化

克隆汉化版本库,此处用了好久的时间,拉取这个分支,没有更好的办法,可以自行百度一下Git慢的解决方式

 'git clone https://gitlab.com/xhang/gitlab.git'


如果已经克隆过,则进行更新

'git fetch'

  比较汉化标签和原标签,导出 patch 用的 diff 文件.进入刚才的目录git clone 的目录

'cd gitlab'
'git diff v9.3.6 v9.3.6-zh > ../9.3.6-zh.diff'

 上传 9.3.6-zh.diff文件到服务器停止 gitlab

'gitlab-ctl stop'
'patch -d /opt/gitlab/embedded/service/gitlab-rails -p1 < ../9.3.6-zh.diff'


重启gitlab即可.
'gitlab-ctl start'


 执行重新配置命令
'gitlab-ctl reconfigure'

8、添加sshkey

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

(1).生成sshkey
在终端中敲下面的命令,第一步会生成一对私钥和公钥,分别存在 ~/.ssh/id_rsa和~/.ssh/id_rsa.pub中。第二步查看公钥字符串。

ssh-keygen -t rsa -C "$your_email"
cat ~/.ssh/id_rsa.pub

如果是在Windows下可以使用Git工具生成


这里使用的是Git Bash 下载地址:https://git-scm.com/downloads

$your_emai是你的邮箱地址,一直回车即可,此命令在C:\Users\<你的用户名>.ssh目录下生成一对公私密钥,拷贝公钥(.pub结尾的文件)的内容,如我的id_rsa.pub:

(2).保存sshkey到gitlab
登陆你的GitLab账号之后,点击右上角的”Profile Setting” -> “SSH Keys”,输入SSH Key标题(可自定义),将拷贝的id_rsa.pub内容拷贝到Key中,”Add Key”即可。

9、windows下git bash设置

命令行指令
Git 全局设置
git config --global user.name "Administrator"                             用户名
git config --global user.email "admin@example.com"               邮箱
 创建新版本库
git clone http://192.168.8.147/root/test.git                            库名
cd test
touch README.md
git add README.md
git commit -m "add README"
git push -u origin master
 已存在的文件夹
cd existing_folder
git init
git remote add origin http://192.168.8.147/root/test.git
git add .
git commit -m "Initial commit"
git push -u origin master
 已存在的 Git 版本库
cd existing_repo
git remote add origin http://192.168.8.147/root/test.git
git push -u origin --all
git push -u origin --tags


上传 代码或文件成功


GitLab一些常用指令

GitLab 启动 停止

**:
1.Start all GitLab components

sudo gitlab-ctl start
 
2.Stop all GitLab components

sudo gitlab-ctl stop


3.Restart all GitLab components

sudo gitlab-ctl restart

 
GitLab使用gitlab-ctl日志查看的方法

Gitlab 默认的日志文件存放在/var/log/gitlab 目录下

1.查看所有日志

sudo gitlab-ctl tail


2.查看nginx 访问日志

sudo gitlab-ctl tail nginx/gitlab_acces.log
 
3.查看 postgresql 日志

sudo gitlab-ctl tail  postgresql



维护

1.GitLab 仓库:
1.1 搜索git_data_dir

sudo vi /etc/gitlab/gitlab.rb
/git_data_dir

   

搜索到缺省路径: git_data_dir “/var/opt/gitlab/git-data”

需要su权限进入 git-data

sudo su
cd git-data
cd repositories

2.GitLab Backup

创建GitLab系统的备份

create a GitLab backup task

# use this command if you've installed GitLab with the Omnibus package
sudo gitlab-rake gitlab:backup:create



Also you can choose what should be backed up by adding environment variable SKIP. Available options: db, uploads (attachments), repositories, builds(CI build output logs), artifacts (CI build artifacts), lfs (LFS objects). Use a comma to specify several options at the same time.

sudo gitlab-rake gitlab:backup:create SKIP=db,uploads

 
Upload backups to remote (cloud) storage

Starting with GitLab 7.4

For omnibus packages:

gitlab_rails['backup_upload_connection'] = {
  'provider' => 'AWS',
  'region' => 'eu-west-1',
  'aws_access_key_id' => 'AKIAKIAKI',
  'aws_secret_access_key' => 'secret123'
}
gitlab_rails['backup_upload_remote_directory'] = 'my.s3.bucket'

Uploading to locally mounted shares
Using the Local storage provide
挂载U盘或其他设备
查看设备:

cat /proc/partitions

我的设备时 sdb4

在mnt下新建backups ,然后

sudo mkdir backups
sudo chown gitlab:gitlab backups
mount /dev/sbd1 /mnt/backups -o uid=1000,gid=1000



/dev/sdb1指的是U盘,/mnt/backups是挂载的地方.

如果是fat16就使用下面的命令
mount -t msdos /dev/sdb4 /mnt/usb
如果是fat32
mount -t vfat /dev/sdb4 /mnt/usb
如果是ext2格式,就用命令:
mount -t ext2 /dev/sda4 /mnt/usb
1.加挂FAT32文件系统
最简单的用法
mount /dev/hda6 /mnt/d

如果当前U盘已经挂载,

umount /dev/sdb1    ### or umount /media/disk which is the same

 

sdb1 是你的U盘

cd /mnt/usb即可看见u盘文件

For omnibus packages:

gitlab_rails['backup_upload_connection'] = {
  :provider => 'Local',
  :local_root => '/mnt/backups'
}

# The directory inside the mounted folder to copy backups to
# Use '.' to store them in the root directory
gitlab_rails['backup_upload_remote_directory'] = 'gitlab_backups'



Backup archive permissions
The backup archives created by GitLab (123456_gitlab_backup.tar) will have owner/group git:git and 0600 permissions by default. This is meant to avoid other system users reading GitLab’s data. If you need the backup archives to have different permissions you can use the ‘archive_permissions’ setting.

# In /etc/gitlab/gitlab.rb, for omnibus packages
gitlab_rails['backup_archive_permissions'] = 0644 # Makes the backup archives world-readable


Backup and restore omnibus-gitlab configuration

refer :
https://gitlab.com/gitlab-org/omnibus-gitlab/blob/master/doc/settings/backups.md

It is recommended to keep a copy of /etc/gitlab, or at least of /etc/gitlab/gitlab-secrets.json, in a safe place.

All configuration for omnibus-gitlab is stored in /etc/gitlab. To backup your configuration, just backup this directory.

# Example backup command for /etc/gitlab:
# Create a time-stamped .tar file in the current directory.
# The .tar file will be readable only to root.
sudo sh -c 'umask 0077; tar -cf $(date "+etc-gitlab-%s.tar") -C / etc/gitlab'


Error
1.NoMethodError: undefined method `files’ for nil:NilClass

gitlab:backup:create fails when ‘backup_upload_remote_directory’ doesn’t exist


参考文档

http://www.cnblogs.com/wenwei-blog/p/5861450.html

http://blog.csdn.net/u011241606/article/details/51471367

http://blog.csdn.net/love8753/article/details/75308652

原创粉丝点击