felix-cao / Blog

A little progress a day makes you a big success!
31 stars 4 forks source link

gitlab 安装指南 #4

Open felix-cao opened 6 years ago

felix-cao commented 6 years ago

一、 更改 Repo 源

gitlab 官网 由于网络环境的原因,将 repo 源修改为[清华大学]。 在 /etc/yum.repos.d 目录下新建 gitlab-ce.repo 文件并保存。内容如下:

vi /etc/yum.repos.d/gitlab-ce.repo

内容为:

[gitlab-ce]
name=Gitlab CE Repository
baseurl=https://mirrors.tuna.tsinghua.edu.cn/gitlab-ce/yum/el$releasever/
gpgcheck=0
enabled=1

二、 安装gitlab

上一步修改了 yum 源,因此先重新生成缓存, 再安装

yum makecache
yum install gitlab-ce

三、 配置

cp -r /etc/gitlab/gitlab.rb /etc/gitlab/gitlab.bak.rb
echo > /etc/gitlab/gitlab.rb
vi /etc/gitlab/gitlab.rb

添加如下内容

nginx['listen_port'] = 9000
external_url 'http://git.56512.com'
git_data_dirs({
   "default" => {
       "path" => "/home/git/git-data",
       "failure_count_threshold" => 10,
       "failure_wait_time" => 30,
       "failure_rest_time" => 1800,
       "storage_timeout" => 30
    }
})

注意:

四、 初始化 GitLab

使用gitlab命令行工具

gitlab-ctl reconfigure

这个时候访问 http://git.56512.com 就可以了。

五、GitLab常用命令

使用已有的 nginx 为gitlab提供 https 访问

Reference

felix-cao commented 3 years ago

gitlab 如何设置中文或英文

右上角用户头像 settings(设置) -> Preferences(偏好) -> 下拉到底部 Localization(本地化) -> Language

gitlab 如何添加用户

左上角扳手状的 icon, 点击 Admin Area(管理中心), 左侧 Overview(概览) Dashboard(仪表盘) ,右边 New user 按钮

删除 project 项目

进入项目 --> settings --> general --> Advanced Collapse, 下拉到最下面

felix-cao commented 3 years ago

删除以 # 开头的注释内容

:g/^#/d

删除所有空行

:g/^$/d
felix-cao commented 3 years ago

开启 telnet 命令

telnet 可以测试端口号是否可用,比如:

telnet ip:port 或者 telnet www.baidu.com

PS:win7环境下,默认没有安装telnet客户端,你可以去“控制面板”--》“程序”(在左下角)---》“打开或关闭Windows功能”,勾上“telnet客户端”,确定就可以正常使用telnet命令了。

felix-cao commented 3 years ago

credential

git config --global credential.helper

felix-cao commented 3 years ago

添加新项目时,出现错误 image

原因及解决方案

felix-cao commented 3 years ago

ln -s /var/opt/gitlab/.ssh /home/git/.ssh

felix-cao commented 3 years ago

https://blog.csdn.net/alangshan/article/details/88866474

felix-cao commented 3 years ago

gitlab 忘记root密码

[root@localhost ~]# su git
[root@localhost ~]# gitlab-rails console production
DEPRECATION WARNING: Passing the environment's name as a regular argument is deprecated and will be removed in the next Rails version. Please, use the -eoption instead. (called from require at bin/rails:4)
--------------------------------------------------------------------------------
 GitLab:       12.2.0 (1c1d47c5974)
 GitLab Shell: 9.3.0
 PostgreSQL:   10.9
--------------------------------------------------------------------------------
Loading production environment (Rails 5.2.3)
irb(main):001:0> user = User.where(id: 1).first
=> #<User id:1 @root>
irb(main):002:0> user.password = 'root@123'
=> "root@123"
irb(main):003:0> user.password_confirmation = 'root@123'
=> "root@123"
irb(main):004:0> user.save!
Enqueued ActionMailer::DeliveryJob (Job ID: e562694d-2a1b-4bad-843b-d8567ac51077) to Sidekiq(mailers) with arguments: "DeviseMailer", "password_change", "deliver_now", #<GlobalID:0x00007fae7e55bcc8 @uri=#<URI::GID gid://gitlab/User/1>>
=> true
irb(main):005:0> quit

image

记得重启电脑

felix-cao commented 3 years ago

Gitlab 配置邮箱

修改 Gitlab 配置文件

$ vi /etc/gitlab/gitlab.rb
gitlab_rails['smtp_enable'] = true
gitlab_rails['smtp_address'] = "smtp.qq.com"
gitlab_rails['smtp_port'] = 465
gitlab_rails['smtp_user_name'] = "491766244@qq.com"
gitlab_rails['smtp_password'] = "-----" # QQ邮箱授权码
gitlab_rails['smtp_domain'] = "mail.qq.com"
gitlab_rails['smtp_authentication'] = "login"
gitlab_rails['smtp_enable_starttls_auto'] = true
gitlab_rails['smtp_tls'] = true
gitlab_rails['gitlab_email_from'] = '491766244@qq.com'
gitlab_rails['gitlab_email_enabled'] = true

更新配置、重启服务

$ gitlab-ctl reconfigure && gitlab-ctl restart

测试

$ gitlab-rails console
Notify.test_email('491766244@qq.com','Message Subject','Hello, Felix Cao').deliver_now

代码提交邮件通知

Admin Area -> Service templates -> Emails on push image

参考 Gitlab Doc