Ubuntu安装Gogs服务

花了半天的时间把阿里云的centos 换成了ubuntu 14.04 lts ,原因是因为我想安装个gogs git服务,但是centos的glibc版本太低,折腾了半天没有成功。

迁移Ghost数据

#更新
sudo apt-get update
sudo apt-get upgrade
sudo apt-get update

#挂载数据盘
sudo mount -rw /dev/xvdb1 /opt/
#注:
sudo mount /dev/xvdb1 /opt/
mount -o remount rw /
#安装node环境
#apt-get install unzip
#wget 
http://nodejs.org/dist/v0.10.33/node-v0.10.33-linux-x64.tar.gz
#tar zxvf node-v0.10.33-linux-x64.tar.gz
#配置环境变量
#vi /etc/profile
#输入保存

#set for nodejs by irving
export NODE_HOME=/opt/node-v0.10.33-linux-x64
export PATH=$NODE_HOME/bin:$PATH
export NODE_PATH=$NODE_HOME/lib/node_modules:$PATH

#保存退出
#:wq
#重启生效
#source /etc/profile
#检查是否安装成功
#node -v
#npm –v
#更换npm源
npm install -g cnpm --registry=
https://registry.npm.taobao.org   (说明:https://npm.taobao.org)
#安装Ghost
wget
http://ghost.org/zip/ghost-latest.zip
unzip -uo ghost-0.5.3.zip -d ghost
#修改配置
复制config.example.js文件重命名/opt/ghost/config.js修改production节点为下面内容,更换为mysql

production: {
        url: 'http://115.29.174.111/',
        mail: {},
        database: {
            client: 'mysql',
            connection: {
                host     : '127.0.0.1',
                user     : 'root',   //我们暂且用 MySQL 的 root 账户
                password : '123456', //输入你的 MySQL 密码
                database : 'ghost',  //我们前面为 Ghost 创建的数据库名称
                charset  : 'utf8'
            }
        },

        server: {
            // Host to be passed to node's `net.Server#listen()`
            host: '127.0.0.1',
            // Port to be passed to node's `net.Server#listen()`, for iisnode set this to `process.env.PORT`
            port: '2368'
        }
    }

#安装包
cd ghost
cnpm install --production

root@AY1406151605405725a8Z:/opt/ghost# cnpm install --production
npm WARN engine html-to-text@0.1.0: wanted: {"node":"~0.8.0"} (current: {"node":"0.10.33","npm":"2.1.6"})

> sqlite3@2.2.7 install /opt/ghost/node_modules/sqlite3
> node-pre-gyp install --fallback-to-build

make: Entering directory `/opt/ghost/node_modules/sqlite3/build'
  ACTION deps_sqlite3_gyp_action_before_build_target_unpack_sqlite_dep Release/obj/gen/sqlite-autoconf-3080500/sqlite3.c
  TOUCH Release/obj.target/deps/action_before_build.stamp
  CC(target) Release/obj.target/sqlite3/gen/sqlite-autoconf-3080500/sqlite3.o
  AR(target) Release/obj.target/deps/sqlite3.a
  COPY Release/sqlite3.a
  CXX(target) Release/obj.target/node_sqlite3/src/database.o
  CXX(target) Release/obj.target/node_sqlite3/src/node_sqlite3.o
  CXX(target) Release/obj.target/node_sqlite3/src/statement.o
  SOLINK_MODULE(target) Release/obj.target/node_sqlite3.node
  SOLINK_MODULE(target) Release/obj.target/node_sqlite3.node: Finished
  COPY Release/node_sqlite3.node
  COPY /opt/ghost/node_modules/sqlite3/lib/binding/node-v11-linux-x64/node_sqlite3.node
  TOUCH Release/obj.target/action_after_build.stamp
make: Leaving directory `/opt/ghost/node_modules/sqlite3/build'
connect-slashes@1.2.0 node_modules/connect-slashes

colors@0.6.2 node_modules/colors

xml@0.0.12 node_modules/xml

node-uuid@1.4.1 node_modules/node-uuid

validator@3.4.0 node_modules/validator

passport-http-bearer@1.0.1 node_modules/passport-http-bearer
忖?passport-strategy@1.0.0

morgan@1.3.1 node_modules/morgan
忖?basic-auth@1.0.0
忖?depd@0.4.5
忖?on-finished@2.1.0 (ee-first@1.0.5)

showdown@0.3.2-ghost node_modules/showdown

passport@0.2.0 node_modules/passport
忖?pause@0.0.1
忖?passport-strategy@1.0.0

semver@2.2.1 node_modules/semver

