文章目录
前提:有git
#-----------------------------------1、install requirements---------------------------------------------
sudo apt update
sudo apt install ca-certificates curl openssh-server postfix
#-----------------------------------2、进入/tmp目录然后下载安装脚本---------------------------------------------
cd /tmp
curl -LO https://packages.gitlab.com/install/repositories/gitlab/gitlab-ce/script.deb.sh
sudo bash /tmp/script.deb.sh
sudo apt install gitlab-ce
# 输出如下信息(一部分)
'''
GitLab was unable to detect a valid hostname for your instance.
Please configure a URL for your GitLab instance by setting `external_url` configuration in /etc/gitlab/gitlab.rb file. # 关键提示1
Then, you can start your GitLab instance by running the following command: sudo gitlab-ctl reconfigure # 关键提示2
For a comprehensive list of configuration options please see the Omnibus GitLab readme
https://gitlab.com/gitlab-org/omnibus-gitlab/blob/master/README.md
Help us improve the installation experience, let us know how we did with a 1 minute survey:
https://gitlab.fra1.qualtrics.com/jfe/form/SV_6kVqZANThUQ1bZb?installation=omnibus&release=14-4
'''
#-----------------------------------3、注意到装完gitlab-ce中的两个关键提示---------------------------------------------
sudo vi /etc/gitlab/gitlab.rb
# 修改:external_url 'http://ip' ip是本地ip
sudo gitlab-ctl reconfigure
#-----------------------------------4、打开本地gitlab链接注册并登陆---------------------------------------------
http://localhost
# 注册个人信息并登陆
# 会出现如下提醒,意思是需要联系管理员完成审核
#------------------------------------5、error:登陆不上---------------------------------------------
Your account is pending approval from your GitLab administrator and hence blocked. Please contact your GitLab
#------------------------------------6、gitlab服务器修改管理员用户root密码---------------------------------------------
cd /opt/gitlab/bin/
sudo gitlab-rails console # 进入控制台
--------------------------------------------------------------------------------
Ruby: ruby 2.7.4p191 (2021-07-07 revision a21a3b7d23) [x86_64-linux]
GitLab: 14.4.2 (1ce86e92f81) FOSS
GitLab Shell: 13.21.1
PostgreSQL: 12.7
--------------------------------------------------------------------------------
u=User.find()^[[Loading production environment (Rails 6.1.4.1)
irb(main):001:0> u=User.find(1) # 1查询root用户账号信息并赋值给u
=> #<User id:1 @root>
irb(main):002:0> u.password='root12345' #2输入密码
=> "root12345"
irb(main):003:0> u.password_confirmation='root12345' #3 确认密码
=> "root12345"
irb(main):004:0> u.save # 4保存设置
Enqueued ActionMailer::MailDeliveryJob (Job ID: ff0be5d1-a001-4b39-ad25-ad2b1f78c834) to Sidekiq(mailers) with arguments: "DeviseMailer", "password_change", "deliver_now", {:args=>[#<GlobalID:0x00007f75fd37eba8 @uri=#<URI::GID gid://gitlab/User/1>>]}
=> true # 5设置成功
irb(main):005:0> exit # 6退出
# -----------------------------------7、重启服务-----------------------------------
sudo gitlab-ctl restart
# -----------------------------------8、审核注册账户-----------------------------------
# 打开本地链接(网页端输入ip,回车即可)
# 登陆root账户,审核注册账户,再用邮箱和密码就可以登陆本地gitlab(自己设置root账户的密码,登陆上去,完成自己注册账户的审核,结束后就可以实现注册账户的登陆)
usr = ss(xx@qq.com)# ss是gitlab账户,账户
passwd = XX
# -----------------------------------9、ADD keygen-----------------------------------
cd ~/.ssh/
ls -al # 查看是否有密钥文件
ssh-keygen -t rsa -C "xx@qq.com" # 没有的话生成密钥,每个邮箱应该都有自己对应的密钥
ls -al # 继续查看
cat id_rsa.pub # 有的话查看密钥,复制到gitlab
# -----------------------------------10、本地项目-----------------------------------
# 本地创建A项目
# 在gitlab的web界面再创建一个同名项目(应该是需要同名的)
# -----------------------------------11、上传代码-----------------------------------
cd A
git init # 初始化
git add . # 添加到本地仓库
git commit -m "init" # 上传到暂存区
git remote add origin http://192.168.1.11/ss/roadclose.git # http://192.168.1.11/ss/roadclose.git来自gitlab登陆自己账号后的。链接到gitlab的web端
git push -u origin master # 推代码到gitlab
# Username for 'http://192.168.1.11': ss
# Password for 'http://ss@192.168.1.11': (输入密码,但是不会显示,密码是gitlab的登陆密码)