使用gitlab在服务器上搭建私服git仓库,并且上传项目

官网:The DevSecOps Platform | GitLab

1.安装gitlab软件:

  • 安装相关依赖:

    复制代码
    yum install -y policycoreutils policycoreutils-python openssh-server open-clients postfix ca-certificates
    # ca-certificates: 不安装下载gitlab包报错--no-check-certificate
  • 设置postfix开机自启,并启动,postfix支持gitlab发信功能

    复制代码
    systemctl start postfix && systemctl enable postfix
  • 下载给gitlab包

    复制代码
    wget https://mirrors.tuna.tsinghua.edu.cn/gitlab-ce/yum/el7/gitlab-ce-12.4.2-ce.0.el7.x86_64.rpm
  • 安装rpm包:

    复制代码
    rpm -ivh gitlab-ce-12.4.2-ce.0.el7.x86_64.rpm
  • 修改gitlab的配置:/etc/gitlab/gitlab.rb

    复制代码
    # 修改gitlab访问地址和端口,默认为80,我们改为82
    sed -i "s/^external_url.*/external_url 'http:\/\/192.168.66.201:82'/" /etc/gitlab/gitlab.rb
    
    # 第一次修改,nginx监听端口
    sed -i "s/^# nginx\['listen_port'\].*/nginx\['listen_port'\] = 82/" /etc/gitlab/gitlab.rb
    # 后面的修改,nginx监听端口
    sed -i "s/^nginx['listen_port'].*/nginx['listen_port'] = 82/" /etc/gitlab/gitlab.rb
    
    # 重新加载配置
    gitlab-ctl reconfigure
  • 重启gitlab服务:

    复制代码
    gitlab-ctl restart
  • 登陆页面:http://192.168.174.201:82,修改root用户密码

  • 使用root用户登陆:

2.配置ssh公钥:

复制代码
ssh-keygen -t rsa -b 1024 -C "用户名/邮箱"
# 如果不指定用户名和邮箱,将默认使用主机的用户名和主机名
# ssh-keygen - 生成、管理和转换认证密钥,t制定类型
# RSA
# window:C:/用户/user/.ssh/id_rsa.pub公钥文件,linux:~/.ssh/id_rsa.pub公钥文件

cat ~/.ssh/id_rsa.pub

3.安装和配置git:

  • 安装:

    复制代码
    yum install -y git
  • 配置:

    复制代码
    git config --global user.name "qv123"
    git config --global user.email "qv1095322098@163.com"
    
    # 查看
    git config --global user.name
    git config --global user.email

4.上传项目:

1.方式一:创建本地项目推送

    • 初始化项目。将项目添加到工作区,或者直接拉取空仓库:

      复制代码
      cd ~/my_hexo && git init
    • 添加远程仓库路径:仓库地址是服务器IP

      复制代码
      git remote add origin git@192.168.174.201:qv123_group/my_hexo.git
      # origin远端名称
      # 查看命令帮助:git remote -help
    • 查看远程仓库得名称和地址:

      复制代码
      git remote -v show
    • 将项目从工作区添加到暂存区:

      复制代码
      git add .
    • 将项目从暂存区提交到本地仓库:(这里必须配置用户名和邮箱地址)

      复制代码
      git commit -m "one commit"
    • 查看本地分支:

      复制代码
      git branch
    • 拉取一下远程的空仓库:

      复制代码
      # 最好拉取一下空仓库,不然可能导致推送错误
      git pull -u origin master
      
      # 报错
      To git@192.168.174.201:qv123_group/my_hexo.git
       ! [rejected]        master -> master (fetch first)
      error: failed to push some refs to 'git@192.168.174.201:qv123_group/my_hexo.git'
      hint: Updates were rejected because the remote contains work that you do
      hint: not have locally. This is usually caused by another repository pushing
      hint: to the same ref. You may want to first merge the remote changes (e.g.,
      hint: 'git pull') before pushing again.
      hint: See the 'Note about fast-forwards' in 'git push --help' for details.
      [root@gitlab-server qv1234.github.io-master]# git pull --rebase origin
      fatal: 'origin' does not appear to be a git repository
      fatal: Could not read from remote repository.
      ​
      Please make sure you have the correct access rights
      and the repository exists.
    • 推送到远程仓库:

      复制代码
      git push -u origin master
      # master是分支

2.方式二:(推荐

    • 直接克隆空仓库:

      复制代码
      git clone git@192.168.174.201:qv123_group/my_hexo.git
      cd my_hexo
    • 查看远程仓库得名称和地址:

      复制代码
      [root@gitlab-server my_hexo]# git remote -v show
      origin  git@192.168.174.201:qv123_group/my_hexo.git (fetch)
      origin  git@192.168.174.201:qv123_group/my_hexo.git (push)
    • 将项目从工作区添加到暂存区:

      复制代码
      git add . --all
    • 将项目从暂存区提交到本地仓库:(这里必须配置用户名和邮箱地址)

      复制代码
      git commit -m "one commit"
    • 查看本地分支:

      复制代码
      git branch
    • 推送到远程仓库:

      复制代码
      git push -u origin master
      # master是分支
相关推荐
Thera7771 分钟前
【Linux C++】彻底解决僵尸进程:waitpid(WNOHANG) 与 SA_NOCLDWAIT
linux·服务器·c++
阿梦Anmory6 分钟前
Ubuntu配置代理最详细教程
linux·运维·ubuntu
呉師傅20 分钟前
【使用技巧】Adobe Photoshop 2024调整缩放与布局125%后出现点菜单项漂移问题的简单处理
运维·服务器·windows·adobe·电脑·photoshop
heartbeat..23 分钟前
JVM 性能调优流程实战:从开发规范到生产应急排查
java·运维·jvm·性能优化·设计规范
小Tomkk1 小时前
数据库 变更和版本控制管理工具 --Bytebase 安装部署(linux 安装篇)
linux·运维·数据库·ci/cd·bytebase
赌博羊1 小时前
ImportError: /lib/x86_64-linux-gnu/libc.so.6: version `GLIBC_2.32‘ not found
linux·运维·gnu
getapi1 小时前
Ubuntu 22.04 服务器的系统架构是否为 amd64 x86_64
linux·服务器·ubuntu
消失的旧时光-19431 小时前
Linux 入门核心命令清单(工程版)
linux·运维·服务器
艾莉丝努力练剑1 小时前
【Linux:文件】Ext系列文件系统(初阶)
大数据·linux·运维·服务器·c++·人工智能·算法
小天源1 小时前
Cacti在Debian/Ubuntu中安装及其使用
运维·ubuntu·debian·cacti