bcryptjs@0.7.10 node_modules/bcryptjs

fs-extra@0.8.1 node_modules/fs-extra
忖?jsonfile@1.1.1
忖?rimraf@2.2.8
忖?ncp@0.4.2
忖?mkdirp@0.3.5

passport-oauth2-client-password@0.1.1 node_modules/passport-oauth2-client-password
忖?pkginfo@0.2.3
忖?passport@0.1.18 (pause@0.0.1)

oauth2orize@1.0.1 node_modules/oauth2orize
忖?uid2@0.0.3
忖?utils-merge@1.0.0
忖?debug@0.7.4

rss@0.2.1 node_modules/rss
忖?mime@1.2.11

downsize@0.0.5 node_modules/downsize
忖?xregexp@2.0.0

compression@1.1.0 node_modules/compression
忖?vary@1.0.0
忖?on-headers@1.0.0
忖?bytes@1.0.0
忖?debug@2.0.0 (ms@0.6.2)
忖?compressible@2.0.1 (mime-db@1.1.2)
忖?accepts@1.1.2 (negotiator@0.4.9, mime-types@2.0.2)

body-parser@1.8.2 node_modules/body-parser
忖?bytes@1.0.0
忖?media-typer@0.3.0
忖?raw-body@1.3.0
忖?depd@0.4.5
忖?on-finished@2.1.0 (ee-first@1.0.5)
忖?qs@2.2.3
忖?type-is@1.5.2 (mime-types@2.0.2)
忖?iconv-lite@0.4.4

express@4.9.2 node_modules/express
忖?utils-merge@1.0.0
忖?merge-descriptors@0.0.2
忖?fresh@0.2.4
忖?cookie@0.1.2
忖?escape-html@1.0.1
忖?range-parser@1.0.2
忖?cookie-signature@1.0.5
忖?finalhandler@0.2.0
忖?vary@1.0.0
忖?media-typer@0.3.0
忖?parseurl@1.3.0
忖?methods@1.1.0
忖?path-to-regexp@0.1.3
忖?depd@0.4.5
忖?on-finished@2.1.1 (ee-first@1.1.0)
忖?debug@2.0.0 (ms@0.6.2)
忖?qs@2.2.3
忖?etag@1.3.1 (crc@3.0.0)
忖?proxy-addr@1.0.1 (ipaddr.js@0.1.2)
忖?send@0.9.2 (ms@0.6.2, destroy@1.0.3, on-finished@2.1.0, mime@1.2.11)
忖?type-is@1.5.2 (mime-types@2.0.2)
忖?accepts@1.1.2 (negotiator@0.4.9, mime-types@2.0.2)
忖?serve-static@1.6.4 (send@0.9.3)

bluebird@2.3.0 node_modules/bluebird

html-to-text@0.1.0 node_modules/html-to-text
忖?underscore@1.7.0
忖?htmlparser@1.7.7
忖?optimist@0.6.1 (wordwrap@0.0.2, minimist@0.0.10)
忖?underscore.string@2.3.3

lodash@2.4.1 node_modules/lodash

unidecode@0.1.3 node_modules/unidecode

cheerio@0.17.0 node_modules/cheerio
忖?dom-serializer@0.0.1 (domelementtype@1.1.3)
忖?entities@1.1.1
忖?htmlparser2@3.7.3 (domelementtype@1.1.3, domutils@1.5.0, entities@1.0.0, domhandler@2.2.1, readable-stream@1.1.13)
忖?CSSselect@0.4.1 (domutils@1.4.3, CSSwhat@0.4.7)

busboy@0.2.8 node_modules/busboy
忖?readable-stream@1.1.13 (isarray@0.0.1, inherits@2.0.1, string_decoder@0.10.31, core-util-is@1.0.1)
忖?dicer@0.2.3 (streamsearch@0.1.2)

bookshelf@0.7.6 node_modules/bookshelf
忖?inherits@2.0.1
忖?trigger-then@0.3.0
忖?simple-extend@0.1.0
忖?create-error@0.3.1
忖?inflection@1.3.8
忖?semver@2.3.2
忖?backbone@1.1.0 (underscore@1.7.0)
忖?bluebird@2.0.7

knex@0.6.21 node_modules/knex
忖?tildify@0.2.0
忖?interpret@0.3.7
忖?inherits@2.0.1
忖?commander@2.5.0
忖?generic-pool-redux@0.1.0
忖?chalk@0.4.0 (has-color@0.1.7, ansi-styles@1.0.0, strip-ansi@0.1.1)
忖?minimist@0.0.10
忖?semver@2.3.2
忖?mkdirp@0.5.0 (minimist@0.0.8)
忖?readable-stream@1.1.13 (isarray@0.0.1, string_decoder@0.10.31, core-util-is@1.0.1)
忖?bluebird@1.2.4
忖?liftoff@0.11.3 (extend@1.2.1, minimist@0.1.0, resolve@0.7.4, findup-sync@0.1.3)

