前言
因爲有些倉庫上傳到Github並不是非常合適,所以就搭建了一個自己的私人倉庫。
在安裝Gogs前,我也嘗試了Gitlab,效果很不錯
環境
- Centos7.1
安裝
配置Gogs所需的環境
安裝nginx
sudo apt-get install nginx
安裝git
sudo apt-get install git
安裝MySQL
sudo apt-get install mysql-server
進入數據庫
mysql -u root -p
創建gogs數據庫
SET GLOBAL storage_engine = 'InnoDB';
CREATE DATABASE gogs CHARACTER SET utf8 COLLATE utf8_bin;
GRANT ALL PRIVILEGES ON gogs.* TO ‘root’@‘localhost’ IDENTIFIED BY 'YourPassword';
FLUSH PRIVILEGES;
QUIT;
爲Gogs創建單獨的用戶
sudo adduser git
....
cd到根目錄,下載Gogs
su git
cd ~
wget https://dl.gogs.io/0.11.4/linux_amd64.zip
unzip linux_amd64.zip
配置與運行Gogs
修改Gogs service配置文件
vim /home/git/gogs/scripts/init/centos/gogs
PATH=/sbin:/usr/sbin:/bin:/usr/bin
DESC="Go 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 #如果運行gogs不是用的這個用戶,修改對應用戶
切會root
賬戶然後複製到/etc/init.d/
sudo cp /home/git/gogs/scripts/init/centos/gogs /etc/init.d/
增加執行權限
sudo chmod +x /etc/init.d/gogs
複製service
cp /home/git/gogs/scripts/systemd/gogs.service /etc/systemd/system/
啓動Gogs
sudo service gogs start
在自己瀏覽器上配置Gogs, localhost
替換成自己的ip地址
http://localhost:3000/install
有關Gogs的配置文件在/home/git/gogs/custom/conf/app.ini
裏面,相關配置在Gogs文檔中有。
nginx 反代理
現在訪問Gogs都需要在域名後面加入3000的端口號,可以設置nginx反代理,通過二級域名跳轉到指定端口
創建相應的配置文件
sudo vim /etc/nginx/sites-enabled/gogs.conf
添加
server {
listen 80;
server_name code.limchihi.cn;
location / {
proxy_pass http://127.0.0.1:3000/;
}
}
Done