GitLab 在企业内经常用于代码的版本控制,也是 DevOps 平台中尤为重要的一个工具,接下来在Centos7上(推荐配置:4C4G40G 以上)上安装 GitLab;
1.安装
首先在 GitLab 国内源下载(阿里云网盘下载方式) GitLab 的安装包:Index of /gitlab-ce/yum/el7/ | 清华大学开源软件镜像站 | Tsinghua Open Source Mirror 将下载后的 rpm 包(安装演示下载14.9.5版本),上传到服务器,之后通过 yum 直接安装即可:
[root@jax-centos7 ~]# yum install gitlab-ce-14.9.5-ce.0.el7.x86_64.rpm -y
安装完成后,需要更改几处配置:
# 将 external_url 更改为自己的发布地址,可以是服务器的 IP,也可以是一个可被解析的域名
[root@jax-centos7 ~]# vim /etc/gitlab/gitlab.rb
##! https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/instancedata-data-retrieval.html
external_url 'http://47.*.*.13:7070'
# 公司内可能已经有了 Prometheus 监控平台,
# 所以 GitLab 自带的 Prometheus 可以无需安装,后期可以安装 GitLab Exporter 即可进行监控
# 关闭 Prometheus 插件(可选)
###! Docs: https://docs.gitlab.com/ee/administration/high_availability
# monitoring_role['enable'] = true
prometheus['enable'] = false
# 配置QQ邮箱发送验证等通知消息(可选)
###! **Use smtp instead of sendmail/postfix.**
gitlab_rails['smtp_enable'] = true
gitlab_rails['smtp_address'] = "smtp.qq.com"
gitlab_rails['smtp_port'] = 465
gitlab_rails['smtp_user_name'] = "*******@qq.com"
gitlab_rails['smtp_password'] = "1234567890******"
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['smtp_pool'] = false
###! **Can be: 'none', 'peer', 'client_once', 'fail_if_no_peer_cert'**
###! Docs: http://api.rubyonrails.org/classes/ActionMailer/Base.html
# gitlab_rails['smtp_openssl_verify_mode'] = 'none'
# gitlab_rails['smtp_ca_path'] = "/etc/ssl/certs"
# gitlab_rails['smtp_ca_file'] = "/etc/ssl/certs/ca-certificates.crt"
### Email Settings
# gitlab_rails['gitlab_email_enabled'] = true
##! If your SMTP server does not like the default 'From: gitlab@gitlab.example.com'
##! can change the 'From' with this setting.
##! 此处的qq邮箱配置需要与gitlab_rails['smtp_user_name']中配置的邮箱一致
gitlab_rails['gitlab_email_from'] = '*******@qq.com'
修改配置后 刷新配置 并重启:
[root@jax-centos7 ~]# gitlab-ctl reconfigure
Starting Chef Infra Client, version 15.17.4
..............................................
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!
##! 重启gitlab
[root@jax-centos7 ~]# gitlab-ctl restart
之后可以通过浏览器访问 GitLab,账号 root,默认密码在/etc/gitlab/initial_root_password;
*************************小插曲 更新配置 未出现gitlab Reconfigured! **************************************
### 查看日志
[root@jax-centos7 ~]# cat /var/log/gitlab/postgres/current
FATAL: could not create shared memory segment: Cannot allocate memory
##是由于共享内存无法分配造成的 修改gitlab配置文件 (按需修改大小)
[root@jax-centos7 ~]# vim /etc/gitlab/gitlab.rb
postgresql['shared_buffers'] = "100MB"
##再次刷新配置 重启
[root@jax-centos7 ~]# gitlab-ctl reconfigure
[root@jax-centos7 ~]# gitlab-ctl restart
2.设置默认中文(可选)
2.1 打开/opt/gitlab/embedded/service/gitlab-rails/config/application.rb 文件,搜索config.i18n.default_locale = :
[root@jax-centos7 ~]# vim /opt/gitlab/embedded/service/gitlab-rails/config/application.rb
# config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}').to_s]
config.i18n.default_locale = :zh_CN
2.2 进入/opt/gitlab/embedded/service/gitlab-rails/config/locales/目录,建立zh_CN.yml文件
*根据en.yml翻译,翻译时的GitLab版本是14.9.5
[root@jax-centos7 ~]# cd /opt/gitlab/embedded/service/gitlab-rails/config/locales/
[root@jax-centos7 ~]# vim zh_CN.yml
# Sample localization file for English. Add more files in this directory for other locales.
# See https://github.com/svenfuchs/rails-i18n/tree/master/rails%2Flocale for starting points.
en:
hello: "你好,世界"
activerecord:
attributes:
issue_link:
source: 问题来源
target: 问题目标
group:
path: 群组 URL
member:
user: "成员的邮箱地址"
invite_email: "成员的邮箱地址"
project/error_tracking_setting:
token: "Auth 令牌"
project: "项目"
api_url: "Sentry API URL"
project/metrics_setting:
external_dashboard_url: "外部仪表板 URL"
project/grafana_integration:
token: "Grafana HTTP API 令牌"
grafana_url: "Grafana API URL"
grafana_enabled: "启用 Grafana 集成"
service_desk_setting:
project_key: "项目名称后缀"
user/user_detail:
job_title: '工作标题'
user/user_detail:
bio: 'Bio'
views:
pagination:
previous: "上"
next: "下"
date:
abbr_day_names:
- 日
- 一
- 二
- 三
- 四
- 五
- 六
abbr_month_names:
-
- 1月
- 2月
- 3月
- 4月
- 5月
- 6月
- 7月
- 8月
- 9月
- 10月
- 11月
- 12月
day_names:
- 星期天
- 星期一
- 星期二
- 星期三
- 星期四
- 星期五
- 星期六
formats:
default: "%Y-%m-%d"
long: "%B %d, %Y"
short: "%b %d"
admin: "%e %b, %Y"
month_names:
-
- 一月
- 二月
- 三月
- 四月
- 五月
- 六月
- 七月
- 八月
- 九月
- 十月
- 十一月
- 十二月
order:
- :year
- :month
- :day
datetime:
time_ago_in_words:
half_a_minute: "半分钟以前"
less_than_x_seconds:
one: "不到 1 秒前"
other: "不到 %{count} 秒前"
x_seconds:
one: "1 秒前"
other: "%{count} 秒前"
less_than_x_minutes:
one: "不到 1 分钟前"
other: "不到 %{count} 分钟前"
x_minutes:
one: "1 分钟前"
other: "%{count} 分钟前"
about_x_hours:
one: "大约 1 小时前"
other: "大约 %{count} 小时前"
x_days:
one: "1 天前"
other: "%{count} 天前"
about_x_months:
one: "大约 1 个月前"
other: "大约 %{count} 个月前"
x_months:
one: "1 个月前"
other: "%{count} 个月前"
about_x_years:
one: "大约 1 年前"
other: "大约 %{count} 年前"
over_x_years:
one: "1 年多以前"
other: "超过 %{count} 年以前"
almost_x_years:
one: "大约 1 年前"
other: "大约 %{count} 年前"
distance_in_words:
about_x_hours:
one: 大约 1 小时
other: 大约 %{count} 小时
about_x_months:
one: 大约 1 个月
other: 大约 %{count} 个月
about_x_years:
one: 大约 1 年
other: 大约 %{count} 年
almost_x_years:
one: 将近 1 年
other: 将近 %{count} 年
half_a_minute: 半分钟
less_than_x_minutes:
one: 不到一分钟
other: 不到 %{count} 分钟
less_than_x_seconds:
one: 不到 1 秒
other: 不到 %{count} 秒
over_x_years:
one: 1 年多以前
other: 超过 %{count} 年
x_days:
one: 1 天
other: "%{count} 天"
x_minutes:
one: 1 分钟
other: "%{count} 分钟"
x_months:
one: 1 月
other: "%{count} 月"
x_years:
one: 1 年
other: "%{count} 年"
x_seconds:
one: 1 秒
other: "%{count} 秒"
prompts:
day: 日
hour: 小时
minute: 分钟
month: 月
second: 秒
year: 年
errors:
format: "%{attribute} %{message}"
messages:
label_already_exists_at_group_level: "%{group} 的组级别已存在。 请选择另一个。"
username_exists_as_a_different_namespace: 具有该用户名的用户、别名或组已存在。
wrong_size: "大小错误(应为 %{file_size})"
size_too_small: "太小(至少应为 %{file_size})"
size_too_big: "太大(最多应为 %{file_size})"
accepted: 必须接受
blank: 不能为空
present: 必须为空
confirmation: 不匹配 %{attribute}
empty: 不能为空
equal_to: 必须等于 %{count}
even: 必须相等
exclusion: 被预定了
greater_than: 必须大于 %{count}
greater_than_or_equal_to: 必须大于或等于 %{count}
inclusion: 不包含在列表中
invalid: 是无效的
less_than: 必须小于 %{count}
less_than_or_equal_to: 必须小于或等于 %{count}
model_invalid: "Validation failed: %{errors}"
not_a_number: 不是数字
not_an_integer: 必须是整数
odd: 一定是奇数
required: 必须存在
taken: 已经被使用了
too_long:
one: 太长(最多 1 个字符)
other: 太长(最多 %{count} 个字符)
too_short:
one: 太短(最少 1 个字符)
other: 太短(最少 %{count} 个字符)
wrong_length:
one: 长度错误(应该是 1 个字符)
other: 长度错误(应该是 %{count} 个字符)
search_chars_too_long: 搜索查询太长(最多 %{count} 个字符)
search_terms_too_long: 搜索查询太长(最多 %{count} 个字词)
other_than: 必须不是 %{count}
template:
body: '以下字段存在问题:'
header:
one: 1 个错误禁止保存此 %{model}
other: "%{count} 个错误禁止保存此 %{model}"
helpers:
select:
prompt: 请选择
submit:
create: 创建 %{model}
submit: 保存 %{model}
update: 更新 %{model}
number:
currency:
format:
delimiter: ","
format: "%u%n"
precision: 2
separator: "."
significant: false
strip_insignificant_zeros: false
unit: "$"
format:
delimiter: ","
precision: 3
separator: "."
significant: false
strip_insignificant_zeros: false
human:
decimal_units:
format: "%n %u"
units:
billion: 十亿
million: 百万
quadrillion: 千万亿
thousand: 千
trillion: 万亿
unit: ''
format:
delimiter: ''
precision: 3
significant: true
strip_insignificant_zeros: true
storage_units:
format: "%n %u"
units:
byte:
one: Byte
other: Bytes
gb: GB
kb: KB
mb: MB
tb: TB
percentage:
format:
delimiter: ''
format: "%n%"
precision:
format:
delimiter: ''
support:
array:
last_word_connector: ",和"
two_words_connector: " 和 "
words_connector: ","
time:
am: am
formats:
default: "%a, %d %b %Y %H:%M:%S %z"
long: "%B %d, %Y %H:%M"
short: "%d %b %H:%M"
timeago_tooltip: "%b %-d, %Y %-l:%M%P"
with_timezone: "%Y-%m-%d %H:%M:%S %z"
pm: pm
2.3 运行gitlab-ctl reconfigure和gitlab-ctl restart 重新配置并重启 GitLab
[root@jax-centos7 ~]# gitlab-ctl reconfigure
[root@jax-centos7 ~]# gitlab-ctl restart
# 查看日志
[root@jax-centos7 ~]# gitlab-ctl tail