Contents

Ubuntu安装GitLab

配置主机名

sudo hostnamectl hostname gitlab

hosts

10.10.10.130 gitlab GITLAB gitlab.hckz.top

检查升级

sudo apt-get update && sudo apt-get upgrade

qemu-guest-agent-虚拟机使用-非虚拟机可不用安装

# 安装

sudo apt-get install qemu-guest-agent

# 启动-开机启动-查看状态

sudo systemctl enable qemu-guest-agent && sudo systemctl start qemu-guest-agent && sudo systemctl status qemu-guest-agent

安装nfs

sudo apt-get install nfs4-acl-tools nfs-common -y

前置安装

sudo apt-get install -y conntrack ipvsadm ipset jq iptables curl sysstat wget vim net-tools git

sudo apt-get install -y curl openssh-server ca-certificates tzdata perl golang libc6 libnfs-utils libnfs-dev

句柄配置

ulimit -SHn 65535

sudo vim /etc/security/limits.conf

1
2
3
4
5
6
* soft nofile 655360
* hard nofile 131072
* soft nproc 655350
* hard nproc 655350
* seft memlock unlimited
* hard memlock unlimitedd

ulimit -a

安装时间同步服务

sudo apt-get install chrony

备份原有配置

sudo mv /etc/chrony/chrony.conf /etc/chrony/chrony.conf.bak

修改配置文件

sudo vim /etc/chrony/chrony.conf

>> server 192.168.22.253 iburst

时区配置

sudo ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime

启动系统服务chronyd

chronyc sources -v

重启校时服务并配置开机自启

sudo systemctl restart chronyd && sudo systemctl enable chronyd

查看时间

timedatectl

最大可用配置

sudo vim /etc/default/grub

修改 »>

GRUB_CMDLINE_LINUX="numa=off"

系统优化

sudo vim /etc/sysctl.d/k8s_better.conf

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
net.bridge.bridge-nf-call-iptables=1
net.bridge.bridge-nf-call-ip6tables=1
net.ipv4.ip_forward=1
vm.swappiness=0
vm.overcommit_memory=1
vm.panic_on_oom=0
fs.inotify.max_user_instances=8192
fs.inotify.max_user_watches=1048576
fs.file-max=52706963
fs.nr_open=52706963
net.ipv6.conf.all.disable_ipv6=1
net.netfilter.nf_conntrack_max=2310720

1
2
3
4
sudo modprobe br_netfilter
sudo lsmod |grep conntrack
sudo modprobe ip_conntrack
sysctl -p /etc/sysctl.d/k8s_better.conf

挂载服务

sudo vim /etc/systemd/system/nfs-mount.service


 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
[Unit]
Description=NFS Mount Service
After=network-online.target
Wants=network-online.target

[Service]
ExecStart=/usr/local/bin/nfs-mount -d /mnt/data
Restart=always
RestartSec=10
User=root
Type=simple

[Install]
WantedBy=multi-user.target

挂载脚本

sudo vim /usr/local/bin/nfs-mount


 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
    #!/bin/bash
    # 挂载 NFS 服务器的存储

    REMOTE_DIR="10.10.10.254:/mnt/pve/data"
    MOUNT_CMD="sudo mount -t nfs $REMOTE_DIR"

    # 检查是否提供了 -d 参数
    if [[ "$1" == "-d" && -n "$2" ]]; then
        LOCAL_DIR="$2"
    else
        echo "用法: $0 -d <本地挂载路径>"
        exit 1
    fi

    while true; do
        # 检查网络连接
        if ping -c 1 10.10.10.254 &> /dev/null; then
            # 检查是否已经挂载
            if ! sudo mount | grep "on $LOCAL_DIR type nfs" &> /dev/null; then
                # 尝试挂载
                $MOUNT_CMD $LOCAL_DIR
                if [ $? -eq 0 ]; then
                    echo "NFS-存储挂载成功 $(date '+%Y-%m-%d %H:%M:%S')"
                    break
                else
                    echo "NFS-存储挂载失败,正在重试 $(date '+%Y-%m-%d %H:%M:%S')"
                fi
            else
                echo "NFS-存储已经挂载 $(date '+%Y-%m-%d %H:%M:%S')"
                break
            fi
        else
            echo "NFS-Server-网络不可达 $(date '+%Y-%m-%d %H:%M:%S')"
        fi
        sleep 3
    done

重载服务

systemctl daemon-reload

重启/启动服务

systemctl start nfs-mount.service

开机自启

systemctl enable nfs-mount.service

curl -L get.gitlab.cn | bash

安装

sudo EXTERNAL_URL="https://gitlab.hckz.top" apt-get install -y gitlab-jh

gitlab配置

vim /etc/gitlab/gitlab.rb

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51

# 证书配置
nginx['ssl_certificate'] = "/etc/gitlab/ssl/gitlab.hckz.top.crt"
nginx['ssl_certificate_key'] = "/etc/gitlab/ssl/gitlab.hckz.top.key"

# 网易邮箱配置
gitlab_rails['smtp_enable'] = true
gitlab_rails['smtp_address'] = "smtp.163.com"
gitlab_rails['smtp_port'] = 465
gitlab_rails['smtp_user_name'] = "xxxxxxxxxxxx@163.com"
gitlab_rails['smtp_password'] = "XXXXXXXXXXXXXXX"
gitlab_rails['smtp_authentication'] = "login"
gitlab_rails['smtp_enable_starttls_auto'] = false
gitlab_rails['smtp_tls'] = true
gitlab_rails['gitlab_email_from'] = 'xxxxxxxxxxxx@163.com'
gitlab_rails['smtp_domain'] = "smtp.163.com"


# 缓冲区
gitlab_rails['git_max_size'] = 1024

# 默认存储路径
git_data_dirs({
"default" => {
    "path" => "/mnt/data/Gitlab-Server"
    }
})

# 禁用 Puma
# 只有一个 Puma 进程可以为应用程序提供服务
# 禁用集群模式
# puma['worker_processes'] = 0

# 优化 Sidekiq
# 并发减少 默认50
sidekiq['max_concurrency'] = 30

# 禁用监控
# 暂时不需要
prometheus_monitoring['enable'] = false

# GitLab 如何处理内存
# 加快释放内存

gitlab_rails['env'] = {
'MALLOC_CONF' => 'dirty_decay_ms:1000,muzzy_decay_ms:1000'
}

gitaly['env'] = {
'MALLOC_CONF' => 'dirty_decay_ms:1000,muzzy_decay_ms:1000'
}

保存配置后重启

sudo gitlab-ctl reconfigure

重启生效

sudo gitlab-ctl restart