Gitlab官网:https://about.gitlab.com/
gitlab历史版本下载:gitlab/gitlab-ce - Packages · packages.gitlab.com
一、CentOS 7 安装Gitlab
1.1 安装步骤
1.1.1 配置yum源
vim /etc/yum.repos.d/gitlab-ce.repo
复制以下内容到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
1.1.2 更新本地yum缓存
sudo yum makecache
1.1.3 安装GitLab社区版
sudo yum install gitlab-ce #自动安装最新版
sudo yum install gitlab-ce-x.x.x #安装指定版本
1.1.4 修改gitlab默认IP和端口
sudo vim /etc/gitlab/gitlab.rb
将http://localhost更改为,解析的域名或者内网ip
external_url 'http://192.168.1.121:8888'
修改完成后需要执行配置重载
sudo gitlab-ctl reconfigure
1.1.5 开放端口及重载防火墙
sudo firewall-cmd --add-port=8888/tcp --permanent
sudo firewall-cmd --reload
1.1.6 GitLab登录
在浏览器的地址栏中输入上述gitlab服务器external_url 配置的内网IP及端口即可打开GitLab登录界面。
1.1.7 GitLab默认密码
gitlab-ce初装以后,把密码放在了一个临时文件中了 /etc/gitlab/initial_root_password
这个文件将在首次执行reconfigure后24小时自动删除
Notes:
Default admin account has been configured with following details:
Username: root
Password: You didn't opt-in to print initial root password to STDOUT.
Password stored to /etc/gitlab/initial_root_password. This file will be cleaned up in first reconfigure run after 24 hours.
NOTE: Because these credentials might be present in your log files in plain text, it is highly recommended to reset the password following https://docs.gitlab.com/ee/security/reset_user_password.html#reset-your-root-password.
gitlab Reconfigured!
[root@demo]# cat /etc/gitlab/initial_root_password
Password 冒号后面即为密码字符串
# WARNING: This value is valid only in the following conditions
# 1. If provided manually (either via `GITLAB_ROOT_PASSWORD` environment variable or via `gitlab_rails['initial_root_password']` setting in `gitlab.rb`, it was provided before database was seeded for the first time (usually, the first reconfigure run).
# 2. Password hasn't been changed manually, either via UI or via command line.
#
# If the password shown here doesn't work, you must reset the admin password following https://docs.gitlab.com/ee/security/reset_user_password.html#reset-your-root-password.
Password: thAXLJhVoo6V9sRvRH5HrLrD5rg88C7gccEGZDT4Lq0=
# NOTE: This file will be automatically deleted in the first reconfigure run after 24 hours.
登录
1.1.8 管理员修改密码
1.1.9 普通用户修改密码
登录成功后点击左侧工具栏目Profile Settings ------ Password -------修改密码-------Save password。
Gitlab 常用命令
Gitlab 性能调优
sudo vim /etc/gitlab/gitlab.rb
unicorn['worker_processes'] = 2 #官方建议值为CPU核数+1(服务器只部署gitLab的情况下),可提高服务器响应速度,此参数最小值为2,设为1服务器可能卡死
unicorn['work_timeout'] = 60 #设置超时时间
unicorn['worker_memory_limit_min'] = "200 * 1 << 20" #减少最小内存
unicorn['worker_memory_limit_max'] = "300 * 1 << 20" #减少最大内存
postgresql['shared_buffers'] = "128MB" #减少数据库缓存
postgresql['max_worker_processes'] = 6 #减少数据库并发数
sidekiq['concurrency'] = 15 #减少sidekiq并发数
sudo gitlab-ctl reconfigure
sudo gitlab-ctl restart
Gitlab 配置邮件通知
修改配置文件
vim /etc/gitlab/gitlab.rb
# 这里以QQ邮箱为例,配置QQ邮箱为发件邮箱
gitlab_rails['smtp_enable'] = true
gitlab_rails['smtp_address'] = "smtp.qq.com"
gitlab_rails['smtp_port'] = 465
gitlab_rails['smtp_user_name'] = "你的qq邮箱@qq.com"
gitlab_rails['smtp_password'] = "QQ邮箱授权码"
gitlab_rails['smtp_domain'] = "smtp.qq.com"
gitlab_rails['smtp_authentication'] = "login"
gitlab_rails['smtp_enable_starttls_auto'] = true
gitlab_rails['smtp_tls'] = true
gitlab_rails['gitlab_email_from'] = "你的qq邮箱@qq.com"
注意:“smtp_password”不是QQ邮箱的密码,而是QQ邮箱的授权码,其他使用授权码的邮箱厂商配置类同。
重启gitlab服务
# 修改了配置文件之后要重新加载配置文件
gitlab-ctl reconfigure
gitlab服务器上邮件测试
root@demo$ gitlab-rails console
root@demo$ Notify.test_email('xxxxx@xxx.com','Message Subject','message Body').deliver_now
格式:Notify.test_email('收件邮箱地址', '邮件主题', '邮件内容').deliver_now
如果能收到测试邮件表示配置正确
Gitlab项目权限说明
Guest(匿名用户) - 创建项目、写留言薄
Reporter(报告人)- 创建项目、写留言薄、拉项目、下载项目、创建代码片段
Developer(开发者)- 创建项目、写留言薄、拉项目、下载项目、创建代码片段、创建合并请求、创建新分支、推送不受保护的分支、移除不受保护的分支 、创建标签、编写wiki
Master(管理者)- 创建项目、写留言薄、拉项目、下载项目、创建代码片段、创建合并请求、创建新分支、推送不受保护的分支、移除不受保护的分支 、创建标签、编写wiki、增加团队成员、推送受保护的分支、移除受保护的分支、编辑项目、添加部署密钥、配置项目钩子
Owner(所有者)- 创建项目、写留言薄、拉项目、下载项目、创建代码片段、创建合并请求、创建新分支、推送不受保护的分支、移除不受保护的分支 、创建标签、编写wiki、增加团队成员、推送受保护的分支、移除受保护的分支、编辑项目、添加部署密钥、配置项目钩子、开关公有模式、将项目转移到另一个名称空间、删除项目
钉钉添加gitlab机器人
1、钉钉群助手添加机器人
打开群设置——>机器人——>添加机器人——>极狐Gitlab
2、获取机器人的webhook
复制出机器人的Webhook地址,可用于向这个群发送消息,格式如下:
注意:请保管好此Webhook 地址,不要公布在外部网站上,泄露后有安全风险
3、在GitLab中设置项目的Webhook
填入对应GitLab机器人的Webhook地址,即可完成配置。
Gitlab 禁止从页面下载压缩包
公司里面的Gitlab ,禁止从网页直接下载repo压缩包,在stackflow找到一个解决方案,在gitlab内置的nginx上配置localhost来实现:
gitlab配置禁止下载压缩包:
sudo vim /etc/gitlab/gitlab.rb
更改gitlab配置文件中nginx自定义配置
nginx['custom_gitlab_server_config'] = "location ~* \.(archive|raw) {return 404; }\n"
重载配置
sudo gitlab-ctl reconfigure