搭建gogs

我的机器环境:centos 7

1.安装git

yum install git
 
2.安装mysql
gogs的数据存在mysql中,需要安装一个mysql来存数据,当然也有其他的选择,比如sqllite。
mysql安装:
http://www.cnblogs.com/dingxu/p/8927955.html
 
安装好mysql后:
登录到mysql
mysql -uroot -p
 
SET GLOBAL storage_engine = 'InnoDB';                //如果显示没有这个字段的错误,就用default_storage_engine = 'InnoDB'
CREATE DATABASE gogs CHARACTER SET utf8 COLLATE utf8_bin;
GRANT ALL PRIVILEGES ON gogs.* TO ‘root’@‘localhost’ IDENTIFIED BY 'xxxx';
FLUSH PRIVILEGES;
QUIT;
## xxxx是密码

3.安装nginx

yum install nginx    // 默认配置文件安装在/etc/nginx,修改nginx.conf和nginx.conf.default配置文件

 

启动nginx
cd /usr/sbin
./nginx                //启动nginx
./nginx -s quit       //停止nginx
./nginx -s stop      //强制停止,相当于执行 ps -ef 后,找到pid,执行kill -9 pid
./nginx -s reload   //重启,使nginx配置文件做了修改,可以使用此命令 
 
gogs的默认web页面是在3000端口,可以通过nginx来做一个转发,这样直接ip就可以访问了。
 
server {
listen 80;
server_name ip;//ip或者域名
location / {
  proxy_pass http://127.0.0.1:3000/;
  }
}
 

4.安装gogs

1.创建git用户

useradd git
passwd git          //设置密码
 

2.下载解压gogs

切换到git用户
su git
 
cd ~
 
# unzip 命令不可用的话需先安装
unzip linux_amd64.zip

3.配置gogs

vim /home/git/gogs/scripts/init/debian/gogs
 
PATH=/sbin:/usr/sbin:/bin:/usr/bin
DESC="GoGs Git Service"
NAME=gogs
SERVICEVERBOSE=yes
PIDFILE=/var/run/$NAME.pid
SCRIPTNAME=/etc/init.d/$NAME
WORKINGDIR=/home/git/gogs #根据自己的目录修改
DAEMON=$WORKINGDIR/$NAME
DAEMON_ARGS="web"
USER=git #修改对应用户
 

4.切回root,拷贝文件和服务

#拷贝到init.d下
cp /home/git/gogs/scripts/init/debian/gogs /etc/init.d/
#添加可执行权限
chmod +x /etc/init.d/gogs
#拷贝service
cp /home/git/gogs/scripts/systemd/gogs.service /etc/systemd/system/
 

5.启动

systemctl start gogs.service
 
访问ip:3000,也可以用nginx做一个反向代理

配置gogs

修改数据库的配置,ip地址啊,开放注册,管理员设置等
 

 

配置完成后

可以把它理解为一个简单的github来用。还是不错的

 

修改配置

编辑/home/git/gogs/custom/conf/app.ini即可
 
app.ini:
 
[repository]
ROOT = /home/git/gogs-repositories
 
[server]
DOMAIN           = xxx.xxx.xxx.xxx
HTTP_PORT        = 3000
ROOT_URL         = http:// xxx.xxx.xxx.xxx:3000/
DISABLE_SSH      = false
SSH_PORT         = 22
START_SSH_SERVER = false
OFFLINE_MODE     = false
 
[mailer]
ENABLED = false
 
[service]
REGISTER_EMAIL_CONFIRM = false
ENABLE_NOTIFY_MAIL     = false
DISABLE_REGISTRATION   = true
ENABLE_CAPTCHA         = false
REQUIRE_SIGNIN_VIEW    = false
 
[picture]
DISABLE_GRAVATAR        = true
ENABLE_FEDERATED_AVATAR = false
 
[session]
PROVIDER = file
 
[log]
MODE      = file
LEVEL     = Info
ROOT_PATH = /home/git/gogs/log
 
[security]
INSTALL_LOCK = true
SECRET_KEY   = My9SzhERU5PiV6F
 
 
注意:
测试参考文档在做nginx时,通过创建/etc/nginx/sites-available/gogs.conf或者/etc/nginx/sites-enabled/gogs.conf文件,nginx不生效,通过修改nginx.conf和nginx.conf.default配置文件才成功反向代理
gogs.conf:
server {
        listen 80;
        server_name  127.0.0.1;
        location / {
                proxy_pass http://127.0.0.1:3000/;
                proxy_redirect default;
        }
}
 
 
 posted on 2018-04-24 12:24  ding-xu  阅读(3195)  评论(0编辑  收藏  举报