使用docker安装gitlab以及gitlab简单使用
使用docker安裝gitlab以及gitlab簡(jiǎn)單使用
- docker 安裝gitlab以及使用
- 1.創(chuàng)建主機(jī)映射目錄
- 2.gitlab鏡像拉取
- 3.運(yùn)行g(shù)itlab鏡像
- 4.配置
- 5.配置ssl支持
- 1.進(jìn)入到gitlab 的ssh命令行
- 2.登錄到Gitlab服務(wù)器
- 3.查詢用戶
- 4.修改密碼
- 5.保存
- 6.登錄
- 6.配置郵箱登錄
- 7.創(chuàng)建項(xiàng)目
- 8.創(chuàng)建ssh密鑰對(duì)
docker 安裝gitlab以及使用
本文基于 docker容器 +阿里云ECS服務(wù)器及外網(wǎng)域名進(jìn)行搭建
1.創(chuàng)建主機(jī)映射目錄
用于映射docker容器的目錄文件
[root@server-backend docker]# mkdir -p /docker/gitlib/config && mkdir -p /docker/gitlib/logs && mkdir -p /docker/gitlib/data [root@server-backend docker]# ls /docker/gitlib/ config data logs [root@server-backend docker]#2.gitlab鏡像拉取
docker pull gitlab/gitlab-ce3.運(yùn)行g(shù)itlab鏡像
docker run -d -p 443:443 -p 80:80 -p 222:22 --name gitlab --restart always -v /docker/gitlib/config:/etc/gitlab -v /docker/gitlib/logs:/var/log/gitlab -v /docker/gitlib/data:/var/opt/gitlab gitlab/gitlab-ce # -d:后臺(tái)運(yùn)行 # -p:將容器內(nèi)部端口向外映射 # --name:命名容器名稱 # -v:將容器內(nèi)數(shù)據(jù)文件夾或者日志、配置等文件夾掛載到宿主機(jī)指定目錄4.配置
按上面的方式,gitlab容器運(yùn)行沒問題,但在gitlab上創(chuàng)建項(xiàng)目的時(shí)候,生成項(xiàng)目的URL訪問地址是按容器的hostname來生成的,也就是容器的id。作為gitlab服務(wù)器,我們需要一個(gè)固定的URL訪問地址,于是需要配置gitlab.rb(宿主機(jī)路徑:/docker/gitlib/config/gitlab.rb)。
# gitlab.rb文件內(nèi)容默認(rèn)全是注釋 $ vim /docker/gitlib/config/gitlab.rb編輯文件內(nèi)容如下:
192.168.199.231應(yīng)該改為正確地址
# 配置http協(xié)議所使用的訪問地址,不加端口號(hào)默認(rèn)為80 external_url 'http://192.168.199.231'# 配置ssh協(xié)議所使用的訪問地址和端口 gitlab_rails['gitlab_ssh_host'] = '192.168.199.231' gitlab_rails['gitlab_shell_ssh_port'] = 222 # 此端口是run時(shí)22端口映射的222端口 :wq #保存配置文件并退出修改完成后重啟gitlab容器
# 重啟gitlab容器 $ docker restart gitlab #或者進(jìn)入容器中執(zhí)行 gitlab-ctl reconfigure gitlab-ctl restart此時(shí)項(xiàng)目的倉(cāng)庫(kù)地址就變了。如果ssh端口地址不是默認(rèn)的22,就會(huì)加上ssh:// 協(xié)議頭
打開瀏覽器輸入ip地址(因?yàn)槲业膅itlab端口為80,所以瀏覽器url不用輸入端口號(hào),如果端口號(hào)不是80,則打開為:ip:端口號(hào))
默認(rèn)的用戶為root,密碼可以查看initial_root_password文件
[root@server-backend config]# cat /docker/gitlib/config/initial_root_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: /w28USJrdUSrS2dTPsi73PmQ0Vu31i6BKDwcat60vqk=# NOTE: This file will be automatically deleted in the first reconfigure run after 24 hours. [root@server-backend config]#https://blog.csdn.net/u012881331/article/details/84647261
5.配置ssl支持
https://docs.gitlab.com/omnibus/settings/nginx.html#enable-https
配置https 需要使用證書,此處使用阿里云的免費(fèi)證書(證書一年有效期,過期需要再申請(qǐng))
下載下來的證書放到/docker/gitlib/config/ssl目錄下
gitlab默認(rèn)使用.crt格式的私鑰,需要進(jìn)行格式轉(zhuǎn)換(.pem 直接改成crt即可)
修改 /etc/gitlab/gitlab.rb中 external_url變?yōu)閔ttps
Edit the external_url in /etc/gitlab/gitlab.rb:
# note the 'https' below external_url "https://gitlab.example.com"Disable Let’s Encrypt in /etc/gitlab/gitlab.rb:
letsencrypt['enable'] = false nginx['redirect_http_to_https'] = true完整的配置文件
# 配置https協(xié)議所使用的訪問地址,不加端口號(hào)默認(rèn)為443 external_url 'https://git.example.com' # 配置ssh協(xié)議所使用的訪問地址和端口 gitlab_rails['gitlab_ssh_host'] = 'git.example.com' gitlab_rails['gitlab_shell_ssh_port'] = 222 # 此端口是run時(shí)22端口映射的222端口 #配置ssl letsencrypt['enable'] = false nginx['redirect_http_to_https'] = trueNow, reconfigure GitLab:
sudo gitlab-ctl reconfigure6.初始化用戶
1.進(jìn)入到gitlab 的ssh命令行
[root@server-backend ~]# docker exec -it gitlab /bin/bash root@03cbecccf5c8:/#2.登錄到Gitlab服務(wù)器
root@03cbecccf5c8:/# gitlab-rails console production #如果執(zhí)行上面的指令提示 Usage: "rails console [options]" 則可能是Gitlab版本不一樣,然后參數(shù)方式不一樣,需要用如下方式 root@03cbecccf5c8:/# gitlab-rails console -e production3.查詢用戶
> user = User.where(username:"root").first => #<User id:1 @root>4.修改密碼
> user.password = "qwer1234" => "qwer1234"5.保存
> user.save! Enqueued ActionMailer::DeliveryJob (Job ID: 1f015e02-34bc-4b26-8e37-3101937b7ce1) to Sidekiq(mailers) with arguments: "DeviseMailer", "password_change", "deliver_now", #<GlobalID:0x00007fa6b83b1378 @uri=#<URI::GID gid://gitlab/User/1>> => true完整的執(zhí)行過程如下
root@3b22cfb3d2bf:/# gitlab-rails console -e production --------------------------------------------------------------------------------Ruby: ruby 2.7.2p137 (2020-10-01 revision 5445e04352) [x86_64-linux]GitLab: 14.2.3 (2324101daeb) FOSSGitLab Shell: 13.19.1PostgreSQL: 12.7 -------------------------------------------------------------------------------- Loading production environment (Rails 6.1.3.2) irb(main):001:0> user = User.where(username:"root").first => #<User id:1 @root> irb(main):003:0> user.password='12345678' => "12345678" irb(main):004:0> user.save! Enqueued ActionMailer::MailDeliveryJob (Job ID: f59cf638-e6e3-4200-b82f-136812e59fba) to Sidekiq(mailers) with arguments: "DeviseMailer", "password_change", "deliver_now", {:args=>[#<GlobalID:0x00007f2eb915dd78 @uri=#<URI::GID gid://gitlab/User/1>>]} => true irb(main):005:0>6.登錄
賬號(hào):root
密碼:qwer1234
6.配置郵箱登錄
配置郵箱服務(wù)的用途
有合并請(qǐng)求時(shí),郵件通知
賬號(hào)注冊(cè)時(shí),郵件驗(yàn)證
修改密碼時(shí),通過郵件修改
配置步驟:
1.開啟QQ郵箱的smtp服務(wù)(不建議使用163郵箱,發(fā)幾次之后,就不能發(fā)送)
設(shè)置–》賬戶–》smtp–》密保驗(yàn)證–》驗(yàn)證成功返回一串字符串,形狀如(ausdixersybgcgid)
保存返回的字符串
2.修改gitlab配置
vim /etc/gitlab/gitlab.rb
按/后輸入smtp_enable,找到下面這一串文本,進(jìn)行修改
?
按esc退出到命令行模式之后:wq 保存并退出gitlab-ctl reconfigure 3.測(cè)試郵件服務(wù)是否正常gitlab-rails consoleNotify.test_email('接收方郵件地址','郵件標(biāo)題','郵件內(nèi)容').deliver_now按回車,測(cè)試發(fā)送。復(fù)制代碼
開通smtp時(shí)返回的字符:
7.創(chuàng)建項(xiàng)目
8.創(chuàng)建ssh密鑰對(duì)
1、安裝git工具。
2、運(yùn)行g(shù)it bash here 在彈出框中輸入cd ~/.ssh/(如果彈出“No such file or directory“,則通過"mkdir ~/.ssh"語句創(chuàng)造.ssh文件夾)
3、輸入“ssh-keygen -t rsa -C “gitlab的用戶名” ”語句,然后回車,會(huì)出現(xiàn)設(shè)置密碼,可以直接多次回車跳過,這樣就生成秘鑰了,可以在.ssh文件夾下看到id_rsa和id_rsa.pub兩個(gè)文件,id_rsa.pub文件中的內(nèi)容就是你需要的ssh秘鑰。
ssh-keygen -t rsa -C “root”
關(guān)注【指尖架構(gòu)師】公眾號(hào),獲取更多資訊
總結(jié)
以上是生活随笔為你收集整理的使用docker安装gitlab以及gitlab简单使用的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 2021年四川高考成绩及录取结果查询,2
- 下一篇: TypeScript + React +