Ghost是基于Node.js的开源博客平台,由前WordPress UI部门主管John O’Nolan和WordPress高级工程(女)Hannah Wolfe创立,目的是为了给用户提供一种更加纯粹的内容写作与发布平台.
主机环境:
[root@test ~]# lsb_release -a
LSB Version: :core-4.1-amd64:core-4.1-noarch
Distributor ID: CentOS
Description: CentOS Linux release 7.4.1708 (Core)
Release: 7.4.1708
Codename: Core
[root@test ~]# uname -a
Linux test 3.10.0-693.2.2.el7.x86_64 #1 SMP Tue Sep 12 22:26:13 UTC 2017 x86_64 x86_64 x86_64 GNU/Linux
安装步骤:
安装Node:
[root@test ~]# wget http://nodejs.org/dist/v0.10.40/node-v0.10.40.tar.gz
[root@test ~]# tar -zxvf node-v0.10.40.tar.gz
[root@test ~]# cd node-v0.10.40
[root@test node-v0.10.40]# ls -l
total 320
-rw-rw-r-- 1 root root 19863 Jul 10 2015 AUTHORS
drwxrwxr-x 10 root root 4096 Jul 10 2015 benchmark
-rw-rw-r-- 1 root root 61 Jul 10 2015 BSDmakefile
-rw-rw-r-- 1 root root 136831 Jul 10 2015 ChangeLog
-rw-rw-r-- 1 root root 8853 Jul 10 2015 common.gypi
-rwxrwxr-x 1 root root 21622 Jul 10 2015 configure
-rw-rw-r-- 1 root root 4463 Jul 10 2015 CONTRIBUTING.md
drwxrwxr-x 9 root root 4096 Jul 10 2015 deps
drwxrwxr-x 4 root root 4096 Jul 10 2015 doc
drwxrwxr-x 2 root root 4096 Jul 10 2015 lib
-rw-rw-r-- 1 root root 41412 Jul 10 2015 LICENSE
-rw-rw-r-- 1 root root 10949 Jul 10 2015 Makefile
-rw-rw-r-- 1 root root 16355 Jul 10 2015 node.gyp
-rw-rw-r-- 1 root root 2139 Jul 10 2015 README.md
drwxrwxr-x 3 root root 4096 Jul 10 2015 src
drwxrwxr-x 12 root root 4096 Jul 10 2015 test
drwxrwxr-x 9 root root 4096 Jul 10 2015 tools
-rw-rw-r-- 1 root root 8270 Jul 10 2015 vcbuild.bat
[root@test node-v0.10.40]# ./configure
[root@test node-v0.10.40]# make && make install
[root@test node-v0.10.40]# node -v
v0.10.40 //说明安装成功
安装mysql:
Ghost默认使用sqlite3数据库,对于一般使用足够了,但是内容多的话,就会拖慢整个系统,也就影响页面打开速度了,不想使用Mysql的朋友可以跳过这步.
mysql安装参考:https://www.tracymc.cn/archives/614(yum安装)、https://www.tracymc.cn/archives/218(编译安装)
[root@test node-v0.10.40]# mysql -u root -p
Enter password:
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 3
Server version: 5.5.56-MariaDB MariaDB Server
Copyright (c) 2000, 2017, Oracle, MariaDB Corporation Ab and others.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
MariaDB [(none)]> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| zabbix |
+--------------------+
4 rows in set (0.01 sec)
MariaDB [(none)]>create database ghost;
Query OK, 1 row affected (0.00 sec)
MariaDB [(none)]> grant all on ghost.* to ghost@'localhost' identified by '123456' with grant option; //设置复杂密码,我这是只是测试
Query OK, 0 rows affected (0.01 sec)
MariaDB [(none)]> flush privileges;
Query OK, 0 rows affected (0.00 sec)
MariaDB [(none)]> exit
Bye
安装Ghost:
[root@test ~]# wget http://dl.ghostchina.com/Ghost-0.7.4-zh-full.zip
[root@test ~]# unzip Ghost-0.7.4-zh-full.zip -d ghost
[root@test ~]# cd ghost/
[root@test ghost]# cp config.example.js config.js
[root@test ghost]# vi config.js
Ghost有产品模式、开发模式和测试模式等多种运行模式,这里我们需要在配置文件中找到production模式:
// ### Production
// When running Ghost in the wild, use the production environment.
// Configure your URL and mail settings here
production: {
url: 'http://my-ghost-blog.com',
mail: {},
database: {
client: 'sqlite3',
connection: {
filename: path.join(__dirname, '/content/data/ghost.db')
},
debug: false
},
// 配置MySQL 数据库
/*database: {
client: 'mysql',
connection: {
host : 'host',
user : 'user',
password : 'password',
database : 'database',
charset : 'utf8'
},
debug: false
},*/
server: {
host: '127.0.0.1',
port: '2368'
},
修改为:
// ### Production
// When running Ghost in the wild, use the production environment.
// Configure your URL and mail settings here
production: {
url: 'http://1.2.3.4', //修改为你的域名或者IP,注意加上http://
mail: {},
/* database: { //从这开始注释
client: 'sqlite3',
connection: {
filename: path.join(__dirname, '/content/data/ghost.db')
},
debug: false
},*/ //注释结束,将sqlite3注释修改为mysql
// 配置MySQL 数据库
database: {
client: 'mysql',
connection: {
host : '127.0.0.1',
user : 'ghost',
password : '123456',
database : 'ghost',
charset : 'utf8'
},
debug: false
},
server: {
host: '127.0.0.1',
port: '80'
},
[root@test ghost]# npm start --production
//首次启动
> ghost@0.7.4 start /root/ghost
> node index
Migrations: Database initialisation required for version 004
Migrations: Creating tables...
Migrations: Creating table: posts
Migrations: Creating table: users
Migrations: Creating table: roles
Migrations: Creating table: roles_users
Migrations: Creating table: permissions
Migrations: Creating table: permissions_users
Migrations: Creating table: permissions_roles
Migrations: Creating table: permissions_apps
Migrations: Creating table: settings
Migrations: Creating table: tags
Migrations: Creating table: posts_tags
Migrations: Creating table: apps
Migrations: Creating table: app_settings
Migrations: Creating table: app_fields
Migrations: Creating table: clients
Migrations: Creating table: client_trusted_domains
Migrations: Creating table: accesstokens
Migrations: Creating table: refreshtokens
Migrations: Populating fixtures
Migrations: Populating permissions
Migrations: Creating owner
Migrations: Populating default settings
Migrations: Complete
Ghost is running in production...
Your blog is now available on http://127.0.0.1
Ctrl+C to shut down
浏览器输入127.0.0.1就可以访问博客了.Ctrl+C或者退出SSH终端进程就会停止.
前面提到的启动Ghost使用npm start –production命令.这是一个在开发模式下启动和测试的不错的选择.但是通过这种命令行启动的方式有个缺点.即当你关闭终端窗口或者从SSH断开连接时,Ghost就停止了.为了防止Ghost 停止工作,我们得解决这个问题.
以下有几种解决方案:
PM2(https://github.com/Unitech/pm2)
Forever (https://npmjs.org/package/forever)
Supervisor (http://supervisord.org/)
使用Forever:
[root@test ghost]# npm install forever -g //安装forever
[root@test ghost]# NODE_ENV=production forever start index.js //运行ghost,必须在/root/ghost目录下,不然会报错
[root@test ghost]# forever list //检测ghost是否在运行
info: Forever processes running
data: uid command script forever pid id logfile uptime
data: [0] jz38 /usr/local/bin/node index.js 31223 31225 /root/.forever/jz38.log 0:0:0:16.449
[root@test ghost]# forever stop index.js //停止ghost
info: Forever stopped process:
uid command script forever pid id logfile uptime
[0] jz38 /usr/local/bin/node index.js 31223 31225 /root/.forever/jz38.log 0:0:2:2.84
[root@test ghost]# forever list //没有进程信息了,说明ghost已停止
info: No forever processes running
使用supervisor:
supervisor安装配置参考:https://www.tracymc.cn/archives/599、https://www.tracymc.cn/archives/588
[root@test ghost]# vi /etc/supervisord.d/ghost.ini
[program:ghost]
command = node /root/ghost/index.js
directory = /root/ghost
user = root
autostart = true
autorestart = true
stdout_logfile = /var/log/supervisor/ghost.log
stderr_logfile = /var/log/supervisor/ghost_err.log
environment = NODE_ENV="production"
[root@test ghost]# supervisorctl start ghost //启动ghost
[root@test ghost]# supervisorctl status //查看ghost状态
cesi RUNNING pid 31284, uptime 0:00:36
ghost RUNNING pid 31285, uptime 0:00:36
tomcat RUNNING pid 31283, uptime 0:00:36
[root@test ghost]# supervisorctl stop ghost //停止ghost
ghost: stopped
[root@test ghost]# supervisorctl status //查看ghost状态
cesi RUNNING pid 31284, uptime 0:00:53
ghost STOPPED May 20 11:18 PM
tomcat RUNNING pid 31283, uptime 0:00:53
Be First to Comment