GitLab Basic
GitLab Basic
GitLab 简介
GitLab 是由 GitLab Inc.开发,一款基于 Git 的完全集成的软件开发平台(fully 集成软件 development platform)。[5][6] 另外,GitLab 且具有wiki以及在线编辑、issue跟踪功能、CI/CD 等功能
详情参考:https://zh.wikipedia.org/wiki/GitLab
Installing GitLab via Package
官方所提供的安装步骤(GitLab EE
版本):https://about.gitlab.com/install/#centos-7
懒人安装方法(通过rpm包安装,GitLab CE
版本):
# 安装所需依赖yum install -y curl policycoreutils-python openssh-server postfix
# 下载CE包wget https://mirrors.tuna.tsinghua.edu.cn/gitlab-ce/yum/el7/gitlab-ce-13.1.4-ce.0.el7.x86_64.rpmyum install -y gitlab-ce-13.1.4-ce
编辑gitlab
配置文件/etc/gitlab/gitlab.rb
:
# 大概在29行,将url改为本机地址,当然在这里你可以直接填写你的域名external_url 'http://172.16.1.131'# 时区gitlab_rails['time_zone'] = 'Asia/Shanghai'# ssh拉取端口gitlab_rails['gitlab_shell_ssh_port'] = 10222# 并添加以下内容letsencrypt['enable'] = false
启动相关服务:
systemctl start postfixsystemctl start sshd
初始化GitLab
服务:
gitlab-ctl reconfigure
默认GitLab 是安装到/opt/gitlab
目录,配置文件在/etc/gitlab/
下.
安装完成之后, 打开浏览器进行访问即可:
:warning:默认用户名为root
, 密码首次使用GitLab
时会提示设置.
默认密码:
podman exec -ti gitlab_local_arm grep "Password:" /etc/gitlab/initial_root_password
GitLab EE 与 CE 版本比较:https://about.gitlab.com/features/#compare
Installing GitLab with Docker
GitLab 仓库镜像:https://hub.docker.com/r/gitlab/gitlab-ce/
ARM架构的镜像推荐使用:https://github.com/zengxs/gitlab-docker
$ cat gitlab.rbexternal_url 'http://git.nblh.local'
gitlab_rails['gitlab_ssh_host'] = 'git.nblh.local'gitlab_rails['gitlab_shell_ssh_port'] = 2202
$ docker run \ -itd \ -p 9980:80 \ -p 2222:22 \ -v /Users/agou-ops/workspace/podman_workspace/gitlab:/etc/gitlab \ --restart always \ --privileged=true \ --name gitlab \ zengxs/gitlab:ce
haproxy反向代理:
配置 HTTPS 证书
为GitLab
的ssl证书创建目录: mkdir -pv /etc/gitlab/ssl
修改配置文件/etc/gitlab/gitlab.rb
:
external_url 'https://gitlab.agou-ops.top' # gitlab申请的域名证书nginx['redirect_http_to_https']=truenginx['ssl_certificate'] = "/etc/gitlab/ssl/gitlab.pem"nginx['ssl_certificate_key'] = "/etc/gitlab/ssl/gitlab.key"
更新gitlab
的配置:
gitlab-ctl reconfigure
最后修改nginx
的配置文件/etc/nginx/conf.d/gitlab.conf
:
server { listen *:443 ssl http2; server_name gitlab.agou-ops.top; error_log /home/logs/nginx/gitlab.mydomain.com.com.error.log error; access_log /home/logs/nginx/gitlab.mydomain.com.access.log main; server_tokens off; client_max_body_size 0; ssl on; ssl_certificate /etc/gitlab/ssl/gitlab.pem; ssl_certificate_key /etc/gitlab/ssl/gitlab.key;...}
server{ listen*:80; server_name gitlab.agou-ops.top; rewrite^(.*)$https://$host$1permanent; # 或者 # return 301 https://$server_name$request_uri;}
# 另 add_header X-Served-By $host; proxy_set_header Host $host; proxy_set_header X-Forwarded-Scheme $scheme; proxy_set_header X-Forwarded-Proto $scheme; proxy_set_header X-Forwarded-For $remote_addr; proxy_set_header X-Real-IP $remote_addr; proxy_pass http://127.0.0.1:8880$request_uri;
重启GitLab
:
gitlab-ctl restart
SMTP 邮件设置
QQ exmail
QQ exmail (腾讯企业邮箱)
gitlab_rails['smtp_enable'] = truegitlab_rails['smtp_address'] = "smtp.exmail.qq.com"gitlab_rails['smtp_port'] = 465gitlab_rails['smtp_user_name'] = "xxxx@xx.com"gitlab_rails['smtp_password'] = "password"gitlab_rails['smtp_authentication'] = "login"gitlab_rails['smtp_enable_starttls_auto'] = truegitlab_rails['smtp_tls'] = truegitlab_rails['gitlab_email_from'] = 'xxxx@xx.com'gitlab_rails['smtp_domain'] = "exmail.qq.com"
更多邮箱格式, 参考GitLab SMTP Settings
重启GitLab
服务器, 使配置生效:
gitlab-ctl restart
测试SMTP邮件是否正常运行:
Testing the SMTP configuration
You can verify GitLab’s ability to send emails properly using the Rails console. On the GitLab server, execute gitlab-rails console
to enter the console. Then, you can enter the following command at the console prompt to cause GitLab to send a test email:
[root@aliyun ~]\# gitlab-rails console-------------------------------------------------------------------------------- GitLab: 13.1.4 (18c5ab32b73) FOSS GitLab Shell: 13.3.0 PostgreSQL: 11.7--------------------------------------------------------------------------------Loading production environment (Rails 6.0.3.1)irb(main):001:0> Notify.test_email('destination_email@address.com', 'Message Subject', 'Message Body').deliver_now
# press enter to test SMTP sending
Gitlab 项目域名IP修改
`/opt/gitlab/embedded/service/gitlab-rails/config/gitlab.yml`文件以下内容: ## GitLab settings gitlab: ## Web server settings (note: host is the FQDN, do not include http://) host: 192.168.0.104 port: 8880 https: false
`/etc/gitlab/gitlab.rb`以下内容:## Url on which GitLab will be reachable.## For more details on configuring external_url see:## https://gitlab.com/gitlab-org/omnibus-gitlab/blob/master/doc/settings/configuration.md#configuring-the-external-url-for-gitlabexternal_url 'http://192.168.0.104:8880'
重启gitlab服务以生效:gitlab-ctl restart
版本升级
建议升级前按照钱数备份方式,先对GitLab数据进行备份,同时备份GitLab配置文件
/etc/gitlab/gitlab.rb
,然后再执行下列步骤。
- 关闭部分GitLab服务
gitlab-ctl stop unicorngitlab-ctl stop sidekiqgitlab-ctl stop nginx
- 升级GitLab
GitLab 升级包下载地址:https://packages.gitlab.com/gitlab/gitlab-ce
。下载好需要的版本上传至服务器,直接运行下列命令安装就可以了。
rpm -Uvh gitlab-ce-10.0.4-ce.0.el7.x86_64.rpm
- 重新配置GitLab
安装完成后,根据需要修改配置文件/etc/gitlab/gitlab.rb
,也可以直接使用原来备份好的gitlab.rb
文件,执行重新配置命令:
gitlab-ctl reconfigure
- 重启GitLab
gitlab-ctl restart
参考链接
- GitLab installation: https://docs.gitlab.com/ee/install/
- GitLab SMTP Settings: https://docs.gitlab.com/omnibus/settings/smtp.html#smtp-settings