“Gitlab社区版安装和配置”的版本间的差异

来自linux中国网wiki
跳到导航 跳到搜索
 
第366行: 第366行:
 
最后,保存上面的更改,即可使用新密码登录。
 
最后,保存上面的更改,即可使用新密码登录。
 
注意:root密码不能小于8位即12345678,不然会显示false
 
注意:root密码不能小于8位即12345678,不然会显示false
 +
 +
 +
2024
 +
root@debian11:~# gitlab-rails console
 +
--------------------------------------------------------------------------------
 +
Ruby:        ruby 3.0.6p216 (2023-03-30 revision 23a532679b) [x86_64-linux]
 +
GitLab:      16.4.1 (e6801ed8d44) FOSS
 +
GitLab Shell: 14.28.0
 +
PostgreSQL:  13.11
 +
------------------------------------------------------------[ booted in 37.63s ]
 +
Loading production environment (Rails 7.0.6)
 +
irb(main):001:0> user = User.where(username:"root").first
 +
=> #<User id:1 @root>
 +
 +
irb(main):006:0> user.password = "evan12345678"
 +
=> "evan12345678"
 +
irb(main):007:0> user.save!
 +
=> true
 +
 
</pre>
 
</pre>
 
[https://www.codenong.com/cs105343781/ 服务器Gitlab忘记root密码]
 
[https://www.codenong.com/cs105343781/ 服务器Gitlab忘记root密码]

2024年8月29日 (四) 02:21的最新版本

进阶

GitLab能打开,但总是出现502错误?

GitLab 所需内存最低为4G,若服务器配置太低会出现502错误

 puma['worker_timeout'] = 90 # 这个好像也有点效果 

GitLab实战三——Gitlab架构组件详解

GitLab系列2 GitLab Workhorse

14_Linux环境搭建GitLab服务器和组件介绍

使用 Nginx 代理内网 GitLab 并确保 SSH / HTTP 克隆地址正确


Gitlab-3.外部Nginx反向代理Gitlab内部Nginx

Gitlab Nginx 配置踩坑实际

How to remove a Gitlab project

    Open project
    Setting (In the left sidebar)
    General
    Advanced Setting (Click on Expand)
    Remove Project (Bottom of the Page)
    Confirm (By typing project name and press Confirm button)

https://stackoverflow.com/questions/24032232/how-to-remove-a-gitlab-project

usage and devops

GitLab 管理员手册

GitLab如何删除已有项目

为GitLab帐号添加SSH keys并连接GitLab

GitLab 如何修改项目从私有到公有

本地java代码上传Gitlab仓库


Gitlab搭建与使用第一篇

超详细·gitlab的高可用搭建完整过程

devops-gitlab运维实践

第零 docker-compose for gitlab  



2020 直接 docker-compose 其实可以上 alpine的  不过官方的没有  
用ng upstream 到 80 or 443 


#官方依然是这个 Tue 09 Nov 2021 02:56:50
cat docker-compose.yml


web:
  image: 'gitlab/gitlab-ce:14.0.0-ce.0'
  #image: 'gitlab/gitlab-ce:11.4.3'
  #image: 'gitlab/gitlab-ce:latest'  
  restart: always
  hostname: 'mygitlab.com'
  environment:
    GITLAB_OMNIBUS_CONFIG: |
      external_url 'http://gitlab.lliao.net'
      #external_url 'https://mygitlab.com'
      # Add any other gitlab.rb configuration here, each on its own line
  ports:
    - '7080:80'
    - '4433:443'
    - '2222:22'
  volumes:
    - ./gitlab/config:/etc/gitlab
    - ./gitlab/logs:/var/log/gitlab
    - ./gitlab/data:/var/opt/gitlab



#下面是可优化的选项
    environment:
        TZ: 'Asia/Shanghai'
        GITLAB_OMNIBUS_CONFIG: |
          external_url 'http://120.27.246.9'  暴露的url
          gitlab_rails['gitlab_shell_ssh_port'] = 2222 
          unicorn['port'] = 8888
          nginx['listen_port'] = 80




这个不太对的 不用理  

这个首次登录密码重置为什么没了 june 2021 version gitlab14
 Browse to the hostname and login

On your first visit, you'll be redirected to a password reset screen. Provide the password for the initial administrator account and you will be redirected back to the login screen. Use the default account's username root to login.


https://mygitlab.com:4433/
7080端口好像不行 要改下面的ssh相关就好了 

cat gitlab.conf 

   server {
        listen       80;
        server_name  gitlab.com;
 

        location / {
            proxy_pass http://192.168.10.38:7080;
            proxy_set_header X-Real-IP $remote_addr;
            proxy_set_header Host $host;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
           
        }
     }

改进  暂时不建议用这个 

    运行在自定义的 HTTP 和 SSH 端口:

    web:
    image: 'gitlab/gitlab-ce:latest'
    restart: always
    hostname: 'gitlab.example.com'
    environment:
        GITLAB_OMNIBUS_CONFIG: |
        external_url 'http://gitlab.example.com:8929'
        gitlab_rails['gitlab_shell_ssh_port'] = 2224
    ports:
        - '8929:8929'
        - '2224:22'
    volumes:
        - '/srv/gitlab/config:/etc/gitlab'
        - '/srv/gitlab/logs:/var/log/gitlab'
        - '/srv/gitlab/data:/var/opt/gitlab'



Install GitLab with Docker

init

GitLab默认密码

user root 
    gitlab-ce-14+初装以后,把密码放在了一个临时文件中了
    /etc/gitlab/initial_root_password
    这个文件将在首次执行reconfigure后24小时自动删除

gitlab搭配ssh默认端口引发的问题

明明 docker-compose.yml  用 了2222端口但还是有问题   rb文件也要改为 2222  这个是为了开外网 给外面的用  例如jenkins 在外面的 

修改sshd_config中的Port #这一步 试过 可以不用操作的
service sshd restart

#第一步的我没改哦 好像可以不动 
修改/etc/gitlab/gitlab.rb [再次声明,gitlab.yml中的配置会被这个给覆盖]

启用下面这行,并把端口改为自己服务器的sshd端口 如果是我常用的 这里50022 应该是2222才对哦

gitlab_rails['gitlab_shell_ssh_port'] = 50022

使之生效,大功告其!

gitlab-ctl reconfigure



其它办法 
然后要等待一会儿直到页面能够重新显示为止
修改http的clone地址加上端口
修改gitlab.yml文件
进入容器内部
docker exec -it gitlab /bin/bash
修改文件
cd /opt/gitlab/embedded/service/gitlab-rails/config
vim gitlab.yml
复制代码
修改gitlab
             host:10.10.0.44
             port:7002

然后在容器内执行gitlab-ctl restart (注意 这里如果docker restart gitlab了,设置会被重新覆盖,也就丢失了,因为restart会重新执行gitlab-ctl reconfigure,目前没有什么好的方式,只有尽量少启动gitlab)

修改http的clone地址加上端口

java+maven项目+tapd+jenkins+gitlab+sonarqube+docker实现自动化持续部署(超详细)

第一种 Install and configure the necessary dependencies

debian 11 bullseye
https://mirrors.tuna.tsinghua.edu.cn/gitlab-ce/debian/pool/bullseye/main/g/gitlab-ce/gitlab-ce_14.6.2-ce.0_amd64.deb


进入gitlab官方网站,选择对应的操作系统——CentOS 6 (and RedHat/Oracle/Scientific Linux 6),
https://about.gitlab.com/downloads/#centos6

按照官方的提示进行安装:
安装配置必要的依赖
在Centos 6 和 7 中,以下的命令将会打开HTTP和SSH在系统防火墙中的可访问权限。

#sudo lokkit -s http -s ssh


[gitlab-ce]
name=gitlab-ce
baseurl=http://mirrors.tuna.tsinghua.edu.cn/gitlab-ce/yum/el6
repo_gpgcheck=0
gpgcheck=0
enabled=1
gpgkey=https://packages.gitlab.com/gpg.key


sudo yum makecache

# 安装依赖包
sudo yum install curl openssh-server openssh-clients postfix cronie
# 启动 postfix 邮件服务
sudo service postfix start
# 检查 postfix
sudo chkconfig postfix on
# 安装 GitLab 社区版
sudo yum install gitlab-ce
# 初始化 GitLab 配置并启动GitLab
打开/etc/gitlab/gitlab.rb,将external_url = ‘http://git.example.com’修改为自己的IP地址:http://xxx.xx.xxx.xx,,然后执行下面的命令,对GitLab进行编译。

sudo gitlab-ctl reconfigure
一直都有更新的。

sudo gitlab-ctl reconfigure
登录GitLab
Username: root
Password: 5iveL!fe

我在ubuntu下的一键安装,如果用汉化版的有问题的。
所以现在只能用英文原版的。


现在会要求改密码了 在第一次 

git_data_dirs({"default" => "/data/gitlab/git-data"})
/data/gitlab/git-data

gitlab-ctl reconfigure 

Debian11 安装 gitlab ce 社区版

第二种 Add the GitLab package server and install the package

curl https://packages.gitlab.com/install/repositories/gitlab/gitlab-ce/script.rpm.sh | sudo bash
sudo yum install gitlab-ce 

 

 


【gitlab小症状】gitlab搭配ssh默认端口引发的血战

docker安装gitlab并使用非标准端口

gitlab性能优化调化 占用内存过大问题


/etc/gitlab/gitlab.rb

#进程数目 
 unicorn['worker_processes'] = 2

#减少数据库缓存 默认为  256M
postgresql['shared_buffers'] = "128MB"


#减少并发数 默认为8
postgresql['max_worker_processes'] = 4



#减少 sidekiq并发数 
sidekiq['concurrency'] = 20


bundle 占用内存

#打开注释 不然是默认用OS上的 太多不好 RAM不够呀 在注释的情况下默认是服务器上的所有线程。


# puma['worker_processes'] = 2
puma['worker_processes'] = 2

puma['per_worker_max_memory_mb'] = 1024

#最后  reload  有也加加 restart 
gitlab-ctl reconfigure

gitlab占用内存过大问题

GitLab配置优化及汉化

GitLab 官方镜像内部集成 Prometheus 历史数据过大的问题处理

GitLab provides out-of-the-box monitoring with Prometheus, providing easy access to high quality time-series monitoring of GitLab services. https://docs.gitlab.com/ee/administration/monitoring/prometheus/

gitlab官网的包,Prometheus将会捆绑在软件包中

Prometheus是一个监控服务,会保存历史监控数据,下面尝试关闭该服务并删除之前的数据(在Docker Gitlab上操作)

#is docker use docker-compose

volume 可见为
./gitlab/config:/etc/gitlab

docker-compose  restart 

# is bin install

vi /etc/gitlab/gitlab.rb #,添加 默认是开启的 prometheus 过分 

prometheus_monitoring['enable'] = false

gitlab-ctl reconfigure
#等一下  gitlab自带的prometheus  graf node_exporter 相关的进程全没了 

Prometheus吃磁盘空间和内存

Gitlab 重置 root 密码


先登录入容器

要重置root密码,请先使用root权限登录服务器。使用以下命令启动Ruby on Rails控制台:

su - git
gitlab-rails console
#gitlab-rails console production

等到控制台加载完毕,您可以通过搜索电子邮件或用户名等方法找到您的账号。

user = User.where(id: 1).first

或者

user = User.find_by(email: '[email protected]')

找出用户以后,可以更改其密码:

user.password = '12345678'
#user.password_confirmation = 'e12345678'

user.save!
可能得先重启服务呢  一定要保存 有时登录不对 可能是浏览器缓存了哦 
最后,保存上面的更改,即可使用新密码登录。
注意:root密码不能小于8位即12345678,不然会显示false


2024
root@debian11:~# gitlab-rails console 
--------------------------------------------------------------------------------
 Ruby:         ruby 3.0.6p216 (2023-03-30 revision 23a532679b) [x86_64-linux]
 GitLab:       16.4.1 (e6801ed8d44) FOSS
 GitLab Shell: 14.28.0
 PostgreSQL:   13.11
------------------------------------------------------------[ booted in 37.63s ]
Loading production environment (Rails 7.0.6)
irb(main):001:0> user = User.where(username:"root").first
=> #<User id:1 @root>

irb(main):006:0> user.password = "evan12345678"
=> "evan12345678"
irb(main):007:0> user.save!
=> true

服务器Gitlab忘记root密码

https://docs.gitlab.com/ee/security/reset_user_password.html

Linux初装gitlab初始默认密码

报错

================================================================================
Recipe Compile Error in /opt/gitlab/embedded/cookbooks/cache/cookbooks/gitlab/recipes/default.rb
================================================================================

RuntimeError
------------
GitLab external URL must include a schema and FQDN, e.g. http://gitlab.example.com/

记得前缀有http样

https://mirror.tuna.tsinghua.edu.cn/help/gitlab-ce/

https://www.linuxchina.net/?p=2750

 

日常

GitLab基础:5种查询GitLab的版本的方法

ssh端口问题

因为母机用了22 所以正常情况下不能用22了 除非你改了母机的sshd 为其它端口

Docker搭建gitlab之端口映射


Docker GitLab SSH 坑

利用docker部署gitlab忘记进行ssh的端口映射

trouble shooting

docker-compose 安装完 后 

打开web
502
Whoops, GitLab is taking too much time to respond.
若进入浏览器后若出现502页面,不要着急,多刷新几次,出现502是因为GitLab服务还在准备当中。

问题原因

我的虚拟机只分配了 2G 物理内存,内存不足,然后 Gitlab 自启动的一些服务或者组件太占内存,导致无法正常访问网站

free -m 
看下used  和 free的使用情况,如果free一直在减少,说明gitlab正在启动,消耗内存中,还没有启动完成!这个时候访问是会提示502 Whoops, GitLab is taking too much time to respond.  

这个时候不要去修改什么端口,启动等等,之前试过都无效!

我们需要等待一下再去访问,即可!当然这仅是502错误中的一种



gitlat 换服务器后

Caused by: hudson.plugins.git.GitException: Command "git fetch --tags --force --progress -- [email protected]:php/live-room-manage.git +refs/heads/*:refs/remotes/origin/*" returned status code 128:
stdout: 
stderr: ssh: Could not resolve hostname git..com: Try again
fatal: Could not read from remote repository.

docker里面hosts git.com 域名 

gitlab迁移后,"集成"页面500报错

gitlab迁移后,访问“项目–>设置–>集成”页面500报错如下:

ActionView::Template::Error ():
1: %li
2:   .row
3:     .col-md-8.col-lg-7
4:       %strong.light-header= hook.url    
5:       %div    
6:         - ProjectHook.triggers.each_value do |event|    
7:           - if hook.public_send(event)  
app/models/hooks/web_hook.rb:62:in `url' 

网上搜索后,都说恢复原来备份的"/etc/gitlab/gitlab-secrets.json"文件,然后执行命令
# gitlab-ctl reconfigure
# gitlab-ctl restart
就行了。可是我的gitlab-secrets.json文件也丢失了,没有备份这个文件。
后来在官方issue里找到解决方法,使用api删除webhook就可以了。
不过删除后,"集成"页面可以访问,但是原来的钩子配置也没有了,需要重新配置。

方法如下:
1.通过web页面,获取project_id

 

 

2.通过project_id,查找出hook_id
# gitlab-rails db
gitlabhq_production=> select id from web_hooks where project_id=42;   //会得到hook_id,我这里是11

3.通过API删除hook_id
# curl --header "Private-Token: D6sfysEa65H_6k8aPyV7" -X DELETE http://gitlab.example.com/api/v4/projects/42/hooks/11
//将Private-Token的值,project_id,hook_id替换为自己的

创建private token:
点击"用户"-->"设置"-->"访问令牌",然后创建保存就行了。


https://www.cnblogs.com/jatq/p/14048267.html

see also

Gitlab之repos位置迁移

References

https://gitlab.com/gitlab-org/gitlab-foss/-/blob/master/doc/install/installation.md

GitLab Docker images


使用 Omnibus 安装包安装极狐GitLab

在 CentOS 7 上使用 Docker 部署安装 GitLab

GitLab 中文社区版 Docker 镜像

ouyangzhiping/docker-gitlab.md

GitLab的安装及使用教程

使用Docker安装GitLab

GitLab安装教程

Docker 搭建 Gitlab 服务

快速安装 GitLab 并汉化

linux环境下nginx反向代理gitlab社区版

备份 还原

老版本的 GitLab从旧服务器迁移到新服务器

gitlab ee 14.3.2 安装,配置和数据迁移

install

yum install -y curl policycoreutils-python
wget -c   --no-check-certificate https://mirrors.tuna.tsinghua.edu.cn/gitlab-ee/yum/el7/gitlab-ee-14.3.2-ee.0.el7.x86_64.rpm
rpm -ivh  gitlab-ee-14.3.2-ee.0.el7.x86_64.rpm
Note 可能打开一开始是502 原来是服务器上的的confu 用了太多内存导致的 ,没有 8G ram真的不要上java 应用

configu

cat gitlab.rb

gitlab-ctl reconfigure



external_url 'http://git.2.com:8089'

git_data_dirs({
  "default" => {
    "path" => "/data/gitlab-data/git-data"
   }
})

gitlab_workhorse['auth_backend'] = "http://localhost:8088"


puma['worker_processes'] = 2

puma['port'] = 8088



puma['per_worker_max_memory_mb'] = 1024
sidekiq['max_concurrency'] = 10



postgresql['shared_buffers'] = "128MB"

postgresql['max_worker_processes'] = 4
prometheus_monitoring['enable'] = false

ng confi

cat /etc/nginx/conf.d/git.2.com.conf
server {
    listen      80;
    server_name git.2.com;
    index       index.html index.html index.php;

    #charset koi8-r;
    charset     utf-8;

    access_log  /var/log/nginx/git.2.com.access.log;
    error_log  /var/log/nginx/git.2.com.error.log;


    location /{
        proxy_pass http://127.0.0.1:8089;
        #proxy_set_header Host $host:$server_port;
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header REMOTE-HOST $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        index    index.html index.htm index.php;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection "upgrade";
        proxy_http_version 1.1;
    }

    error_page  404              /404.html;

#    include traits.d/enable-redirect-https.conf;

}


备份和还原

备份Back up GitLab

#官方教程是最好的 


GitLab 12.2 or later:

sudo gitlab-backup create

Creating backup archive: 1637650373_2021_11_23_14.3.2-ee_gitlab_backup.tar ... done
Uploading backup archive to remote storage  ... skipped
Deleting tmp directories ... done
done
done
done
done
done
done
done
Deleting old backups ... skipping
Warning: Your gitlab.rb and gitlab-secrets.json files contain sensitive data 
and are not included in this backup. You will need these files to restore a backup.
Please back them up manually.
Backup task is done.


位置 是 /var/opt/gitlab/backups/

另外两个文件得自己带走 

cp /etc/gitlab/gitlab.rb .
[root@jumpserver gitbaknov]# cp /etc/gitlab/gitlab-secrets.json  .



If you’re running GitLab from within a Docker container, run the backup from the host, based on your installed version of GitLab:

    GitLab 12.2 or later:

    docker exec -t <container name> gitlab-backup create
    

注意 

Storing configuration files

The backup Rake task GitLab provides does not store your configuration files. The primary reason for this is that your database contains items including encrypted information for two-factor authentication and the CI/CD secure variables. Storing encrypted information in the same location as its key defeats the purpose of using encryption in the first place. 

At the very minimum, you must back up:

For Omnibus:

    /etc/gitlab/gitlab-secrets.json
    /etc/gitlab/gitlab.rb 
    
 

还原

 
 还原的如下  
 
 Restore for Omnibus GitLab installations

This procedure assumes that:

    You have installed the exact same version and type (CE/EE) of GitLab Omnibus with which the backup was created.
    You have run sudo gitlab-ctl reconfigure at least once.
    GitLab is running. If not, start it using sudo gitlab-ctl start. 

First ensure your backup tar file is in the backup directory described in the gitlab.rb configuration gitlab_rails['backup_path']. The default is /var/opt/gitlab/backups. It needs to be owned by the git user.

sudo cp 11493107454_2018_04_25_10.6.4-ce_gitlab_backup.tar /var/opt/gitlab/backups/
sudo chown git.git /var/opt/gitlab/backups/11493107454_2018_04_25_10.6.4-ce_gitlab_backup.tar

Stop the processes that are connected to the database. Leave the rest of GitLab running:

sudo gitlab-ctl stop puma
sudo gitlab-ctl stop sidekiq
# Verify
sudo gitlab-ctl status

Next, restore the backup, specifying the timestamp of the backup you wish to restore:

# This command will overwrite the contents of your GitLab database!
gitlab-backup restore BACKUP=1637675425_2021_11_23_14.3.2-ee
sudo gitlab-backup restore BACKUP=11493107454_2018_04_25_10.6.4-ce

一般都yes 最后把  /etc/gitlab/gitlab-secrets.json 也拿过去 ,gitalb.rb 本来就在启动后就拿过去了的 


还原有错 

estoring PostgreSQL database gitlabhq_production ... ERROR:  must be owner of extension pg_trgm
ERROR:  must be owner of extension btree_gist
ERROR:  must be owner of extension btree_gist
ERROR:  must be owner of extension pg_trgm



Restoring PostgreSQL database gitlabhq_production ... ERROR:  must be owner of extension pg_trgm

      
installs, see the following link for more information:
https://docs.gitlab.com/ee/raketasks/backup_restore.html#restore-for-omnibus-gitlab-installations

old

 # 下面这个手工的 线上一般不用了 以前学习用的

获取 GitLab 镜像
docker search gitlab

docker pull gitlab/gitlab-ce:latest

查看本地镜像
docker images

创建目录

mkdir -p /data/gitlab/{config,data,logs}

创建并运行容器

docker run --detach \
       --hostname git.evan.com \
       --publish 443:443 \
       --publish 80:80 \
       --publish 222:22 \
       --name gitlabce\
       --restart always \
       --volume /data/gitlab/config:/etc/gitlab \
       --volume /data/gitlab/logs:/var/log/gitlab \
       --volume /data/gitlab/data:/var/opt/gitlab \
       gitlab/gitlab-ce:latest


查看运行状态

docker ps
netstat -ntulap | grep docker
访问 GitLab

启动
docker start gitlabce

docker stop gitlabce

如果没有域名,直接使用 IP 访问即可。
初始账户

用户: root
密码: 5iveL!fe  现在一般要自己配置密码的了