沙滩星空的博客沙滩星空的博客

使用gitlab搭建私有代码库服务器

Docker Compose方式搭建gitlab服务器

设置gitlab工作目录的环境变量 GITLAB_HOME

export GITLAB_HOME=/srv/gitlab

创建 docker-compose.yml 文件:

web:
  image: 'gitlab/gitlab-ce:latest'
  restart: always
  hostname: 'gitlab.example.com'
  environment:
    GITLAB_OMNIBUS_CONFIG: |
      external_url 'http://gitlab.example.com'
  ports:
    - '80:80'
    - '443:443'
    - '122:22'
  volumes:
    - '$GITLAB_HOME/config:/etc/gitlab'
    - '$GITLAB_HOME/logs:/var/log/gitlab'
    - '$GITLAB_HOME/data:/var/opt/gitlab'

运行 docker-compose

gitlab是个很耗资源的应用,至少需要2核4G的硬件配置。

docker-compose up -d

gitlab的docker容器启动很耗时,可能需要数分钟。如果启动未完成,访问gitlab可能出现 502错误
硬件配置不够,gitlab的docker容器将无法成功启动。我这边本地测试2核4G的虚拟机花了4分钟的启动时间。

查看 gitlab镜像

docker images
REPOSITORY                       TAG                 IMAGE ID            CREATED            SIZE
gitlab/gitlab-ce                 latest              033bcfa1b036        7 days ago          2.09GB

重置gitlab管理员密码

整个网上99%的都教你用 gitlab-rails console production命令。其实可能是错的,因为不同版本可能不一样。
我的gitlab版本命令为 gitlab-rails console -e production

gitlab-rails console -e production

--------------------------------------------------------------------------------
 Ruby:         ruby 2.7.2p137 (2020-10-01 revision 5445e04352) [x86_64-linux]
 GitLab:       13.7.4 (2f14978e280) FOSS
 GitLab Shell: 13.14.0
 PostgreSQL:   12.4
--------------------------------------------------------------------------------
Loading production environment (Rails 6.0.3.3)
irb(main):004:0> user = User.where(username:"root").first
=> #<User id:1 @root>
irb(main):006:0> user.password = "123456"
=> "123456"
irb(main):011:0> user.save()
Enqueued ActionMailer::MailDeliveryJob (Job ID: b4213688-7436-4fa0-921c-e0b077d65d38) to Sidekiq(mailers) with arguments: "DeviseMailer", "password_change", "deliver_now", {:args=>[#<GlobalID:0x00007fa99a6b7d30 @uri=#<URI::GID gid://gitlab/User/1>>]}
=> true
查询所有的用户
user = User.all
通过条件查询用户 常见的where条件有 username email state 
user = User.where(id:1).first
user = User.find_by(email: 'admin@local.host')
通过id查询用户
user = User.find(1)

查询用户某个字段的值 显示当前用户的email
user.email

修改密码
user.password = 'new_password'
user.password_confirmation = 'new_password'
user.save
echo 'user = User.find_by(username: "root");user.password="secret_pass!";user.password_confirmation="secret_pass!";user.save' | sudo gitlab-rails console

# 修改用户状态
user.state = 'active'
user.save

端口号设置

vim /var/opt/gitlab/gitlab-rails/etc/gitlab.yml

vim /var/opt/gitlab/nginx/conf/gitlab-http.conf

gitlab-ctl restart

配置文件 /etc/gitlab/gitlab.rb

gitlab的安装与修改端口配置 https://www.cnblogs.com/heartxkl/p/12943904.html


忘记gitlab密码怎么办 http://www.eryajf.net/5315.html
GitLab的安装及使用教程 https://www.cnblogs.com/niuben/p/10867877.html
CentOS 7.5上安装 GitLab 最新版CE/EE https://blog.csdn.net/weixin_43767602/article/details/84568858
gitlab安装要求 https://docs.gitlab.com/ee/install/requirements.html
官网CentOS7安装教程:https://about.gitlab.com/install/#centos-7
Docker-compose https://docs.gitlab.com/omnibus/docker/README.html#install-gitlab-using-docker-compose

未经允许不得转载:沙滩星空的博客 » 使用gitlab搭建私有代码库服务器

评论 抢沙发

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址