一、基于docker-compose
安装可以发邮件版的gitlab
新建 mkdir /usr/local/docker/gitlab
目录,在此目录下新建docker-compose.yml
, 配置如下:
1. 新建网易或qq版的docker-compose.yml
1.1 gitlab邮箱版(网易邮箱发送)
version: '3'
services:
gitlab:
image: 'twang2218/gitlab-ce-zh'
hostname: '192.168.118.131'
environment:
TZ: 'Asia/Shanghai'
GITLAB_OMNIBUS_CONFIG: |
external_url 'http://192.168.118.131:8088'
gitlab_rails['gitlab_shell_ssh_port'] = 2222
unicorn['port'] = 8088
nginx['listen_port'] = 80
external_url 'http://192.168.118.131:8088'
gitlab_rails['gitlab_shell_ssh_port'] = 2222
gitlab_rails['time_zone'] = 'Asia/Shanghai'
# email setting
gitlab_rails['smtp_enable'] = true
gitlab_rails['smtp_address'] = "smtp.163.com"
gitlab_rails['smtp_port'] = 25
gitlab_rails['smtp_user_name'] = "网易邮箱"
gitlab_rails['smtp_password'] = "网易邮箱密码"
gitlab_rails['smtp_domain'] = "163.com"
gitlab_rails['smtp_authentication'] = "login"
gitlab_rails['smtp_enable_starttls_auto'] = true
gitlab_rails['gitlab_email_from'] = "[email protected]"
gitlab_rails['smtp_tls'] = false
gitlab_rails['smtp_openssl_verify_mode'] = 'peer'
user["git_user_email"] = "[email protected]"
ports:
- '8088:80'
- '443:443'
- '2222:22'
volumes:
- ./config:/etc/gitlab
- ./data:/var/opt/gitlab
- ./logs:/var/log/gitlab
1.2 gitlab邮箱版(网易邮箱发送)
version: '3'
services:
gitlab:
image: 'twang2218/gitlab-ce-zh'
restart: always
hostname: '192.168.118.131'
environment:
TZ: 'Asia/Shanghai'
GITLAB_OMNIBUS_CONFIG: |
external_url 'http://192.168.118.131:8088'
gitlab_rails['gitlab_shell_ssh_port'] = 2222
unicorn['port'] = 8088
nginx['listen_port'] = 80
external_url 'http://192.168.118.131:8088'
gitlab_rails['time_zone'] = 'Asia/Shanghai'
# email setting
gitlab_rails['smtp_enable'] = true
gitlab_rails['smtp_address'] = "smtp.qq.com"
# 部署上阿里云服务器后如果25端口不行可以换465或者587端口尝试
gitlab_rails['smtp_port'] = 465
gitlab_rails['smtp_user_name'] = "qq邮箱"
gitlab_rails['smtp_password'] = "授权码"
gitlab_rails['smtp_domain'] = "qq.com"
gitlab_rails['smtp_authentication'] = "login"
gitlab_rails['smtp_enable_starttls_auto'] = true
gitlab_rails['gitlab_email_from'] = "[email protected]"
gitlab_rails['smtp_tls'] = true
gitlab_rails['smtp_openssl_verify_mode'] = 'peer'
user["git_user_email"] = "[email protected]"
ports:
- '8088:80'
- '443:443'
- '2222:22'
volumes:
- ./config:/etc/gitlab
- ./data:/var/opt/gitlab
- ./logs:/var/log/gitlab
2. 配置好后,启动docker-compose
,并访问地址:http://ip
,若端口号为8080,则http://ip:8080
端口默认是 80,若端口号为8080,则外部访问地址为 8080
命令如下:
docker-compose up
注意: 因gitlab启动较慢,需要较久的时间,要耐心等待。
访问效果如下:
- 设置管理员初始密码,密码必须大于8位,我的是
12345678
- 配置完成后登陆,默认的管理员账号为
root
3. 第一次使用GitLab的基本设置
再点击设置,进入设置。
1. 账号和限制,将Gravatar enabled(启用Gravatar头像)选项去掉,因为有时候获取头像需要翻墙,会造成加载缓慢或者访问不通。
2. 注册限制,将启用注册的勾去掉(主要看情况使用,但一般不用勾选)。
点击进入管理区域,为自己新建一个管理员账号
3. 为自己创建一个管理员账号,一般不会直接操作root账户,因为root账户的权限太大了。
同时权限级别为:管理员
4. 编辑用户的密码
如下:
同时权限级别为:管理员
5. root用户退出,管理员进行登陆,登陆之后重新设置密码(12345678)并再次进行重新登陆
二、gitlab
创建项目
1. 新建项目,并给项目取名字。
2. 初始化项目
3. 添加自述文件,内容如下
# 第一个gitlab项目
4. 将代码进行拉取,此后操作和github的使用一样,无非是拉取代码,创建分支,提交代码。
但,注意:在公司中,一般是拉取代码后,创建分支,实现相关功能后,提交代码(先不要推送),然后再次拉取代码,再将本地代码推送远端。
三、GitHub使用SSH免密登陆
1. 生成 SSH KEY
使用 ssh-keygen 工具生成,位置在 Git 安装目录下,我的是 C:\Program Files\Git\usr\bin
,在此目录进入cmd,并输入命令:
ssh-keygen -t rsa -C "[email protected]"
如:
ssh-keygen -t rsa -C "[email protected]"
执行效果:
Generating public/private rsa key pair.
Enter file in which to save the key (/c/Users/Administrator/.ssh/id_rsa):
/c/Users/Administrator/.ssh/id_rsa already exists.
Overwrite (y/n)? y
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /c/Users/Administrator/.ssh/id_rsa.
Your public key has been saved in /c/Users/Administrator/.ssh/id_rsa.pub.
The key fingerprint is:
SHA256:HXH7EEJ6MX8Szr4k7ew3gEFVkXK8ags6vDzCo3BI9Kg [email protected]
The key's randomart image is:
+---[RSA 2048]----+
| .*.=ooo |
| ..X.++ |
| . ..o Bo.. |
| . o o.+ =. |
| o . S oo+.. |
| o . o=+. |
|E o .. . . o+o |
| o +.= .. o |
| .. oo+ .. . |
+----[SHA256]-----+
2. 复制 SSH-KEY 信息到 GitLab
秘钥位置在:C:\Users\Administrator\.ssh
目录下,找到id_rsa.pub
并使用编辑器打开,如:
登录 GitLab,点击“用户头像”-->“设置”-->“SSH 密钥”。即可实现免密登陆,为持续集成持续部署打下基础。
3. 修改git的网络配置:
右键--》TortoiseGit(T) --> 设置--》网络--》SSH客户端,更改SSH客户端的配置如下图所示
选择完成后点击应用按钮,有可能不生效,如果不生效勾选使用代理服务器按钮,再点击应用,应用生效后,再去掉代理服务器的勾选。
Linux 实现gitlab的免密登陆
1. 输入命令
ssh-keygen -t rsa -C "[email protected]"
输入命令完成后点击三次回车,输出结果如下:
Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa):
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /root/.ssh/id_rsa.
Your public key has been saved in /root/.ssh/id_rsa.pub.
The key fingerprint is:
SHA256:3UC2c5VnaUyCRpDVg9ikrqgVHrMMBwpTxhd4ehlNNGI [email protected]
The key's randomart image is:
+---[RSA 2048]----+
| .o.E=+ .@++.+o.|
| oo.+... =.* +o+o|
|o = o .= . oo |
|..o + .. = |
| . o = S.. . |
| = * . |
| * . |
| o |
| . |
+----[SHA256]-----+
2.进入/root/.ssh/
目录
cd /root/.ssh/
cat id_rsa.pub
结果如下:
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQC+e3rwv/k1K+iDw0Ab0h1ljJY1LLi+hPS8vulPPeyE3PXgNj1u5zC2C65xjpE9WATtaw2EW62dgVBp2enp2ArNUDiwga4HO7cbLOVzB5b6eW0MK2xjK8Km8DprZMiGla0NbOWucEMnVtjedb/e74UuhG/As6iASyxDbzMg75oA6j1u0PmuS15RZLjbfigTlzwxy1HK1O32yJ1lbH78TdnP4YtwrFZ0bJ3A1PqUDTU7TaYrRetugSOWS8/u8ZnoXfnLYKfSPDlW8e+e6znMJbm8pEPPEJ4nnKRNr12KB77/bER0DlqrU+NkQ1sDD7ZeRplup7b+vgn5UxacheuYEbb5 [email protected]
3.进入gitlab进行如下操作
gitlab
基本调试命令
docker exec -it gitlab-email_gitlab_1 bin/bash
进入容器后,可以使用下列命令进行调试邮箱发送所出现的问题
gitlab-rails console production
查看ActionMailer delivery_method以确保其符合您的预期。如果配置了SMTP,则应显示:smtp。如果您使用的是Sendmail,则应显示:sendmail:
ActionMailer::Base.delivery_method
如果您使用的是SMTP,请检查邮件设置:
ActionMailer::Base.smtp_settings
Notify.test_email('[email protected]', 'Hello World', 'This is a test message').deliver_now