debian 9 安装 gogs+supervisor+nginx反代
前言
分了一台阿里云, 所以在上面跑了debian9, 换了源为163的debian9源(aliyun有点问题), 打算跑个git server, 选了gogs最新版, 使用源码编译安装, 现在记下流水以便后续使用
安装go
全部在root下执行
#wget https://dl.google.com/go/go1.12.4.linux-amd64.tar.gz
#tar -C /usr/local -xzf go1.12.4.linux-amd64.tar.gz
编辑 ~/.basrhc (我用的zsh, 一样的)
export GOROOT=/usr/local/go
export GOBIN=$GOROOT/bin
export GOPATH=/home/go
export GOALL=$GOROOT:$GBIN:$GOPATH:$GOPATH/bin
export PATH=.:$PATH:$GOALL
保存退出后
source ~/.bashrc
执行go 输出go的配置
安装supervisor
aliyun仓库的supervisor 有hash mismatch 问题, 所以我重新用了163的debian strech 源
wget http://mirrors.163.com/.help/sources.list.jessie -O /etc/apt/sources.list
sed 's/jessie'strech/g' /etc/apt/sources.list
apt-get clean
rm -rf /var/lib/apt/lists/
apt-get update && apt-get upgrade -y
apt-get install supervisor
/etc/init.d/supervisor start
安装nginx, mysql
自行搜索
安装配置gogs
我采用编译安装. 服务器上已经配置了nginx和mysql,
mysql端口274400
配置gogs DB
mysql -h127.0.0.1 -uroot -p -P27440
create database if not exists gogs character set utf8 collate utf8_general_ci;
安装gogs
go get -d github.com/gogits/gogs
cd $GOPATH/src/github.com/gogits/gogs
go build
注意这里要保证内存可用. 我这个aliyun是1G的ram, 跑了mysql后只有500M不到, 所以停掉mysql先.
mkdir -p /var/log/gogs
先测试下gogs 直接命令跑
gogs web
启动没有问题, 现在用supervisor来启动, 在/etc/supervisor/conf.d/ 下增加一个gogs,
注意一定要配environment, 不然会报错gogs: ERROR (spawn error) , 因为supervisor 不会读取/etc/profile加载的数据.
[program:gogs]
user=root
environment=HOME="/root",USER="root"
command=/home/go/src/github.com/gogs/gogs/gogs web
autostart=true
autorestart=true
startsecs=10
stdout_logfile=/var/log/gogs/stdout.log
stdout_logfile_maxbytes=1MB
stdout_logfile_backups=10
stdout_capture_maxbytes=1MB
stderr_logfile=/var/log/gogs/stderr.log
stderr_logfile_maxbytes=1MB
stderr_logfile_backups=10
stderr_capture_maxbytes=1MB
保存后加载然后启动
supervisorctl update
nginx反代, 反代3000端口
upstream gogs {
server 127.0.0.1:3000;
}
server {
listen 80;
server_name git.xxx.com git.xxx1.org git.xxx2.com;
charset utf-8;
location / {
proxy_pass http://gogs;
proxy_redirect off;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_next_upstream error timeout invalid_header http_500 http_502 http_503 http_504;
proxy_max_temp_file_size 0;
proxy_connect_timeout 90;
proxy_send_timeout 90;
proxy_read_timeout 90;
proxy_buffer_size 4k;
proxy_buffers 4 32k;
proxy_busy_buffers_size 64k;
proxy_temp_file_write_size 64k;
}
access_log /var/log/nginx/gogs.access.log access;
}
保存后重新reload 下nginx, 这里要配下域名, 我用的子域名 git.xxx.org 来指向gogs服务
然后浏览器输入git.xxx.org 就会跳到install 页面, 注意, 页面有一个选项, 是否使用内建的SSH-server, 不要勾, 我的服务器已经有SSH server了. 端口是27439. 所以要改下端口.
Gogs 在install的时候, 会默认把conf/app.ini 的配置, 复制一份到custom/conf/app.ini, 并且在install的时候会链接数据库.
HTTP_PORT 要填写原始的3000端口, 而不是反代的80.
完整的安装后的app.ini 如下
APP_NAME = Gogs
RUN_USER = root
RUN_MODE = prod
[database]
DB_TYPE = mysql
HOST = 127.0.0.1:27430
NAME = gogs
USER = root
PASSWD = root
SSL_MODE = disable
PATH = data/gogs.db
[repository]
ROOT = /home/gogs_repo
[server]
DOMAIN = git.xxx.org
HTTP_PORT = 3000
ROOT_URL = http://git.xxx.org/
DISABLE_SSH = false
SSH_PORT = 27429
START_SSH_SERVER = false
OFFLINE_MODE = false
[mailer]
ENABLED = false
[service]
REGISTER_EMAIL_CONFIRM = false
ENABLE_NOTIFY_MAIL = false
DISABLE_REGISTRATION = false
ENABLE_CAPTCHA = true
REQUIRE_SIGNIN_VIEW = false
[picture]
DISABLE_GRAVATAR = false
ENABLE_FEDERATED_AVATAR = false
[session]
PROVIDER = file
[log]
MODE = file
LEVEL = Info
ROOT_PATH = /home/go/src/github.com/gogs/gogs/log
[security]
INSTALL_LOCK = true
SECRET_KEY = xxxxxxx
如果安装失败需要重装, 做如下操作
1, drop database gogs; #删除掉数据库, 然后重新创建个
2, rm -rf gogs/custom/ #删除掉自定义配置文件
3, supervisorctl start gogs
我为了干净, 重新go clean && go build了一次. 这样安装完, 就可以登录了