安装gitlab
安装Docker社区版本
非阿里云服务器,需将http://mirrors.cloud.aliyuncs.com替换为https://mirrors.aliyun.com
#添加Docker软件包源
sudo wget -O /etc/yum.repos.d/docker-ce.repo http://mirrors.cloud.aliyuncs.com/docker-ce/linux/centos/docker-ce.repo
sudo sed -i 's|https://mirrors.aliyun.com|http://mirrors.cloud.aliyuncs.com|g' /etc/yum.repos.d/docker-ce.repo
#安装Docker社区版本,容器运行时containerd.io,以及Docker构建和Compose插件
sudo dnf -y install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
启动Docker并设置开机自启
#启动Docker
sudo systemctl start docker
#设置Docker守护进程在系统启动时自动启动
sudo systemctl enable docker
配置镜像源
由于运营商网络原因,从Docker Hub拉取镜像会失败。配置镜像加速器可解决该问题。
登录容器镜像服务控制台,在左侧导航栏选择镜像工具 > 镜像加速器,在镜像加速器页面获取加速器地址。
#编辑Docker配置文件/etc/docker/daemon.json。若文件不存在,先创建。
{
"registry-mirrors": ["https://docker.1ms.run"]
}
#重启Docker服务应用新配置。
sudo systemctl restart docker
配置docker-compose并启动
创建目录
mkdir -p /usr/local/docker/gitlab
cd /usr/local/docker/gitlab/
mkdir config
mkdir data
mkdir logs
编写docker-compose.yml
services:
gitlab:
image: 'gitlab/gitlab-ce:latest'
shm_size: '512m'
container_name: "gitlab"
restart: unless-stopped
privileged: true
hostname: 'your-ip'
environment:
TZ: 'Asia/Shanghai'
GITLAB_OMNIBUS_CONFIG: |
external_url 'http://your-ip'
ports:
- '3080:80'
- '443:443'
- '3022:22'
volumes:
- ./config:/etc/gitlab
- ./data:/var/opt/gitlab
- ./logs:/var/log/gitlab
使用docker compose 启动gitlab:
docker compose -f docker-compose.yml up -d
docker compose -f docker-compose.yml down #停止
设置swap内存
在云上内存比较小的情况下,运行gitlab会比较卡。一个方案是设置swap内存。
# 检查当前 Swap 状态
$free -m
total used free shared buff/cache available
Mem: 3591 3471 109 26 260 119
Swap: 0 0 0
$swapon -s
# 创建 Swap 文件
$fallocate -l 4G /swapfile
#设置文件权限
$chmod 600 /swapfile
#格式化为 Swap 文件系统
$mkswap /swapfile
Setting up swapspace version 1, size = 4 GiB (4294963200 bytes)
no label, UUID=f83310ed-83d4-4b28-bb9e-87f4d9b3fe62
#启用 Swap 文件(立即生效,重启后失效)
$swapon /swapfile
#重新查看swap情况
$free -h
total used free shared buff/cache available
Mem: 3.5Gi 3.4Gi 107Mi 26Mi 238Mi 97Mi
Swap: 4.0Gi 0B 4.0Gi
$swapon -s
Filename Type Size Used Priority
/swapfile file 4194300 0 -2
#查看当前 swappiness 值(默认通常为 60)
$cat /proc/sys/vm/swappiness
vim /etc/sysctl.conf
# 在文件末尾添加:vm.swappiness=20
#让配置立即生效
sudo sysctl -p
从网页登录gitlab
运行docker compose命令后,立即登录网页http://your-ip:3080是登不上的,要等到一段时间等gitlab初始化完成之后才能登上。
sshkey登录gitlab
ssh-keygen -t ed25519 -C "mail@youmail.com" -f ./ssh-keys/my_gitlab_key
chmod 700 ./ssh-keys # 密钥目录仅当前用户可进入
chmod 600 ./ssh-keys/my_gitlab_key # 私钥仅当前用户可读写
chmod 644 ./ssh-keys/my_gitlab_key.pub # 公钥可读即可
# ~/.ssh/config
Host gitlab-ali
HostName your_ip
Port your_port
User giti
IdentityFile /workspace/ssh-keys/ali_gitlab_key
StrictHostKeyChecking no
配置好之后测试:
# ssh -T git@gitlab-ali
Warning: Permanently added '[xxx.xxx.xxx.xxx]:xx' (ECDSA) to the list of known hosts.
Welcome to GitLab, @gitusername!
使用ssh进行git操作:
git clone git@gitlab-ali:git_username/git_projname.git
在git提交时候出现的错误提示:“make sure you configure your user.name and user.email in git”, 运行如下命令查看和设置:
# git config --list
core.repositoryformatversion=0
core.filemode=false
core.bare=false
core.logallrefupdates=true
remote.origin.url=http://xxx.xxx.xxx.xxx/git_username/git_projname.git
remote.origin.fetch=+refs/heads/*:refs/remotes/origin/*
branch.main.remote=origin
branch.main.merge=refs/heads/main
branch.main.vscode-merge-base=origin/main
# git config user.name myusername
# git config user.email myemail
# git config --list
参考资料
【1】安装并使用Docker和Docker Compose https://help.aliyun.com/zh/ecs/user-guide/install-and-use-docker#ba0b2951bb2ay
【2】群晖Nas - Docker上安装GitLab https://blog.csdn.net/thinbug/article/details/148565916?spm=1001.2014.3001.5506
【3】https://blog.csdn.net/Luguangdong_123/article/details/105103804
更多推荐
所有评论(0)