1. 配置鏡像加速器
sudo mkdir -p /etc/docker
sudo tee /etc/docker/daemon.json <<-'EOF'
{
"registry-mirrors": ["https://xxxxxx.mirror.aliyuncs.com"]
}
EOF
sudo systemctl daemon-reload
sudo systemctl restart docker
2. 獲取gitlab鏡像包
[root@VM_0_6_centos data]# docker pull gitlab/gitlab-ce
Using default tag: latest
latest: Pulling from gitlab/gitlab-ce
3386e6af03b0: Pull complete
49ac0bbe6c8e: Pull complete
d1983a67e104: Pull complete
1a0f3a523f04: Pull complete
0a1871e024e9: Pull complete
22db415dc935: Pull complete
7a635a8736d3: Pull complete
cc0ef2dfa7c2: Pull complete
816bca05932d: Pull complete
9aff335224a3: Pull complete
Digest: sha256:ad3988896b5c7ccf8272bc6987ce5cff132164e9a6bfc252976b6a2a98bd4896
Status: Downloaded newer image for gitlab/gitlab-ce:latest
docker.io/gitlab/gitlab-ce:latest
[root@VM_0_6_centos data]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
gitlab/gitlab-ce latest 939d1ad829ac 4 days ago 1.84GB
hello-world latest fce289e99eb9 11 months ago 1.84kB
3. 在本機(jī)準(zhǔn)備gitlab工作目錄
在本機(jī)建立的3個(gè)目錄是為了gitlab容器通過(guò)掛載本機(jī)目錄啟動(dòng)后可以映射配置文件,數(shù)據(jù)文件谓松,日志文件到本機(jī),然后后續(xù)就可以直接在本機(jī)查看和編輯了,不用再進(jìn)容器操作倔毙。
[root@VM_0_6_centos ~]# mkdir -p /data/docker/gitlab/{config,data,logs}
4. 啟動(dòng)gitlab
--publish 暴露了容器的三個(gè)端口, 分別是https對(duì)應(yīng)的443, http對(duì)應(yīng)80以及ssh對(duì)應(yīng)的22(如果不需要配置https, 可以不暴露)
--memory 限制容器最大內(nèi)存暫用4G, 這是官方推薦的
--volume 指定掛載目錄, 這個(gè)便于我們?cè)诒镜貍浞莺托薷娜萜鞯南嚓P(guān)數(shù)據(jù)
[root@server-10 ~]# docker run -d \
--name gitlab \
--hostname gitlab \
--memory 4g \
--restart always \
-p 4443:443 -p 8888:80 -p 2222:22 \
-v /data/docker/gitlab/config:/etc/gitlab \
-v /data/docker/gitlab/data:/var/opt/gitlab \
-v /data/docker/gitlab/logs:/var/log/gitlab \
gitlab/gitlab-ce:latest
5. 檢查啟動(dòng)信息
[root@VM_0_6_centos data]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
e9fbcdb96669 gitlab/gitlab-ce:latest "/assets/wrapper" 29 seconds ago Up 28 seconds (health: starting) 0.0.0.0:2222->22/tcp, 0.0.0.0:8888->80/tcp, 0.0.0.0:4443->443/tcp gitlab
啟動(dòng)需要一段時(shí)間(注意STATUS
)
[root@VM_0_6_centos data]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
e9fbcdb96669 gitlab/gitlab-ce:latest "/assets/wrapper" 4 minutes ago Up 4 minutes (healthy) 0.0.0.0:2222->22/tcp, 0.0.0.0:8888->80/tcp, 0.0.0.0:4443->443/tcp gitlab
查看本機(jī)端口狀態(tài)
[root@VM_0_6_centos data]# netstat -tnl
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN
tcp6 0 0 :::2222 :::* LISTEN
tcp6 0 0 :::8888 :::* LISTEN
tcp6 0 0 :::4443 :::* LISTEN
查看本機(jī)為gitlab容器新建的工作目錄內(nèi)容
[root@VM_0_6_centos ~]# tree -L 2 /data/docker/gitlab/
/data/docker/gitlab/
├── config
│ ├── gitlab.rb
│ ├── gitlab-secrets.json
│ ├── ssh_host_ecdsa_key
│ ├── ssh_host_ecdsa_key.pub
│ ├── ssh_host_ed25519_key
│ ├── ssh_host_ed25519_key.pub
│ ├── ssh_host_rsa_key
│ ├── ssh_host_rsa_key.pub
│ └── trusted-certs
├── data
│ ├── alertmanager
│ ├── backups
│ ├── bootstrapped
│ ├── gitaly
│ ├── git-data
│ ├── gitlab-ci
│ ├── gitlab-exporter
│ ├── gitlab-rails
│ ├── gitlab-shell
│ ├── gitlab-workhorse
│ ├── grafana
│ ├── logrotate
│ ├── nginx
│ ├── postgres-exporter
│ ├── postgresql
│ ├── prometheus
│ ├── public_attributes.json
│ ├── redis
│ └── trusted-certs-directory-hash
└── logs
├── alertmanager
├── gitaly
├── gitlab-exporter
├── gitlab-rails
├── gitlab-shell
├── gitlab-workhorse
├── grafana
├── logrotate
├── nginx
├── postgres-exporter
├── postgresql
├── prometheus
├── reconfigure
├── redis
├── redis-exporter
├── sidekiq
├── sshd
└── unicorn
38 directories, 11 files
6. 登錄gitlab
7. 設(shè)置郵件服務(wù)
服務(wù)器名稱 | 服務(wù)器地址 | SSL協(xié)議端口號(hào) | 非SSL協(xié)議端口號(hào) |
---|---|---|---|
SMTP | smtp.163.com | 465/994 | 25 |
smtp_port對(duì)應(yīng)的端口25可能被阿里云或騰訊云封禁,需要申請(qǐng)解禁
[root@VM_0_6_centos ~]# vi /data/docker/gitlab/config/gitlab.rb
user['git_user_email'] = "username@163.com"
gitlab_rails['gitlab_email_enabled'] = true
gitlab_rails['gitlab_email_from'] = 'username@163.com'
gitlab_rails['smtp_enable'] = true
gitlab_rails['smtp_address'] = "smtp.163.com"
gitlab_rails['smtp_port'] = 465
gitlab_rails['smtp_user_name'] = "username@163.com"
gitlab_rails['smtp_password'] = "xxxxx"
gitlab_rails['smtp_domain'] = "163.com"
gitlab_rails['smtp_authentication'] = "login"
gitlab_rails['smtp_enable_starttls_auto'] = true
gitlab_rails['smtp_tls'] = true
gitlab_rails['smtp_openssl_verify_mode'] = 'none'
重新配置服務(wù)械哟、測(cè)試
root@gitlab:/# ggitlab-ctl reconfigure
root@gitlab:/# gitlab-ctl restart
root@gitlab:/# gitlab-rails console
--------------------------------------------------------------------------------
GitLab: 12.6.0-ee (fc376e40baf)
GitLab Shell: 10.3.0
PostgreSQL: 10.9
--------------------------------------------------------------------------------
Loading production environment (Rails 5.2.3)
irb(main):001:0> Notify.test_email('xxxxx@qq.com','title','lalalalalallalalalaalalalal').deliver_now
Notify#test_email: processed outbound mail in 1.9ms
Sent mail to 1169023540@qq.com (604.3ms)
Date: Thu, 26 Dec 2019 01:59:31 +0000
From: GitLab <xxxx@163.com>
Reply-To: GitLab <noreply@gitlab>
To: xxxxxx@qq.com
Message-ID: <5e0414031321e_c663fe2f9fd39981848f@gitlab.mail>
Subject: title
Mime-Version: 1.0
Content-Type: text/html;
charset=UTF-8
Content-Transfer-Encoding: 7bit
Auto-Submitted: auto-generated
X-Auto-Response-Suppress: All
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/REC-html40/loose.dtd">
<html><body><p>lalalalalallalalalaalalalal</p></body></html>
=> #<Mail::Message:70243781477360, Multipart: false, Headers: <Date: Thu, 26 Dec 2019 01:59:31 +0000>, <From: GitLab <zinxcc@163.com>>, <Reply-To: GitLab <noreply@gitlab>>, <To: 1169023540@qq.com>, <Message-ID: <5e0414031321e_c663fe2f9fd39981848f@gitlab.mail>>, <Subject: title>, <Mime-Version: 1.0>, <Content-Type: text/html; charset=UTF-8>, <Content-Transfer-Encoding: 7bit>, <Auto-Submitted: auto-generated>, <X-Auto-Response-Suppress: All>>