gitlab 简单使用
一 简介
二 安装
rpm安装: yum install https://mirrors.tuna.tsinghua.edu.cn/gitlab-ce/yum/el7/gitlab-ce-13.2.3-ce.0.el7.x86_64.rpm docker安装:
由于包太大了 使用本地导入
docker load -i ./gitlab.tar
mkdir /opt/gitlab GITLAB_HOME=/opt/gitlab # 数据持久化目录 docker run --detach \ --hostname gitlab.ctnrs.com \ --publish 443:443 --publish 80:80 --publish 2222:22 \ --name gitlab \ --restart always \ --volume $GITLAB_HOME/config:/etc/gitlab \ --volume $GITLAB_HOME/logs:/var/log/gitlab \ --volume $GITLAB_HOME/data:/var/opt/gitlab \ gitlab/gitlab-ce:latest
网络好也可以使用下面
GITLAB_HOME=/opt/gitlab docker run -d \ --name gitlab \ -p 443:443 \ -p 80:80 \ -p 2222:22 \ -v $GITLAB_HOME/config:/etc/gitlab \ -v $GITLAB_HOME/logs:/var/log/gitlab \ -v $GITLAB_HOME/data:/var/opt/gitlab \ -v /etc/localtime:/etc/localtime \ lizhenliang/gitlab-ce-zh:latest
本地路径 | 容器路径 | 用途 | |
$GITLAB_HOME/data
|
/var/opt/gitlab
|
应用程序数据
|
|
$GITLAB_HOME/logs
|
/var/log/gitlab
|
日志 | |
$GITLAB_HOME/config
|
/etc/gitlab
|
配置文件 | |
Whoops, GitLab is taking too much time to respond.
等待一会儿就正常
设置自己得密码
登录主页
三 配置SMTP(发邮件)
配置SMTP(发邮件): # vim /etc/gitlab/gitlab.rb
gitlab_rails['gitlab_email_from'] = 'zfno111@163.com'
gitlab_rails['smtp_enable'] = true
gitlab_rails['smtp_address'] = "smtp.163.com"
#没有加密就是25
gitlab_rails['smtp_port'] = 25
gitlab_rails['smtp_user_name'] = "zfno111@163.com"
#授权码
gitlab_rails['smtp_password'] = "DUITYZHUFCCFJMIR"
gitlab_rails['smtp_domain'] = "163.com"
gitlab_rails['smtp_authentication'] = "login"
gitlab_rails['smtp_enable_starttls_auto'] = true
gitlab_rails['smtp_tls'] = false
时区
Notify.test_email('1367615159@qq.com', 'zftest', 'zftest').deliver_now
四 配置HTTPS
配置HTTPS: 1、自签证书 2、上传证书文件到/etc/gitlab/ssl目录 3、修改配置文件指定证书 # vim /etc/gitlab/gitlab.rb external_url 'https://gitlab.ctnrs.com' # 访问使用的域名或者IP nginx['enable'] = true nginx['redirect_http_to_https'] = true #设置开启自动将HTTP跳转到HTTPS nginx['ssl_certificate'] = "/etc/gitlab/ssl/gitlab.ctnrs.com.pem" nginx['ssl_certificate_key'] = "/etc/gitlab/ssl/gitlab.ctnrs.com-key.pem“ 重新加载配置: docker restart gitlab
解压 工具
tar -zxvf ./cfssl.tar.gz
#放到指定目录
mv ./cfssl* /usr/bin/
自签CA 以及办法证书
[root@docker ssl]# cat ./certs.sh cat > ca-config.json <<EOF { "signing": { "default": { "expiry": "87600h" }, "profiles": { "server": { "expiry": "87600h", "usages": [ "signing", "key encipherment", "server auth", "client auth" ] } } } } EOF cat > ca-csr.json <<EOF { "CN": "gitlab", "key": { "algo": "rsa", "size": 2048 }, "names": [ { "C": "CN", "L": "Beijing", "ST": "Beijing" } ] } EOF cfssl gencert -initca ca-csr.json | cfssljson -bare ca - cat > gitlab.ctnrs.com-csr.json <<EOF { "CN": "gitlab.ctnrs.com", "hosts": [], "key": { "algo": "rsa", "size": 2048 }, "names": [ { "C": "CN", "L": "BeiJing", "ST": "BeiJing" } ] } EOF cfssl gencert -ca=ca.pem -ca-key=ca-key.pem -config=ca-config.json -profile=server gitlab.ctnrs.com-csr.json | cfssljson -bare gitlab.ctnrs.com
执行脚本
bash ./certs.sh
创建ssl目录
mkdir /opt/gitlab/config/ssl
将证书和私钥拷贝过去
cp ./gitlab.ctnrs.com.pem /opt/gitlab/config/ssl/
cp ./gitlab.ctnrs.com-key.pem /opt/gitlab/config/ssl/
修改配置文件
# vim /etc/gitlab/gitlab.rb external_url 'https://gitlab.ctnrs.com' # 访问使用的域名或者IP nginx['enable'] = true nginx['redirect_http_to_https'] = true #设置开启自动将HTTP跳转到HTTPS nginx['ssl_certificate'] = "/etc/gitlab/ssl/gitlab.ctnrs.com.pem" nginx['ssl_certificate_key'] = "/etc/gitlab/ssl/gitlab.ctnrs.com-key.pem“
关于证书相关信息可以参考
https://www.jianshu.com/p/a9497de4cbff
五 常用的管理命令
• gitlab-ctl Gitlab管理工具 • gitlab-rails • gitlab-redis-cli 访问Redis数据库 • gitlab-psql 访问PGSQL数据库 • gitlab-rake 备份与恢复 • gitlab-backup 12.1版本以后增加的备份与恢复工具