Centos8 + Docker + 公司内网环境(需设置代理) 搭建 配置 Gitlab

编程入门 行业动态 更新时间:2024-10-28 09:22:14

Centos8  + Docker + 公司<a href=https://www.elefans.com/category/jswz/34/1768788.html style=内网环境(需设置代理) 搭建 配置 Gitlab"/>

Centos8 + Docker + 公司内网环境(需设置代理) 搭建 配置 Gitlab

Centos8 + Docker + GitLab


一、GitLab架构图:

根据图,一目了然的了解底层使用了哪些技术!(新版本使用Puma代替Unicorn)

二、Centos 8前期装备

1、设置IP地址,最好固定IP地址,连接外网,配置dnf或yum代理(建议后面不要更换IP,个别网页访问会失败)
#---------------------------------------------------------------------------------------------#
#centos 8 默认使用dnf代替了yum,原yum配置文件(/etc/yum.conf)默认链接到dnf配置文件(/etc/dnf/dnf.conf)
# vim /etc/dnf/dnf.conf # 修改成如下

[main]
gpgcheck=1
installonly_limit=3
clean_requirements_on_remove=True
#best=True
proxy=http://Proxy_Ip:port
proxy_username=username
proxy_password=password

2、安装Gitlab所需要的依赖包(有则跳过这步):curl policycoreutils-python openssh-server openssh-clients
# dnf install -y curl policycoreutils-python openssh-server openssh-clients
3、启动sshd(远程进去的话,一般默认跳过这步)
# systemctl enable sshd     # 开机自启
# systemctl start sshd     # 启用sshd
4、防火墙开发使用到的http协议端口
# firewall-cmd --permanent --add-service=http——# 同 firewall-cmd --add-port=80/tcp --permanent # 更加端口自行更改
# systemctl reload firewalld  # 重新加载防火墙配置
5、更新系统的所有软件
# dnf update -y

三、安装docker 社区版(正式开始安装)

1.卸载旧版本docker

# dnf remove docker*

2.安装docker基础包

# dnf install -y yum-utils device-mapper-persistent-data lvm2

3.设置稳定仓库

# yum-config-manager --add-repo .repo

4.安装Docker Engine - Community --此命令会安装最新版本(latest)

# dnf install docker-ce docker-ce-cli containerd.io

5.可以安装指定版本

# dnf list docker-ce --showduplicates | sort -r  #查看版本
# sudo dnf install docker-ce-<VERSION_STRING> docker-ce-cli-<VERSION_STRING> containerd.io #安装指定版本

6.配置开机自启及docker启动

# systemctl enable docker
# systemctl start docker

7.配置docker代理(非内网环境跳过)
①默认情况下这个配置文件夹并不存在,我们要创建它

# mkdir -p /etc/systemd/system/docker.service.d

②创建一个文件 vim /etc/systemd/system/docker.service.d/http-proxy.conf

# [Service]
# Environment="HTTP_PROXY=:80/"

③如果有局域网或者国内的registry,我们还需要使用 NO_PROXY 变量声明一下

# [Service]
# Environment="HTTP_PROXY=:80/" "NO_PROXY=localhost,127.0.0.1“

④刷新systemd配置:

# sudo systemctl daemon-reload

⑤用系统命令验证环境变量加上去没:

# systemctl show --property=Environment docker
Environment=HTTP_PROXY=:80/

⑥更改docker默认的存储路径,将该字段修改为如下

# vim /usr/lib/systemd/system/docker.service
ExecStart=/usr/bin/dockerd --graph  /docker/docker

⑦重载和重启docker

# sudo systemctl enable docker
# sudo systemctl daemon-reload
# sudo systemctl restart docker
查看docker信息:Docker Root Dir值为修改后的路径
# sudo docker info

四、安装gitlab社区版(真正的正式开始安装)

1.获取gitlab镜像包

# docker pull gitlab/gitlab-ce
查看下载好的镜像包
# docker images
REPOSITORY                                TAG                 IMAGE ID            CREATED             SIZE
gitlab/gitlab-ce                          latest              8ab13771717b		2 weeks ago         2.04GB

2.在本机准备gitlab工作目录

# mkdir -p /docker/App/gitlab/{config,data,logs}

3.启动gitlab(关键步骤)

# docker run -d \--name gitlab \--hostname 10.102.10.239 \--restart always \-p 443:443 -p 80:80 -p 2222:22 \-v /docker/App/gitlab/config:/etc/gitlab \-v /docker/App/gitlab/data:/var/opt/gitlab \-v /docker/App/gitlab/logs:/var/log/gitlab \gitlab/gitlab-ce:latest 说明:-d:后台运行
--name:设置容器的名字;
--hostname:设置容器内主机的名字;《这里建议使用IP,后续克隆有用》
--restart:设置容器的重启策略,可选项: no | on-failure[:max-retries] | always | unless-stopped ;
-p(小写字母):映射端口,形式:[hostPort:]containerPort,如果不加主机端口,那么会在主机上生成随机端口;
-v(小写字母):挂载目录,形式:[HOST-DIR:]CONTAINER-DIR;

4.检查启动信息

# docker ps
---------------
正在启动中------->查看STATUS------->Up 7 seconds (health: starting)
---------------
CONTAINER ID        IMAGE                     COMMAND             CREATED             STATUS                            PORTS                                                            NAMES
98d8ae3393b3        gitlab/gitlab-ce:latest   "/assets/wrapper"   9 seconds ago       Up 7 seconds (health: starting)   0.0.0.0:80->80/tcp, 0.0.0.0:443->443/tcp, 0.0.0.0:2222->22/tcp   gitlab==================启动需要一定的时间,稍加等待后再查看===================# docker ps
---------------
启动成功------->查看STATUS-------->Up 4 minutes (healthy)
---------------
CONTAINER ID        IMAGE                     COMMAND             CREATED             STATUS                   PORTS                                                            NAMES
98d8ae3393b3        gitlab/gitlab-ce:latest   "/assets/wrapper"   4 minutes ago       Up 4 minutes (healthy)   0.0.0.0:80->80/tcp, 0.0.0.0:443->443/tcp, 0.0.0.0:2222->22/tcp   gitlab

