云计算百科
云计算领域专业知识百科平台

Linux 安装 Git 服务器

一、安装 Git

1. 在 CentOS/RHEL 中使用以下命令:

sudo yum update -y # 或者 `sudo dnf update -y` (在较新的系统中)
sudo yum install git -y

验证安装:git –version

2. 配置 Git 用户

git config –global user.name "Your Name"
git config –global user.email "your.email@example.com"

3. 初始化裸仓库 同样在 /srv/git 目录下创建裸仓库:

sudo mkdir -p /srv/git
cd /srv/git
sudo git init –bare myproject.git
sudo chown -R <your-user>:<your-group> /srv/git/myproject.git

4. 配置 SSH 访问(同 Ubuntu 方法)


二、安装 GitLab

1. 安装必要依赖

在 CentOS 或 RHEL 上,运行以下命令:

sudo yum install -y curl policycoreutils openssh-server perl
sudo systemctl enable sshd
sudo systemctl start sshd

2. 添加 GitLab 包并安装

运行以下脚本添加 GitLab 仓库并安装:

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

3. 配置 GitLab 安装后,使用以下命令完成初始化:

sudo gitlab-ctl reconfigure

默认的访问地址为 http://< your-server-ip >。


安装过程如遇到下列相关问题可以参考如下解决办法:

  • 一直卡在这个界面,说明镜像源使用的国外 YUM 源或者网络访问比较慢。
  • [root@git home]# curl s https://packages.gitlab.com/install/repositories/gitlab/gitlab-ee/script.rpm.sh | sudo bash
    Detected operating system as centos/7.
    Checking for curl...
    Detected curl...
    Downloading repository file: https://packages.gitlab.com/install/repositories/gitlab/gitlab-ee/config_file.repo?os=centos&dist=7&source=script

    解决办法:设置国内镜像源,替换 GitLab 的 YUM 源,编辑 /etc/yum.repos.d/gitlab-ee.repo 文件,将所有 packages.gitlab.com 替换为以下镜像源之一:

    • 清华大学镜像:

    https://mirrors.tuna.tsinghua.edu.cn/gitlab-ce/yum

    • 阿里云镜像:

    https://mirrors.aliyun.com/gitlab-ce/yum

    例如,修改后的内容:

    [gitlabee]
    name=gitlabee
    baseurl=https://mirrors.tuna.tsinghua.edu.cn/gitlabee/yum/el$releasever
    repo_gpgcheck=1
    gpgcheck=1
    enabled=1
    gpgkey=https://mirrors.tuna.tsinghua.edu.cn/gitlabce/yum/RPMGPGKEYgitlab

    清理缓存并安装

    sudo yum clean all
    sudo yum makecache
    sudo yum install gitlab-ee -y

    GitLab 的默认端口通常如下:

    1.HTTP 端口:80
    2.HTTPS 端口:443(如果启用了 HTTPS)
    3.SSH 端口(用于 Git 操作):22

    通过 http://ipdi地址:端口/ 访问 GitLab 时提示登录页面,这说明 GitLab 已成功运行。在首次安装 GitLab 时,会提示你设置管理员账号和密码。如果你未设置过,默认的管理员账号和初始密码可以参考以下方法:

    三、登录Gitlab可视化界面

    1. 默认管理员账号

    root

    2. 查找初始密码

    GitLab 在首次启动时,会随机生成一个管理员密码并存储在 /etc/gitlab/initial_root_password 文件中。通过以下命令查看:

    sudo cat /etc/gitlab/initial_root_password

    你将看到类似以下内容:

    # WARNING: This value is valid only in the first 24 hours after installation!
    Password: 3uqmJr4!hIhRVShMR***

    注意: • 如果你已经更改过密码,但忘记了,可以参考以下步骤进行重置。 • 该密码通常在首次启动后24小时有效,超过时间需要手动重置。

    3. 重置管理员密码

    如果你忘记了管理员密码,按照以下步骤重置:

    步骤 1:进入 GitLab Rails 控制台,运行以下命令启动 GitLab Rails 控制台:

    sudo gitlab-rails console

    步骤 2:重置密码,在 Rails 控制台中输入以下命令:

    user = User.find_by(username: "root")
    user.password = "new_password"
    user.password_confirmation = "new_password"
    user.save!

    将 “new_password” 替换为你希望设置的新密码。

    步骤 3:退出控制台,输入 exit 退出控制台。

    4. 登录验证

    使用以下信息登录 GitLab: • 用户名:root • 密码:查找到的初始密码或重置后的新密码。

    赞(0)
    未经允许不得转载:网硕互联帮助中心 » Linux 安装 Git 服务器
    分享到: 更多 (0)

    评论 抢沙发

    评论前必须登录!