使用Gogs安装搭建git仓库

本文中的配置需要打开10080和10022两个端口访问权限。

(1)CentOS 安装 Docker CE

警告:切勿在没有配置 Docker YUM 源的情况下直接使用 yum 命令安装 Docker.

Docker CE 支持 64 位版本 CentOS 7,并且要求内核版本不低于 3.10。

查看centos 内核版本 :cat /etc/redhat-release

安装教程链接:https://yeasy.gitbooks.io/docker_practice/content/install/centos.html

①旧版本的 Docker 称为 docker 或者 docker-engine,使用以下命令卸载旧版本:

yum remove docker \
                  docker-client \
                  docker-client-latest \
                  docker-common \
                  docker-latest \
                  docker-latest-logrotate \
                  docker-logrotate \
                  docker-selinux \
                  docker-engine-selinux \
                  docker-engine

②使用 yum 安装

执行以下命令安装依赖包:

yum install -y yum-utils \
           device-mapper-persistent-data \
           lvm2

执行完毕截图:

执行下面的命令添加 yum 软件源:

(鉴于国内网络问题,强烈建议使用国内源,官方源请在注释中查看。)

 yum-config-manager \
    --add-repo \
    https://mirrors.ustc.edu.cn/docker-ce/linux/centos/docker-ce.repo


#官方源
yum-config-manager \
     --add-repo \
     https://download.docker.com/linux/centos/docker-ce.repo

执行完毕截图:

③安装 Docker CE

更新 yum 软件源缓存,并安装 docker-ce

yum makecache fast


yum install docker-ce

④启动 Docker CE

systemctl enable docker

systemctl start docker

⑤测试 Docker 是否安装正确

$ docker run hello-world

Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
d1725b59e92d: Pull complete
Digest: sha256:0add3ace90ecb4adbf7777e9aacf18357296e799f81cabc9fde470971e499788
Status: Downloaded newer image for hello-world:latest

Hello from Docker!
This message shows that your installation appears to be working correctly.

To generate this message, Docker took the following steps:
 1. The Docker client contacted the Docker daemon.
 2. The Docker daemon pulled the "hello-world" image from the Docker Hub.
    (amd64)
 3. The Docker daemon created a new container from that image which runs the
    executable that produces the output you are currently reading.
 4. The Docker daemon streamed that output to the Docker client, which sent it
    to your terminal.

To try something more ambitious, you can run an Ubuntu container with:
 $ docker run -it ubuntu bash

Share images, automate workflows, and more with a free Docker ID:
 https://hub.docker.com/

For more examples and ideas, visit:
 https://docs.docker.com/get-started/

若能正常输出以上信息,则说明安装成功。

(2)安装Gogs

这里只介绍一下docker方式去安装部署Gogs。

教程链接:使用Docker搭建git服务Gogs - 简书

①首先拉取gogs镜像

docker pull gogs/gogs

②创建本地目录存放数据

mkdir -p /var/gogs

③使用run命令绑定端口和一些配置文件

docker run -d --name=mygogs -p 10022:22 -p 10080:3000 -v /var/gogs:/data gogs/gogs
注:

这里-d将容器跑到后台,不在当前终端输出
-p用来配置外置端口和内置端口的对应关系,将10022转到22端口,将10080转到3000端口
--name用来给这个容器命名,不能重名
-v用来配置数据的对应关系
想要了解更多,需要系统的学习docker相关

(3)配置Gogs

访问:http://服务器ip地址:10080   会出现一个安装页面。

需要把一些本地的IP地址改为服务器IP地址,并且如果默认“数据库名称”是gogs的话,并且使用mysql作为数据库的话。

需要在mysql中新建gogs的数据库,采用utf8mb4编码。并且配置外部IP访问授权。

注意:

mysql数据库版本需要>=5.7 才可以。

mysql增加权限:

GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'ceshi' WITH GRANT OPTION;

FLUSH PRIVILEGES;

可以选择使用mysql作为数据库,但是稍微麻烦一点,需要在mysql配置一下授权,如果不想麻烦,那可以直接使用sqlite3作为数据库,免去了配置数据库

几个ip很重要,可以按我给的配置来填写,当然刚开始填错了也可以后来在app.ini中修改。

邮件服务配置的可以自行选择是否需要

建议不要使用内置ssh,反正笔者试过使用内置ssh可能出现权限拒绝问题,没看到好的解决办法。

安装好需要注册登录:


(4)重新配置Gogs

  1. 删除gogs数据库
  2. 停止gogs容器,docker stop mygogs
  3. 删除gogs下面所有文件  ,命令: rm -rf /var/gogs
  4. 重新启动gogs容器,docker start mygogs
  5. 新建数据库 gogs
  6. 继续访问页面 http://IP:10080  安装

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值