moment@2.4.0 node_modules/moment

express-hbs@0.7.11 node_modules/express-hbs
忖?readdirp@0.3.3 (graceful-fs@2.0.3, minimatch@0.2.14)
忖?js-beautify@1.4.2 (mkdirp@0.3.5, nopt@2.1.2, config-chain@1.1.8)
忖?handlebars@2.0.0 (optimist@0.3.7, uglify-js@2.3.6)

nodemailer@0.7.1 node_modules/nodemailer
忖?public-address@0.1.1
忖?directmail@0.1.8
忖?he@0.3.6
忖?readable-stream@1.1.13 (isarray@0.0.1, inherits@2.0.1, string_decoder@0.10.31, core-util-is@1.0.1)
忖?simplesmtp@0.3.33 (xoauth2@0.1.8, rai@0.1.11)
忖?mailcomposer@0.2.12 (mime@1.2.11, dkim-signer@0.1.2, follow-redirects@0.0.3, mimelib@0.2.18)
忖?aws-sdk@2.0.5 (xmlbuilder@0.4.2, xml2js@0.2.6, aws-sdk-apis@3.1.10)

mysql@2.1.1 node_modules/mysql
忖?require-all@0.0.3
忖?readable-stream@1.1.13 (isarray@0.0.1, inherits@2.0.1, string_decoder@0.10.31, core-util-is@1.0.1)
忖?bignumber.js@1.0.1

sqlite3@2.2.7 node_modules/sqlite3
忖?set-immediate@0.1.1
忖?nan@1.1.2

安装mysql

sudo apt-get install mysql-server mysql-client (会提示设置密码)
#安全设置

root@AY1406151605405725a8Z:~# sudo mysql_secure_installation 

NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MySQL
      SERVERS IN PRODUCTION USE!  PLEASE READ EACH STEP CAREFULLY!

In order to log into MySQL to secure it, we'll need the current
password for the root user.  If you've just installed MySQL, and
you haven't set the root password yet, the password will be blank,
so you should just press enter here.

//输入安装 MySQL 时为 root 账户设置的密码

Enter current password for root (enter for none): 
OK, successfully used password, moving on...

Setting the root password ensures that nobody can log into the MySQL
root user without the proper authorisation.

//是否修改 root 账户的密码?前面设置过 root 账户的密码了,如果不打算修改密码的话,输入 'n'

You already have a root password set, so you can safely answer 'n'.

Change the root password? [Y/n] n
 ... skipping.

By default, a MySQL installation has an anonymous user, allowing anyone
to log into MySQL without having to have a user account created for
them.  This is intended only for testing, and to make the installation
go a bit smoother.  You should remove them before moving into a
production environment.

//是否删除匿名用户?

Remove anonymous users? [Y/n] y
 ... Success!

Normally, root should only be allowed to connect from 'localhost'.  This
ensures that someone cannot guess at the root password from the network.

//是否禁止 root 账户远程登录?

Disallow root login remotely? [Y/n] y
 ... Success!

By default, MySQL comes with a database named 'test' that anyone can
access.  This is also intended only for testing, and should be removed
before moving into a production environment.

//是否删除 MySQL 默认创建的 test 数据库,并删除所有对 test 数据库的权限设置?

Remove test database and access to it? [Y/n] y
 - Dropping test database...
ERROR 1008 (HY000) at line 1: Can't drop database 'test'; database doesn't exist
 ... Failed!  Not critical, keep moving...
 - Removing privileges on test database...
 ... Success!

Reloading the privilege tables will ensure that all changes made so far
will take effect immediately.

//是否重新加载权限表?

Reload privilege tables now? [Y/n] y
 ... Success!

Cleaning up...

All done!  If you've completed all of the above steps, your MySQL
installation should now be secure.

Thanks for using MySQL!

#配置编码
打开 /etc/mysql/my.cnf 文件,为 [mysqld] 添加如下设置
[mysqld]
collation-server = utf8_unicode_ci
init-connect='SET NAMES utf8'
character-set-server = utf8
一般也会把下面节点也配置下
[client]
default-character-set=utf8
[mysql]
default-character-set=utf8

