# Gitlab-Local **Repository Path**: rothschildx/gitlab-local ## Basic Information - **Project Name**: Gitlab-Local - **Description**: Gitlab-CE running on CentOS VMWare. Running locally with LAN - **Primary Language**: Unknown - **License**: Not specified - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2023-09-19 - **Last Updated**: 2023-10-27 ## Categories & Tags **Categories**: Uncategorized **Tags**: GITLAB ## README #### 一、概述 GitLab是一款使用Ruby on Rails 开发的企业级代码托管平台系统,类似于Github和Gitee。该系统分社区版(gitlab-ce) 和企业版(gitlab-ee,收费)。 #### 二、准备 ##### 1、PC机 准备一台用于搭建GitLab的虚拟PC,假设该虚拟PC的IP为192.168.1.100,内存为8G([官网](https://docs.gitlab.cn/jh/install/requirements.html#内存)要求内存最小4G,否则可能无法正常运行) #### 三、安装 ##### 1、下载 下载地址:https://packages.gitlab.com/gitlab/gitlab-ce ,这里下载gitlab-ce-15.4.5-ce.0.el7.x86_64.rpm; ##### 2、上传 将gitlab-ce-15.4.5-ce.0.el7.x86_64.rpm文件上传至/opt目录,该文件比较大,上传过程大约需要持续1分钟; ##### 3、安装 ```shell [root@localhost ~]# rpm -ivh /opt/gitlab-ce-15.4.5-ce.0.el7.x86_64.rpm 警告:/opt/gitlab-ce-15.4.5-ce.0.el7.x86_64.rpm: 头V4 RSA/SHA1 Signature, 密钥 ID f27eab47: NOKEY 准备中... ################################# [100%] 正在升级/安装... 1:gitlab-ce-15.4.5-ce.0.el7 ################################# [100%] It looks like GitLab has not been configured yet; skipping the upgrade script. *. *. *** *** ***** ***** .****** ******* ******** ******** ,,,,,,,,,***********,,,,,,,,, ,,,,,,,,,,,*********,,,,,,,,,,, .,,,,,,,,,,,*******,,,,,,,,,,,, ,,,,,,,,,*****,,,,,,,,,. ,,,,,,,****,,,,,, .,,,***,,,, ,*,. _______ __ __ __ / ____(_) /_/ / ____ _/ /_ / / __/ / __/ / / __ `/ __ \ / /_/ / / /_/ /___/ /_/ / /_/ / \____/_/\__/_____/\__,_/_.___/ Thank you for installing GitLab! GitLab was unable to detect a valid hostname for your instance. Please configure a URL for your GitLab instance by setting `external_url` configuration in /etc/gitlab/gitlab.rb file. Then, you can start your GitLab instance by running the following command: sudo gitlab-ctl reconfigure For a comprehensive list of configuration options please see the Omnibus GitLab readme https://gitlab.com/gitlab-org/omnibus-gitlab/blob/master/README.md Help us improve the installation experience, let us know how we did with a 1 minute survey: https://gitlab.fra1.qualtrics.com/jfe/form/SV_6kVqZANThUQ1bZb?installation=omnibus&release=15-4 [root@localhost ~]# ``` 说明: > 安装过程大约需要持续2分钟; > > 无论gitlab-ce-15.4.5-ce.0.el7.x86_64.rpm文件放到哪个目录,rpm -ivh命令默认都会将gitlab安装到/opt/gitlab/目录。 ##### 4、删除 ```shell [root@localhost ~]# rm -f /opt/gitlab-ce-15.4.5-ce.0.el7.x86_64.rpm ``` ##### 5、配置 修改/etc/gitlab/gitlab.rb文件,操作如下: a、设置外部url ``` # 文件32行 external_url 'http://192.168.1.100:8989' ``` b、设置时区 ``` # 文件68行 gitlab_rails['time_zone'] = 'Asia/Shanghai' ``` c、设置数据存储地址 ``` # 文件629行 git_data_dirs({ "default" => { "path" => "/usr/local/gitlab/data" }, "alternative" => { "path" => "/usr/local/gitlab/data/backup" } }) ``` 说明: ​ default:数据主存储路径; ​ alternative:数据存储备份路径,为避免因磁盘毁坏丢失源码,故添加数据备份路径。 d、设置sidekiq最大并发量 ``` # 文件1051行 sidekiq['max_concurrency'] = 20 ``` e、设置postgresql ``` # 文件1136行 postgresql['shared_buffers'] = "128MB" # 文件1221行 postgresql['max_worker_processes'] = 4 ``` f、修改nginx默认端口,避免冲突 ``` # 文件1457行 nginx['listen_port'] = 8989 ``` 注意:必须和外部url中端口号一致 g、关闭prometheus监控 ``` # 文件2222行 prometheus_monitoring['enable'] = false ``` ##### 6、重载 重新加载GitLab配置。 ```shell [root@localhost ~]# gitlab-ctl reconfigure [2022-11-25T21:30:02+08:00] INFO: Started Cinc Zero at chefzero://localhost:1 with repository at /opt/gitlab/embedded (One version per cookbook) Cinc Client, version 17.10.0 Patents: https://www.chef.io/patents Infra Phase starting [2022-11-25T21:30:02+08:00] INFO: *** Cinc Client 17.10.0 *** ...省略... Running handlers: [2022-11-25T21:41:43+08:00] INFO: Running report handlers Running handlers complete [2022-11-25T21:41:43+08:00] INFO: Report handlers complete Infra Phase complete, 579/1537 resources updated in 11 minutes 41 seconds Notes: Default admin account has been configured with following details: Username: root Password: You didn't opt-in to print initial root password to STDOUT. Password stored to /etc/gitlab/initial_root_password. This file will be cleaned up in first reconfigure run after 24 hours. NOTE: Because these credentials might be present in your log files in plain text, it is highly recommended to reset the password following https://docs.gitlab.com/ee/security/reset_user_password.html#reset-your-root-password. gitlab Reconfigured! [root@localhost ~]# ``` 说明:配置重载过程大约需要**5**分钟。 ##### 7、重启 重新启动GitLab。 ```shell [root@localhost ~]# gitlab-ctl restart ok: run: gitaly: (pid 13539) 1s ok: run: gitlab-kas: (pid 13563) 0s ok: run: gitlab-workhorse: (pid 13574) 0s ok: run: logrotate: (pid 13586) 1s ok: run: nginx: (pid 13600) 0s ok: run: postgresql: (pid 13610) 1s ok: run: puma: (pid 13629) 0s ok: run: redis: (pid 13634) 1s ok: run: sidekiq: (pid 13673) 0s #查看状态 [root@localhost ~]# gitlab-ctl status run: gitaly: (pid 13539) 119s; run: log: (pid 10305) 396s ...省略... run: sidekiq: (pid 13673) 111s; run: log: (pid 10299) 396s [root@localhost ~]# ``` ##### 8、自启 让GitLab随Linux操作系统的启动而自动启动。 ```shell [root@localhost ~]# systemctl enable gitlab-runsvdir.service ``` ##### 9、端口 开放8989端口号,允许外部通过该端口访问GitLab。 ```shell [root@localhost ~]# firewall-cmd --zone=public --add-port=8989/tcp --permanent [root@localhost ~]# firewall-cmd --reload ``` ##### 10、日志 查看GitLab日志信息。 ```shell [root@localhost ~]# gitlab-ctl tail ``` ##### 11、访问 启动浏览器,访问http://192.168.1.100:8989/,如下所示: ![image-20221126184033103](https://gitee.com/rothschildx/gitlab-local/raw/master/Readme.assets/image-20221126184033103.png) 说明: ​ 账号:root ​ 密码:参见/etc/gitlab/initial_root_password文件 ##### 12、问题 描述:启动GitLab命令执行完毕立即访问GitLab可能提示如下页面: image-20221127162054002 方案:启动GitLab命令执行完毕后再稍等片刻。 #### 四、设置 ##### 1、密码 GitLab默认初始化密码太长,不便于记忆,为此可通过如下操作修改密码: a、登录GitLab,如下所示: ![image-20221126193847516](https://gitee.com/rothschildx/gitlab-local/raw/master/Readme.assets/image-20221126193847516.png) b、点击Preferences,如下所示: ![image-20221126194012193](https://gitee.com/rothschildx/gitlab-local/raw/master/Readme.assets/image-20221126194012193.png) c、点击Password,如下所示: ![image-20221126194657072](https://gitee.com/rothschildx/gitlab-local/raw/master/Readme.assets/image-20221126194657072.png) d、输入当前密码—>输入新密码,这里为12345678—>输入确认密码—>点击“Save password”—>重新登录GitLab。 ##### 2、汉化 GitLab默认界面为英文,可以通过下面界面将其设置为中文: a、登录GitLab,如下所示: ![image-20221126194926120](https://gitee.com/rothschildx/gitlab-local/raw/master/Readme.assets/image-20221126194926120.png) b、点击Preferences,如下所示: ![image-20221126195323382](https://gitee.com/rothschildx/gitlab-local/raw/master/Readme.assets/image-20221126195323382.png) c、滑动滚动条至Localization—>Language下拉列表选择“Chinese, Simplified - 简体中文 (97% translated)”—>点击“Save changes”按钮—>刷新页面。