5.再查看本机端口状态

[root@Gitlab /docker/App/gitlab]# netstat -nlt
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address           Foreign Address         State
tcp        0      0 0.0.0.0:111             0.0.0.0:*               LISTEN
tcp        0      0 192.168.122.1:53        0.0.0.0:*               LISTEN
tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN
tcp        0      0 0.0.0.0:5355            0.0.0.0:*               LISTEN
tcp6       0      0 :::2222                 :::*                    LISTEN
tcp6       0      0 :::111                  :::*                    LISTEN
tcp6       0      0 :::80                   :::*                    LISTEN
tcp6       0      0 :::22                   :::*                    LISTEN
tcp6       0      0 :::443                  :::*                    LISTEN
tcp6       0      0 :::5355                 :::*                    LISTEN

6.查看本机为gitlab容器新建的工作目录内容

# tree -L 2 /data/docker/gitlab/
[root@Gitlab /docker/App/gitlab]# tree -L 2 .
.
├── 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├── puma├── reconfigure├── redis├── redis-exporter├── sidekiq└── sshd

=================================================
到这就安装完成,且可以使用了!下面是一些配置和优化。

=================================================

五、更改gitlab.rb配置文件

1.gitlab涉及的配置文件的路径——(默认路径)
名称配置路径
gitlab配置文件/etc/gitlab/gitlab.rb
unicon配置文件(新版Puma代替了)/var/opt/gitlab/gitlab-rails/etc/unicon.rb
nginx配置文件/var/opt/gitlab/nginx/conf/gitlab-http.conf
gitlab仓库默认位置/var/opt/gitlab/git-data/repositories
2.gitlab模块的配置

# vim /etc/gitlab/gitlab.rb

# 访问地址配置
external_url 'http://192.168.2.87:8090'  #http 访问地址,端口不要有冲突
#-------------------代码库配置模块--------------------------------------
git_data_dirs({"default" => {"path" => "/data/gitlab/git-data" } #自定义代码库目录位置
})#-------------------prometheus监控配置模块--------------------------------------
prometheus['listen_address'] = 'localhost:9090'  # 修改prometheus监控默认使用的端口,防止冲突#-------------------邮件配置模块--------------------------------------
gitlab_rails['time_zone'] = 'Asia/Shanghai'	# 时区
gitlab_rails['gitlab_email_enabled'] = true # 启用邮件
gitlab_rails['gitlab_email_from'] = 'fangdong.xiao@qq'
gitlab_rails['gitlab_email_display_name'] = 'gitlab'
gitlab_rails['smtp_enable'] = true	# 启用smtp
gitlab_rails['smtp_address'] = "smtp.qq" 
gitlab_rails['smtp_port'] = 25	# 端口建议使用465,安全
gitlab_rails['smtp_user_name'] = "your_name"
gitlab_rails['smtp_password'] = "your_password"
gitlab_rails['smtp_domain'] = "qq" # 域名
gitlab_rails['smtp_authentication'] = "login" # 认证方式
gitlab_rails['smtp_enable_starttls_auto'] = true
gitlab_rails['smtp_tls'] = true
# 测试邮件服务是否正常
#        gitlab-ctl reconfigure
#        gitlab-rails console
#        Notify.test_email('接收方邮件地址','邮件标题','邮件内容').deliver_now
#        按回车,测试发送。
#-------------------备份模块-----------------------------------------
gitlab_rails['manage_backup_path'] = true  # 启动备份路径
gitlab_rails['backup_path'] = "/backup/gitlab/backups" #自定义备份目录
gitlab_rails['backup_keep_time'] = 2592000 #(30*24*3600) 自动清除30天前的备份文件
#-------------------postgresql数据库模块------------------------:-----
3.nginx模块的配置
nginx['listen_port']=8090    #修改nginx端口

创建备份:
  gitlab-rake gitlab:backup:create
备份的仓库恢复:
  gitlab-rake gitlab:backup:restore BACKUP=1483198680
  恢复时,选择的版本就是备份是产生的Unix时间戳。
注:恢复时,先停掉服务,以免双写导致数据错误。

Gitlab的服务:

sudo gitlab-ctl reconfigure    #初次配置完要运行的服务,重新加载配置
sudo gitlab-ctl start        #启动服务
sudo gitlab-ctl stop        #停止服务
sudo gitlab-ctl restart       #重启服务
sudo gitlab-ctl status        #查看状态
sudo gitlab-ctl show         #查看所有服务配置信息

常用命令:

说明命令
# 检查redis的日志gitlab-ctl tail redis
# 检查postgresql的日志gitlab-ctl tail postgresql
# 检查gitlab-workhorse的日志gitlab-ctl tail gitlab-workhorse
# 检查logrotate的日志gitlab-ctl tail logrotate
# 检查nginx的日志gitlab-ctl tail nginx
# 检查sidekiq的日志gitlab-ctl tail sidekiq
# 检查unicorn的日志gitlab-ctl tail unicorn
匠心制作

更多推荐

Centos8 + Docker + 公司内网环境(需设置代理) 搭建 配置 Gitlab

本文发布于:2024-02-11 03:04:42,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1678790.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:内网   环境   公司   Docker   Gitlab

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!