#
# The MySQL database server configuration file.
#
# You can copy this to one of:
# - "/etc/mysql/my.cnf" to set global options,
# - "~/.my.cnf" to set user-specific options.
# 
# One can use all long options that the program supports.
# Run program with --help to get a list of available options and with
# --print-defaults to see which it would actually understand and use.
#
# For explanations see
# http://dev.mysql.com/doc/mysql/en/server-system-variables.html

# This will be passed to all mysql clients
# It has been reported that passwords should be enclosed with ticks/quotes
# escpecially if they contain "#" chars...
# Remember to edit /etc/mysql/debian.cnf when changing the socket location.
[client]
default-character-set=utf8
port        = 3306
socket        = /var/run/mysqld/mysqld.sock

# Here is entries for some specific programs
# The following values assume you have at least 32M ram

# This was formally known as [safe_mysqld]. Both versions are currently parsed.
[mysqld_safe]
socket        = /var/run/mysqld/mysqld.sock
nice        = 0

[mysqld]
collation-server = utf8_unicode_ci
init-connect='SET NAMES utf8'
character-set-server = utf8
#
# * Basic Settings
#
user        = mysql
pid-file    = /var/run/mysqld/mysqld.pid
socket        = /var/run/mysqld/mysqld.sock
port        = 3306
basedir        = /usr
datadir        = /var/lib/mysql
tmpdir        = /tmp
lc-messages-dir    = /usr/share/mysql
skip-external-locking
#
# Instead of skip-networking the default is now to listen only on
# localhost which is more compatible and is not less secure.
bind-address        = 127.0.0.1
#
# * Fine Tuning
#
key_buffer        = 16M
max_allowed_packet    = 16M
thread_stack        = 192K
thread_cache_size       = 8
# This replaces the startup script and checks MyISAM tables if needed
# the first time they are touched
myisam-recover         = BACKUP
#max_connections        = 100
#table_cache            = 64
#thread_concurrency     = 10
#
# * Query Cache Configuration
#
query_cache_limit    = 1M
query_cache_size        = 16M
#
# * Logging and Replication
#
# Both location gets rotated by the cronjob.
# Be aware that this log type is a performance killer.
# As of 5.1 you can enable the log at runtime!
#general_log_file        = /var/log/mysql/mysql.log
#general_log             = 1
#
# Error log - should be very few entries.
#
log_error = /var/log/mysql/error.log
#
# Here you can see queries with especially long duration
#log_slow_queries    = /var/log/mysql/mysql-slow.log
#long_query_time = 2
#log-queries-not-using-indexes
#
# The following can be used as easy to replay backup logs or for replication.
# note: if you are setting up a replication slave, see README.Debian about
#       other settings you may need to change.
#server-id        = 1
#log_bin            = /var/log/mysql/mysql-bin.log
expire_logs_days    = 10
max_binlog_size         = 100M
#binlog_do_db        = include_database_name
#binlog_ignore_db    = include_database_name
#
# * InnoDB
#
# InnoDB is enabled by default with a 10MB datafile in /var/lib/mysql/.
# Read the manual for more InnoDB related options. There are many!
#
# * Security Features
#
# Read the manual, too, if you want chroot!
# chroot = /var/lib/mysql/
#
# For generating SSL certificates I recommend the OpenSSL GUI "tinyca".
#
# ssl-ca=/etc/mysql/cacert.pem
# ssl-cert=/etc/mysql/server-cert.pem
# ssl-key=/etc/mysql/server-key.pem



[mysqldump]
quick
quote-names
max_allowed_packet    = 16M

[mysql]
default-character-set=utf8
#no-auto-rehash    # faster start of mysql but no tab completition

[isamchk]
key_buffer        = 16M

#
# * IMPORTANT: Additional settings that can override those from this file!
#   The files must end with '.cnf', otherwise they'll be ignored.
#
!includedir /etc/mysql/conf.d/

#重启服务
sudo service mysql restart
mysql -uroot –p
#查看编码
show variables like 'char%';
show variables like 'collation%';

mysql> show variables like 'char%';
+--------------------------+----------------------------+
| Variable_name            | Value                      |
+--------------------------+----------------------------+
| character_set_client     | utf8                       |
| character_set_connection | utf8                       |
| character_set_database   | utf8                       |
| character_set_filesystem | binary                     |
| character_set_results    | utf8                       |
| character_set_server     | utf8                       |
| character_set_system     | utf8                       |
| character_sets_dir       | /usr/share/mysql/charsets/ |
+--------------------------+----------------------------+
8 rows in set (0.00 sec)

