最少4G内存 , 不然后期访问 gitlab web页面可能会报错,最好先规划好数据存储目录,免得日后gitlab数据存储目录空间不足
[root@yfm07 ~]# free -h
total used free shared buff/cache available
Mem: 3.7G 564M 2.6G 44M 516M 2.9G
Swap: 2.0G 0B 2.0G
[root@yfm07 ~]# cat /etc/centos-release
CentOS Linux release 7.9.2009 (Core)
安装Gitlab的依赖包 :
[root@yfm07 ~]# yum -y install curl policycoreutils openssh-server openssh-clients postfix
[root@yfm07 ~]# systemctl enable postfix
[root@yfm07 ~]# systemctl start postfix
[root@yfm07 ~]# iptables -F
[root@yfm07 ~]# systemctl stop firewalld
[root@yfm07 ~]# systemctl disable firewalld
安装Gitlab-ce版
# 下载 gitlab-ce版yum源
[root@yfm07 ~]# curl https://packages.gitlab.com/install/repositories/gitlab/gitlab-ce/script.rpm.sh |bash
[root@yfm07 ~]# yum -y install gitlab-ce
配置gitlab域名
[root@yfm07 ~]# vim /etc/gitlab/gitlab.rb
# 13行 external_url 'http://192.168.199.107' 改为 http://IP
设置简体中文
edit profile-->preferences->Language
gitlab-ctl reconfigure #初始化gitlab
gitlab-ctl start #启动gitlab服务
gitlab-ctl status
systemctl enable gitlab-runsvdir.service #设置开机启动
systemctl restart gitlab-runsvdir.service #重启服务
默认使用nginx作为web服务器
[root@yfm07 ~]# netstat -antup | grep :80
tcp 0 0 0.0.0.0:8060 0.0.0.0:* LISTEN 8052/nginx: master
tcp 0 0 127.0.0.1:8080 0.0.0.0:* LISTEN 8030/puma 5.1.1 (un
tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 8052/nginx: master
tcp 0 0 127.0.0.1:8082 0.0.0.0:* LISTEN 8135/sidekiq 5.2.9
tcp 0 0 127.0.0.1:8080 127.0.0.1:42102 TIME_WAIT -
tcp 0 0 127.0.0.1:59976 127.0.0.1:8060 ESTABLISHED 8050/prometheus
tcp 0 0 127.0.0.1:41926 127.0.0.1:8082 ESTABLISHED 8050/prometheus
tcp 0 0 127.0.0.1:8080 127.0.0.1:42098 TIME_WAIT -
tcp 0 0 127.0.0.1:8060 127.0.0.1:59976 ESTABLISHED 8076/nginx: worker
tcp 0 0 127.0.0.1:8082 127.0.0.1:41926 ESTABLISHED 8135/sidekiq 5.2.9
tcp 0 0 127.0.0.1:8080 127.0.0.1:42100 TIME_WAIT -
tcp 0 0 127.0.0.1:8080 127.0.0.1:42096 TIME_WAIT -
gitlab搭建成功
gitlab主配置文件:/etc/gitlab/gitlab.rb # 可以自定义一些邮件服务等
日志目录:/var/log/gitlab/ # 对应各服务
服务目录:/var/opt/gitlab/ # 对应各服务的主目录
仓库目录:/var/opt/gitlab/git-data # 记录项目仓库等提交信息
重启服务:gitlab-ctl stop/start/restart # 启动命令
访问http://192.168.199.107/,第一次登录 gitlab,需要为root 用户修改密码,root用户也是gitlab的超级管理员,(minimum is 8 characters),12345678
关闭注册功能,用管理员用户登录 Admin Area→setting→取消Sing-up enabled 选项对勾,然后下拉网页 , 在Sign-up restrictions 配置项的末尾有 保存修改 ,http://192.168.199.107/admin
gitlab的使用 :
新建组
新建项目
创建用户
root/12345678
user1/12345678
重置用户密码
删除用户
配置自己的Git 工作环境
[root@yfm07 web1]# git config --global user.name "user1"
[root@yfm07 web1]# git config --global user.email "[email protected]"
[root@yfm07 web1]# cat ~/.gitconfig
[user]
name = user1
email = [email protected]
如果要在某个特定的项目中使用其他名字或者邮件地址,先进到项目目录下,然后只要去掉 --global 选 项重新配置即可
邮箱配置,我这里配置的是qq邮箱
vim /etc/gitlab/gitlab.rb
gitlab_rails['smtp_enable'] = true
gitlab_rails['smtp_address'] = "smtp.qq.com" ## 此处要改成你的smtp地址
gitlab_rails['smtp_port'] = 465
gitlab_rails['smtp_user_name'] = "[email protected]" ## 此处要改成你的邮箱
gitlab_rails['smtp_password'] = "123456" ## qq邮箱授权码,获取方式https://service.mail.qq.com/cgi-bin/help?subtype=1&&id=28&&no=1001256
gitlab_rails['smtp_domain'] = "qq.com" ## smtp地址域名
gitlab_rails['smtp_authentication'] = "login"
gitlab_rails['smtp_enable_starttls_auto'] = true
gitlab_rails['smtp_tls'] = true
###! **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' # 此处去掉注释,默认none即可
gitlab_rails['gitlab_email_enabled'] = true
gitlab_rails['gitlab_email_from'] = '[email protected]' ## 发件邮箱
gitlab_rails['gitlab_email_display_name'] = 'aaa' ## 显示名字
gitlab_rails['gitlab_email_reply_to'] = '[email protected]'
gitlab_rails['gitlab_email_subject_suffix'] = ''
gitlab-ctl stop
gitlab-ctl reconfigure
gitlab-ctl status
测试邮件发送
[root@yfm07 repositories]# gitlab-rails console
irb(main):001:0> Notify.test_email('[email protected]', 'Subject', 'Message Body').deliver_now
Notify#test_email: processed outbound mail in 0.8ms
Delivered mail [email protected] (1201.0ms)
Date: Thu, 25 Feb 2021 18:59:23 +0800
扫描二维码关注公众号,回复:
13132142 查看本文章

配置ssh key
ssh-keygen -t rsa -C "[email protected]" -f ~/.ssh/id_rsa
[root@yfm07 web1]# cat ~/.ssh/id_rsa.pub
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQCguix7dkP2c2LM3KbQTAcbjeqB9RoPyxlWNDGTHOXr+AedC7nEQaOjgdGd0oeson0khUuCXAxsBtex+I0VA9JrBr5c1N8F30ZNwvAHNrnvoFFixWGVGhZtnYKAU5h9RMpcX0VUN+uFDCt3N4L2y+jtJP9AKo7SDTSZYgCATt7lxINLW8Mt2XsnnmeWVfufd92YwP0cZZoazs2LBPz/L1Rt4bT5UL51h6g/KJJRuRP9tdDwmhHMw+nJqmNN2HYAAbTqEtfO982qme6I5So5oDgqe7TqEFceMjaCweS6PqlObKPaq8FNBbDR7mspjzOXuyWrIgT/k9fefMvXOxmMyeUV [email protected]
edit profile 将该公钥添加到gitlab ssh key即可
[root@yfm07 gitlab]# git clone [email protected]:[email protected]/develop/web1.git
Cloning into 'web1'...
The authenticity of host '192.168.199.107 (192.168.199.107)' can't be established.
ECDSA key fingerprint is SHA256:sBPp9/mnvcV7YS85h7+sVjXEM+m21/kB0xLDM0lUvi4.
ECDSA key fingerprint is MD5:7b:9d:60:f6:b9:7a:22:99:49:d8:7f:c4:62:46:39:f0.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '192.168.199.107' (ECDSA) to the list of known hosts.
total 0
Cloning into 'web1'...
remote: Enumerating objects: 3, done.
remote: Counting objects: 100% (3/3), done.
remote: Total 3 (delta 0), reused 0 (delta 0), pack-reused 0
Receiving objects: 100% (3/3), done.
卸载gitlab
yum list installed | grep gitlab
yum remove -y gitlab
find / -name *gitlab*|xargs rm -rf 删除所有包含gitlab的文件及目录
find / -name gitlab |xargs rm -rf
参考: