距离上一次更新该文章已经过了 387 天,文章所描述的內容可能已经发生变化,请留意。
安装 官方文档链接:https://docs.gitlab.cn/jh/index.html
使用外部 PostgreSQL 服务配置 GitLab:https://docs.gitlab.cn/jh/administration/postgresql/external.html
以下安装方式使用内置postgresql
安装必要组件 1 yum -y install curl policycoreutils-python openssh-server perl
rpm方式 源地址:https://mirrors.tuna.tsinghua.edu.cn/gitlab-ce/yum/el7/
1 2 3 wget https://mirrors.tuna.tsinghua.edu.cn/gitlab-ce/yum/el7/gitlab-ce-12.9.0-ce.0.el7.x86_64.rpm rpm -ivh gitlab-ce-12.9.0-ce.0.el7.x86_64.rpm
Docker方式 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 mkdir -p ~/data/gitlab/config ~/data/gitlab/logs ~/data/gitlab/data docker pull gitlab/gitlab-ce:12.9.0-ce.0 docker run -d -p 443:443 -p 80:80 -p 222:22 --name gitlab --restart always -v /home/gitlab/config:/etc/gitlab -v /home/gitlab/logs:/var/log/gitlab -v /home/gitlab/data:/var/opt/gitlab gitlab/gitlab-ce:12.9.0-ce.0 docker exec -it gitlab bash vim /etc/gitlab.rb # 编辑站点地址 gitlab-ctl reconfigure # 配置 docker restart gitlab # 服务控制 docker start gitlab docker stop gitlab docker rm gitlab
Docker-compose方式 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 version: '3' services: gitlab: image: 'gitlab/gitlab-ce:13.5.7-ce.0' restart: 'no' environment: TZ: 'Asia/Shanghai' GITLAB_OMNIBUS_CONFIG: | external_url 'http://192.168.56.100' gitlab_rails['gitlab_shell_ssh_port'] = 2222 unicorn['port'] = 8888 nginx['listen_port'] = 80 ports: - '80:80' - '443:443' - '2222:22' volumes: - ./gitlab/config:/etc/gitlab - ./gitlab/repo:/var/opt/gitlab - ./gitlab/logs:/var/log/gitlab
GitLab 域名/IP
或端口
设置【无论docker还是rpm都需要照下进行修改】 编辑gitlab.yml配置文件(如果出现无法导出项目时进行此操作,如果没有,则跳过此步) 1 vim /opt/gitlab/embedded/service/gitlab-rails/config/gitlab.yml
找到host,并修改为你要配置的域名或IP
1 2 3 4 5 6 gitlab: host: 192.168.0.201 port: 8080 https: false
1 vim /etc/gitlab/gitlab.rb
找到external_url,修改成对应的域名或IP
1 2 3 4 5 external_url 'http://192.168.0.201:8080' gitlab_rails['gitlab_shell_ssh_port' ] = 222
更新配置 GitLab指令 1 2 3 4 gitlab-ctl start gitlab-ctl status gitlab-ctl stop gitlab-ctl restart
k8s安装方式
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 --- kind: Deployment apiVersion: apps/v1 metadata: labels: k8s-app: gitlab name: gitlab namespace: devops spec: replicas: 1 revisionHistoryLimit: 10 selector: matchLabels: k8s-app: gitlab template: metadata: labels: k8s-app: gitlab namespace: devops name: gitlab spec: containers: - name: gitlab image: gitlab/gitlab-ce:12.9.0-ce.0 imagePullPolicy: Always ports: - containerPort: 30088 name: web protocol: TCP - containerPort: 22 name: agent protocol: TCP volumeMounts: - name: gitlab-conf mountPath: /etc/gitlab - name: gitlab-log mountPath: /var/log/gitlab - name: gitlab-data mountPath: /var/opt/gitlab env: - name: gitlab_HOME value: /var/lib/gitlab volumes: - name: gitlab-conf hostPath: path: /data/devops/gitlab/config type: DirectoryOrCreate - name: gitlab-log hostPath: path: /data/devops/gitlab/logs type: DirectoryOrCreate - name: gitlab-data hostPath: path: /data/devops/gitlab/data type: DirectoryOrCreate serviceAccountName: gitlab --- apiVersion: v1 kind: Service metadata: labels: k8s-app: gitlab name: gitlab namespace: devops spec: type: NodePort ports: - name: web port: 30088 targetPort: 30088 nodePort: 30088 - name: slave port: 22 targetPort: 22 nodePort: 30022 selector: k8s-app: gitlab --- apiVersion: v1 kind: ServiceAccount metadata: labels: k8s-app: gitlab name: gitlab namespace: devops --- kind: Role apiVersion: rbac.authorization.k8s.io/v1 metadata: name: gitlab namespace: devops rules: - apiGroups: ["" ] resources: ["pods" ,"pods/exec" ,"pods/log" ,"secrets" ,"nodes" ] verbs: ["create" ,"delete" ,"get" ,"list" ,"patch" ,"update" ,"watch" ] --- apiVersion: rbac.authorization.k8s.io/v1 kind: RoleBinding metadata: name: gitlab namespace: devops roleRef: apiGroup: rbac.authorization.k8s.io kind: Role name: gitlab subjects: - kind: ServiceAccount name: gitlab namespace: devops --- apiVersion: rbac.authorization.k8s.io/v1 kind: ClusterRole metadata: name: gitlab rules: - apiGroups: ["" ] resources: ["pods" ,"pods/exec" ,"pods/log" ,"secrets" ,"nodes" ] verbs: ["create" ,"delete" ,"get" ,"list" ,"patch" ,"update" ,"watch" ] --- apiVersion: rbac.authorization.k8s.io/v1 kind: ClusterRoleBinding metadata: name: gitlab roleRef: apiGroup: rbac.authorization.k8s.io kind: ClusterRole name: gitlab subjects: - kind: ServiceAccount name: gitlab namespace: devops
备份与还原 官方文档参考:https://docs.gitlab.cn/jh/raketasks/backup_restore.html
Gitlab备份、迁移、恢复和升级参考:https://cloud.tencent.com/developer/article/1622317
更新 gitlab跨版本升级 gitlab的升级不能随意升级,需要根据官方文档的升级路线进行升级。如当前版本为10.6.3 -> 目标版本为13.5.7 .
不能直接升级为13.5.7这个版本,需要按 该地址-官方upgrade-path 指示进行升级
配置仓库【任选其一,国内源下载会快一些】 官方仓库 1 curl https://packages.gitlab.com/install/repositories/gitlab/gitlab-ce/script.rpm.sh | bash
国内源仓库 1 2 3 4 5 6 7 8 9 10 11 12 # 第一步 vi /etc/yum.repos.d/gitlab_gitlab-ce.repo # 第二步: 添加如下内容在最下面 [gitlab-ce] name=Gitlab CE Repository baseurl=https://mirrors.tuna.tsinghua.edu.cn/gitlab-ce/yum/el$releasever/ gpgcheck=0 enabled=1 # 第三步 yum makecache fast
然后按照上图,从低到高一步一步执行 yum install gitlab-ce-{版本}
就好 每次升级完一个版本,可以登录进行验证,如果页面出现502,不要惊慌,有可能是gitlab启动中
观察日志 观察日志,查看是否有错误
1 2 3 4 5 6 7 8 # 查看所有的logs; 按 Ctrl-C 退出 sudo gitlab-ctl tail # 拉取/var/log/gitlab下子目录的日志 sudo gitlab-ctl tail gitlab-rails # 拉取某个指定的日志文件 sudo gitlab-ctl tail nginx/gitlab_error.log
Gitlab关闭停用其他不需要的组件 默认运行的组件
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 [root@gitlab opt]# gitlab-ctl status run: alertmanager: (pid 3474) 1289193s; run: log: (pid 1915) 1260609s run: gitaly: (pid 3581) 1289192s; run: log: (pid 1901) 1260609s run: gitlab-exporter: (pid 3536) 1289193s; run: log: (pid 1909) 1260609s run: gitlab-kas: (pid 3475) 1289193s; run: log: (pid 1924) 1260609s run: gitlab-workhorse: (pid 3476) 1289193s; run: log: (pid 1914) 1260609s run: grafana: (pid 3482) 1289193s; run: log: (pid 1906) 1260609s run: logrotate: (pid 68197) 355s; run: log: (pid 1903) 1260609s run: nginx: (pid 3494) 1289193s; run: log: (pid 1912) 1260609s run: node-exporter: (pid 3493) 1289193s; run: log: (pid 1908) 1260609s run: postgres-exporter: (pid 3495) 1289193s; run: log: (pid 1918) 1260609s run: postgresql: (pid 3561) 1289193s; run: log: (pid 1911) 1260609s run: prometheus: (pid 3512) 1289193s; run: log: (pid 1900) 1260609s run: puma: (pid 3576) 1289194s; run: log: (pid 1905) 1260610s run: redis: (pid 3547) 1289194s; run: log: (pid 1921) 1260610s run: redis-exporter: (pid 3518) 1289194s; run: log: (pid 1904) 1260610s run: sidekiq: (pid 3602) 1289193s; run: log: (pid 1922) 1260610s
配置文件将相关配置项enable值改为 false
1 2 3 4 5 6 redis_exporter['enable'] = false postgres_exporter['enable'] = false node_exporter['enable'] = false grafana['enable'] = false prometheus['enable'] = false alertmanager['enable'] = false
重新加载配置