mysql> show variables like 'collation%';
+----------------------+-----------------+
| Variable_name        | Value           |
+----------------------+-----------------+
| collation_connection | utf8_general_ci |
| collation_database   | utf8_unicode_ci |
| collation_server     | utf8_unicode_ci |
+----------------------+-----------------+
3 rows in set (0.00 sec)

#创建数据库
SET GLOBAL storage_engine ='InnoDB';
create database ghost;
#安装forever启动服务
cnpm install forever -g
#启动
NODE_ENV=production forever start index.js
#停止
forever stop index.js
#检查Ghost运行情况
forever list

安装nginx

#模块依赖性
gzip 模块需要 zlib 库
rewrite 模块需要 pcre 库
ssl 功能需要 openssl 库
预先编译好的安装包
sudo apt-get install libpcre3 libpcre3-dev libpcrecpp0 libssl-dev zlib1g-dev
cd /opt
wget
http://nginx.org/download/nginx-1.7.7.tar.gz
mkdir nginx
tar zxvf nginx-1.7.7.tar.gz
cd nginx-1.7.7
./configure --prefix=/opt/nginx --with-http_stub_status_module --with-http_gzip_static_module
make && make install
#配置nginx

location / {
            proxy_set_header   X-Real-IP $remote_addr;
            proxy_set_header   Host      $http_host;
            proxy_set_header   X-NginX-Proxy true;
            proxy_pass         http://127.0.0.1:2368;
        }

#检查配置是否正确
/opt/nginx/sbin/nginx -t
#启动
/opt/nginx/sbin/nginx
#重新加载配置
/opt/nginx/sbin/nginx -s reload
#停止
/opt/nginx/sbin/nginx -s stop

导出数据

进入 http://your-domain.com/ghost/debug 页面,导入数据即可。

安装Gogs

#创建用户及安装依赖
sudo apt-get update
sudo apt-get install git
#下载
wget
http://gogs.dn.qbox.me/gogs_v0.5.5_linux_amd64.zip
unzip gogs_v0.5.5_linux_amd64.zip
#创建数据库
可以使用 etc/mysql.sql 来自动创建名为 gogs 的数据库。如果您选择手动创建,请务必将编码设置为 utf8
$mysql -u root -p
DROP DATABASE IF EXISTS gogs;
CREATE DATABASE IF NOT EXISTS gogs CHARACTER SET utf8 COLLATE utf8_general_ci;
#安装supervisord 守护进程
http://supervisord.org/
安装
sudo apt-get install supervisor
#进程
/usr/bin/supervisord             --  supervisor服务守护进程
/usr/bin/supervisorctl           --  supervisor控制台进程
在/etc/supervisor目录中存放着supervisor的配置文件:其中conf.d是一个子目录,其中存放着supervisor监
管的进程的配置信息,一个进程有一个对应的配置文件supervisord.conf是supervisor的主配置文件,定义服务名称以及接口等等。
#配置
现在要用supervisor监控一个脚本进程,在/etc/supervisor/conf.d中新建一个关于这个脚本进程的配置文件
cd /etc/supervisor/conf.d
vim gogs.conf

[program:gogs]
command=/opt/gogs/scripts/start.sh
directory=/opt/gogs
autostart=true
autorestart=true
stdout_logfile=/var/log/supervisor/gogs_supervisor_out.log
stderr_logfile=/var/log/supervisor/gogs__supervisor_err.log

#保存
:qw
#配置更改生效
supervisorctl update 或者用supervisorctl reload 重新重新启动supervisor程序
#查看状态
supervisorctl status
#停止所有gogs
supervisorctl stop all
#启动gogs
supervisorctl start gogs

#查看3000端口进程
lsof -i:3000
netstat -anl | grep "3000"
#查看某一端口是否开放
lsof -i:80
netstat -nupl  (UDP类型的端口)
netstat -ntpl  (TCP类型的端口)

#杀死进程
kill -9 pid

#开启http的UI控制台
修改主配置文件
vim /etc/supervisor/supervisord.conf,添加如下内容:
[inet_http_server]
port = 192.168.1.60:9001 #IP和绑定端口
username = admin #管理员名称
password = 123456 #管理员密码
这样,在浏览器中输入配置中写的地址和端口号,输入配置好的用户名和密码,便可以看到基于网页的控制台

界面。从中,可以察看supervisor监控的>信息,可以察看进程的日志等
#初始化配置
然后访问 /install 来完成首次运行的配置

Refer:
http://docs.ghost.org/zh/installation/deploy/
http://gogs.io/docs/advanced/configuration_cheat_sheet.html

原文地址:https://www.cnblogs.com/Irving/p/4081542.html