1、安装git
#
yum –y install git
#建立用户,若是建立过git又删除,则再建立时,须要指定用户组useradd git -g git
# useradd git
# passwd git
# 受权(gogs的目录,gogs仓库的目录)
# chown -R git:git [gogs的目录]
# chown -R git:git [gogs仓库的目录]
若是提示系统运行用户: git -> root,则在安装页面中,将运行用户由git改成root
# 注意:如下红色不要执行,由于gogs指定git用户运行的话,要求git必须能登陆
# 禁用git用户shell登陆
# vi /etc/passwd
#找到git用户对应的行,将/usr/bin/bash 改成 /usr/bin/git-shell
2、安装gogs
# 上传gogs压缩包到/opt
# 解压后,进入gogs目录下,执行./gogs web
# 浏览器中访问ip:3000,首次访问会有安装向导(只能安装一次,若是想重装,能够删除掉目录再从新解压,因此仓库最好单独指定),
管理员不能用admin。
# 安装完成后,会自动跳转到配置的域名/user/login页面,默认域名为localhost
配置文件路径
Custom config '/opt/gogs/custom/conf/app.ini' not found, ignore this if you're running first time
#防火墙开放3000端口
若是遇到问题:
数据库设置不正确:Error 1071: Specified key was too long; max key length is 767 bytes
ElasicSearch关联的mysql表,插入数据时会有如下提示
ERROR 1071 (42000): Specified key was too long; max key length is 767 bytes
缘由分析:
MySQL的varchar主键只支持不超过767个字节,须要将mysql的字符编码设置为utf8mb4
输入如下命令打开编辑界面
- sudo vi /etc/mysql/my.cnf
在[mysqld]下加入如下配置:
- innodb_file_format=barracuda
- innodb_file_per_table=true
- innodb_large_prefix=true
- character-set-server=utf8mb4
- collation-server=utf8mb4_unicode_ci
- max_allowed_packet=500M
保存完重启后就能插入了。
注意:以上设置在重启mysql后,还须要修改表的row_format
alter
table
<table_name> row_format=dynamic;
alter
table
<table_name> row_format=compressed;
使用命令修改配置,有些配置没法用命令修改
show variables like 'innodb_large%';
set global innodb_large_prefix=1;
# 备份(
仓库和关联的数据库
)
# ./gogs backup
#恢复,--from="备份文件名称(默认备份路径为gogs根目录)"
# ./gogs restore --from="backup_name"
设置开机启动
将gogs/scripts/systemd/gogs.service拷贝到/usr/lib/systemd/system,而后使用命令设置开机启动,若是启动不成功,则须要修改gogs.service中的
WorkingDirectory ExecStart 和 HOME 后面的路径。
# cp /opt/gogs/scripts/systemd/gogs.service /lib/systemd/system
# systemctl enable gogs.service
# systemctl start gogs.service
# systemctl status gogs.service
以上方案重启失败,查询官方GIT,发现有新的脚本,使用新的配置文件,重启时能够实现开机启动,断电后开机则不行,查看系统日志(/var/log/messages),发现gogs在MYSQL以前启动,修改gogs.service,添加mysql依赖After=mysql.service
gogs.service内容:
[Unit]
Description=Gogs
After=syslog.target
After=network.target
After=mariadb.service mysql.service mysqld.service postgresql.service memcached.service redis.service
[Service]
# Modify these two values and uncomment them if you have
# repos with lots of files and get an HTTP error 500 because
# of that
###
#LimitMEMLOCK=infinity
#LimitNOFILE=65535
Type=simple
User=root
Group=root
WorkingDirectory=/opt/gogs
ExecStart=/opt/gogs/gogs web
Restart=always
Environment=USER=root HOME=/opt/gogs
# Hardening
ProtectSystem=full
PrivateDevices=yes
PrivateTmp=yes
[Install]
WantedBy=multi-user.target
3、文档
修改
alter table access row_format=compressed;
alter table access_token row_format=compressed;
alter table action row_format=compressed;
alter table attachment row_format=compressed;
alter table collaboration row_format=compressed;
alter table comment row_format=compressed;
alter table deploy_key row_format=compressed;
alter table follow row_format=compressed;
alter table issue row_format=compressed;
alter table issue_label row_format=compressed;
alter table issue_user row_format=compressed;
alter table label row_format=compressed;
alter table login_source row_format=compressed;
alter table milestone row_format=compressed;
alter table mirror row_format=compressed;
alter table public_key row_format=compressed;
alter table pull_request row_format=compressed;
-- alter table 'release' row_format=compressed;
alter table repository row_format=compressed;
alter table star row_format=compressed;
alter table two_factor row_format=compressed;
alter table two_factor_recovery_code row_format=compressed;
alter table upload row_format=compressed;
alter table user row_format=compressed;
alter table watch row_format=compressed;
alter table protect_branch row_format=compressed;
alter table webhook row_format=compressed;
alter table hook_task row_format=compressed;
alter table protect_branch_whitelist row_format=compressed;