专业的编程技术博客社区

网站首页 > 博客文章 正文

Gitlab不同方式的安装配置及常见场景用法

baijin 2024-09-27 06:37:32 博客文章 5 ℃ 0 评论

一:rpm 格式安装

1.安装对应的依赖包

yum install -y curl policycoreutils-python openssh-server

systemctl enable sshd

systemctl start sshd

2.邮件通知

yum install postfix -y

systemctl enable postfix

systemctl start postfix

3.获取安装源

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

4.配置https 或 http 访问域名

vi /etc/hosts

192.168.10.32 gitlab.meng.com

EXTERNAL_URL="http://gitlab.meng.com" yum install -y gitlab-ee

1.6G安装包,下载安装需要一段时间

(安装版本 gitlab-ee.x86_64 0:11.9.8-ee.0.el7 )

4.http://gitlab.meng.com

转向到修改密码

5.重启服务

gitlab-ctl restart

二:docker 容器化方式部署

1.使用docker启动redis

docker run --name=gitlab_redis -tid -p 16379:6379 \ registry.test.com:5000/liyong/redis

2.使用docker启动mysql

docker run --name=gitlab_mysql -tid \ -e 'DB_NAME=gitlabhq_production' -e 'DB_USER=gitlab' \ -e 'DB_PASS=password' \ -v /opt/gitlab/mysql:/var/lib/mysql \ -p 13306:3306 registry.test.com:5000/liyong/mysql

3.使用docker启动gitlab

docker run --name gitlab -d --link gitlab_mysql:mysql \ --link gitlab_redis:redisio \ --publish 10022:22 --publish 10080:80 \ --publish 10443:443 \ --env 'GITLAB_PORT=10080' \ --env 'GITLAB_SSH_PORT=10022' \ --env 'GITLAB_SECRETS_DB_KEY_BASE=long-and-random-alpha-numeric-string' \ --volume /srv/docker/gitlab/gitlab:/home/git/data \ registry.test.com:5000/liyong/gitlab

4.配置修改

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

server_name gitlab.example.com;

如,改成

server_name bkgitlab.gxpan.cn;

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

host: gitlab.example.com

改成

host: bkgitlab.gxpan.cn

重启所有服务

gitlab-ctl restart

通过域名访问

bkgitlab.gxpan.cn

首次访问修改 root密码

账号:root

密码:ledou@2019

#docker部署方式2

docker pull gitlab/gitlab-ce

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

vim /home/gitlab/config/gitlab.rb

cat /home/gitlab/config/gitlab.rb|grep -v "#"|sed '/^$/d'

external_url 'http://192.168.10.13'

gitlab_rails['gitlab_ssh_host'] = '192.168.10.13'

gitlab_rails['gitlab_ssh_user'] = '222'

docker restart gitlab

三:常见场景使用技巧

1.gitlab 免密码输入远程提交

git push -u origin master

解决方案

在终端下执行git config --global credential.helper store

2.查看gitconfig配置信息:

cat ~/.gitconfig

3.重置gitlab root的密码

1) 输入gitlab-rails console 进入gitlab控制台

2) 输入user = User.where(id:1).first查询id为1的用户对象,因为超级管理员用户默认都是1

3) 输入user.password='密码',密码位置填写您新的密码即可。

4) 然后再输入user.save!保存用户对象

4.gitlab 安装后的默认账号密码

用户名:root 密码:5iveL!fe

重置密码:

5.web 使用,创建用户组,即命名空间

6.web,创建用户

创建完后,编辑即可修改用户登录密码

7.web,创建项目

8.客户端访问

git clone http://gitlab.meng.com/ledouweb/ledouweb.git

输入账号,密码

ledou_user1

ledou@2019

9.添加文件并提交到远程仓库

vi index.html

git add index.html

git status

git commit -m "add index.html"

远程提交:

git push -u origin master

检查文件:

10.#修改默认80端口为8080

第一步防火墙8080放行

#vi /etc/sysconfig/iptables

-A INPUT -m state --state NEW -m tcp -p tcp --dport 8080 -j ACCEPT

第二步修改配置文件

#vi /var/opt/gitlab/nginx/conf/gitlab-http.conf

找到server段,修改为

server {

listen *:8080;

server_name 192.168.0.59;

#vi /home/git/gitlab-shell/config.yml

# Url to gitlab instance. Used for api calls. Should end with a slash.

gitlab_url: http://192.168.0.59:8080

#vi /home/git/gitlab/config/gitlab.yml

## GitLab settings

gitlab:

## Web server settings

host: 192.168.0.59

port: 8080

#gitlab-ctl restart 重启所有服务

访问http://192.168.0.59:8080

提示页面502错误

#gitlab-ctl tail 查看启动日志发现错误端口8080端口被占用

==> /var/log/gitlab/unicorn/unicorn_stderr.log <==

E, [2016-03-29T01:47:03.808684 #2894] ERROR -- : adding listener failed addr=127.0.0.1:8080 (in use)

把上述8080端口改为8081再重启服务即可正常访问http://192.168.0.59:8081

11.备份恢复

#备份

默认备份的是放在 /var/opt/gitlab/backups 路径下

修改 /etc/gitlab/gitlab.rb 配置

gitlab_rails['backup_path'] = "/var/opt/gitlab/backups"

#执行备份

sudo gitlab-rake gitlab:backup:create

30 4 * * * docker exec gitlab gitlab-backup create STRATEGY=copy

#查看日志

gitlab-ctl tail postgresql

gitlab-ctl start postgresql

#

30 4 * * * docker exec gitlab gitlab-backup create STRATEGY=copy;find /data/gitlab/data/backups -type f -cmin -120 -exec sshpass -p "bwoil789" scp {} root@192.168.102.33:/data/backup/gitlab ;

#45 12 * * * docker exec gitlab gitlab-backup create STRATEGY=copy

0 6 * * * find /data/gitlab/data/backups -type f -ctime +2 -exec rm -f {} ;

Tags:

本文暂时没有评论,来添加一个吧(●'◡'●)

欢迎 发表评论:

最近发表
标签列表