前言
因?yàn)橛行﹤}(cāng)庫(kù)上傳到Github并不是非常合適,所以就搭建了一個(gè)自己的私人倉(cāng)庫(kù)。
在安裝Gogs前,我也嘗試了Gitlab,但Gitlab直接把我的1g小內(nèi)存給吃光了,所以便換了Gogs,后來(lái)發(fā)現(xiàn)只吃了100m的內(nèi)存,效果很不錯(cuò)
環(huán)境
- Ubuntu Server 14.04.1 LTS 64
- 騰訊云乞丐版服務(wù)器 1核 1GB 1Mbps
安裝
配置Gogs所需的環(huán)境
安裝nginx
sudo apt-get install nginx
安裝git
sudo apt-get install git
安裝MySQL
sudo apt-get install mysql-server
進(jìn)入數(shù)據(jù)庫(kù)
mysql -u root -p
創(chuàng)建gogs數(shù)據(jù)庫(kù)
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創(chuàng)建單獨(dú)的用戶
sudo adduser git
....
cd到根目錄,下載Gogs
su git
cd ~
wget https://dl.gogs.io/0.11.4/linux_amd64.zip
unzip linux_amd64.zip
配置與運(yùn)行Gogs
修改Gogs service配置文件
vim /home/git/gogs/scripts/init/debian/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 #這個(gè)根據(jù)自己的目錄修改
DAEMON=$WORKINGDIR/$NAME
DAEMON_ARGS="web"
USER=git #如果運(yùn)行g(shù)ogs不是用的這個(gè)用戶,修改對(duì)應(yīng)用戶
切會(huì)root賬戶然后復(fù)制到/etc/init.d/
sudo cp /home/git/gogs/scripts/init/debian/gogs /etc/init.d/
增加執(zhí)行權(quán)限
sudo chmod +x /etc/init.d/gogs
復(fù)制service
cp /home/git/gogs/scripts/systemd/gogs.service /etc/systemd/system/
啟動(dòng)Gogs
sudo service gogs start
在自己瀏覽器上配置Gogs, localhost替換成自己的ip地址
http://localhost:3000/install
有關(guān)Gogs的配置文件在/home/git/gogs/custom/conf/app.ini里面,相關(guān)配置在Gogs文檔中有。
nginx 反代理
現(xiàn)在訪問(wèn)Gogs都需要在域名后面加入3000的端口號(hào),可以設(shè)置nginx反代理,通過(guò)二級(jí)域名跳轉(zhuǎn)到指定端口
創(chuàng)建相應(yīng)的配置文件
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