更建议参考使用 GitLab的替代者-轻量级Gitea安装与配置,功能更完善,尤其是作为大规模项目的镜像的情况。
Gogs项目开发进展比较缓慢,功能缺陷较多,Gitea 项目继承自 Gogs 项目。
前置条件
- ubuntu 24.04.2 LTS
动手实践
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 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
# 安装 podman $ sudo apt install podman # 创建一个低权限用户,尽量不要使用root用户,身份操作podman,降低安全风险 $ sudo adduser podman # 允许用户下的容器在系统启动的时候启动服务 $ sudo loginctl enable-linger podman # 退出当前用户,切换到刚刚创建的低权限用户, 注意,不要使用 su - user 的方式切换,后续会执行各种报错 # 如果使用 su user 切换会导致环境变量被带到新用户,导致执行报错 # ERRO[0000] XDG_RUNTIME_DIR directory "/run/user/1000" is not owned by the current user # Error running systemd as user - Failed to connect to bus: $DBUS_SESSION_BUS_ADDRESS and $XDG_RUNTIME_DIR not defined # 或者在使用 systemctl --user daemon-reload 之类的命令报错 # Systemd User Services: Failed to connect to bus $ exit # 通过 ssh 登录用户名 podman 密码是创建用户的时候设置的密码,解决报错问题 $ ssh xxx.xxx.xxx.xxx -l podman # 准备本地目录映射 $ mkdir ~/.dockers $ mkdir ~/.dockers/gogs $ podman pull ghcr.io/gogs/gogs:latest # 此处我们 默认不导出 ssh 访问,只允许 http 访问 $ podman run -d --cpus=2 --name gogs -p 10880:3000 -v /home/podman/.dockers/gogs:/data gogs/gogs # 每次都启动新容器方式创建servcie //--new参数,每次启动都删除旧容器,启动一个新容器 $ podman generate systemd --restart-policy=always -n --new -f gogs # 保存到 ~/.config/systemd/user/ $ mkdir .config $ mkdir .config/systemd $ mkdir .config/systemd/user $ mv container-gogs.service ~/.config/systemd/user/ # 刷新配置文件,让其生效 $ systemctl --user daemon-reload # 上述命令如果报错 Failed to connect to bus # 一般是通过 su - 切换账号导致的,需要退出当前的SSH登录 # 重新通过 ssh 登录,用户名 podman 密码是创建用户的时候设置的密码 # 设置容器开机自启,并且现在启动 $ systemctl --user enable --now ~/.config/systemd/user/container-gogs.service # 如果需要进入容器查看执行情况,参考如下命令 # podman exec -it container-gogs bash # 查看日志 # podman logs -f -t gogs # 测试,重启系统,观察是否能开机自动启动 $ sudo reboot # 启动或重启服务 # systemctl --user start container-gogs.service # systemctl --user restart container-gogs.service # 如果启动失败,观察服务日志 # journalctl --user -xeu container-gogs.service # 或者 # sudo journalctl -f |
访问配置,在地址栏输入 http://xxx.xxx.xxx.xxx:10880 进入配置页面,如下图:
后续如果需要修改配置,可以通过调整修改 /home/podman/.dockers/gogs/gogs/conf/app.ini 解决。
/home/podman/.dockers/gogs/gogs/conf/app.ini
INI
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 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 |
; The brand name of the application, can be your company or team name. BRAND_NAME = Gogs ; The system user who should be running the applications. It has no effect on Windows, ; otherwise, it should match the value of $USER environment variable. RUN_USER = git ; The running mode of the application, can be either "dev", "prod" or "test". RUN_MODE = prod [database] ; The database backend, either "postgres", "mysql" "sqlite3" or "mssql". ; You can connect to TiDB with MySQL protocol. TYPE = sqlite3 HOST = 127.0.0.1:5432 NAME = gogs ; For "postgres" only SCHEMA = public USER = gogs PASSWORD = ; For "postgres" only, either "disable", "require" or "verify-full". SSL_MODE = disable ; For "sqlite3" only, make sure to use absolute path. PATH = data/gogs.db [repository] ; The root path for storing managed repositories, default is "~/gogs-repositories" ROOT = /data/git/gogs-repositories ; Default branch name when creating new repositories. DEFAULT_BRANCH = master [server] ; The public-facing domain name for the application. DOMAIN = www.mobibrw.com ; The port number to be listened by the application. HTTP_PORT = 3000 ; The public-facing URL for the application. EXTERNAL_URL = %(PROTOCOL)s://%(DOMAIN)s:%(HTTP_PORT)s/gogs-git-mirror ; Local (DMZ) URL for workers (e.g. SSH update) accessing web service. ; In most cases you do not need to change the default value. ; Alter it only if your SSH server node is not the same as HTTP node. LOCAL_ROOT_URL = %(PROTOCOL)s://%(HTTP_ADDR)s:%(HTTP_PORT)s/gogs-git-mirror ; Whether to enable application level GZIP compression. ENABLE_GZIP = true ; Whether to disable SSH access to the application entirely. DISABLE_SSH = true ; The port number to be exposed in SSH clone URL. SSH_PORT = ; Whether to start a builtin SSH server. START_SSH_SERVER = false ; Whether to disable using CDN for static files regardless. OFFLINE_MODE = true [email] ; Whether to enable the email service. ENABLED = false [auth] REQUIRE_EMAIL_CONFIRMATION = false DISABLE_REGISTRATION = true ENABLE_REGISTRATION_CAPTCHA = false REQUIRE_SIGNIN_VIEW = false [user] ENABLE_EMAIL_NOTIFICATION = false [picture] DISABLE_GRAVATAR = true ENABLE_FEDERATED_AVATAR = false [session] PROVIDER = file [log] MODE = file LEVEL = Info ROOT_PATH = /app/gogs/log [security] INSTALL_LOCK = true SECRET_KEY = xxxxxx [i18n] LANGS = zh-CN,en-US NAMES = 简体中文,English ; Used for jQuery DateTimePicker, ; list of supported languages in https://xdsoft.net/jqplugins/datetimepicker/#lang [i18n.datelang] zh-CN = zh en-US = en |