之前研究过一段时间的Node.js,也找到过几个不错的站,其中Ghost博客就是一个用Node.js写的开源博客,好久没弄了,接下来尝试在新环境配置一下。

默认是装过LNMP环境的,如果没有,先装nginx

sudo yum install nginx -y
sudo service nginx start 开启nginx
sudo chkconfig nginx on 设置nginx为开机启动

首先安装Node.js和npm

[[email protected] ~]# node -v
-bash: node: command not found
[[email protected] ~]# curl -sL https://rpm.nodesource.com/setup | bash -
[[email protected] ~]# yum install -y nodejs
[[email protected] ~]# yum install -y gcc-c++ make
[[email protected] ~]# node -v
v0.10.48
[[email protected] ~]# curl -L https://www.npmjs.com/install.sh | sh
[[email protected] ~]# npm -v
4.2.0
[[email protected] ~]# sudo ln -s /usr/local/bin/node /usr/bin/node
ln: creating symbolic link `/usr/bin/node': File exists

接下来下载Ghost博客

[[email protected] ~]# curl -L https://ghost.org/zip/ghost-latest.zip -o ghost.zip
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100 4091k  100 4091k    0     0  82370      0  0:00:50  0:00:50 --:--:--  237k
[[email protected] ~]# unzip -uo ghost.zip -d ghost
[[email protected] ~]# mv ghost /home/wwwroot/
[[email protected] ~]# cd /home/wwwroot/
[[email protected] wwwroot]# ls
default  ghost  testweb  wordpress-4.7.2-zh_CN.tar.gz[[email protected] wwwroot]# cd ghost/
[[email protected] ghost]# npm install –production
npm WARN npm npm does not support Node.js v0.10.48
npm WARN npm You should probably upgrade to a newer version of node as we
npm WARN npm can't make any promises that npm will work with this version.
npm WARN npm You can find the latest version at https://nodejs.org/
npm ERR! arg Argument starts with non-ascii dash, this is probably invalid: [ '–production' ]
npm ERR! addLocal Could not install /home/wwwroot/ghost/–production

3.安装到这里后发现版本不支持,卸载掉再研究吧。

[[email protected] ~]# yum remove nodejs npm -y

重新安装Node.js,根据Ghost官方的建议,这次安装v0.10.40版本

[[email protected] ~]# wget http://nodejs.org/dist/v0.10.40/node-v0.10.40.tar.gz
[[email protected] ~]# tar zxvf node-v0.10.40.tar.gz
[[email protected] ~]# cd node-v0.10.40
[[email protected] ~]# ./configure
[[email protected] ~]# make && make install
[[email protected] ~]# node -v
v0.10.40
[[email protected] ~]# npm -v
1.4.28

下载Ghost

[[email protected] ~]# wget http://dl.ghostchina.com/Ghost-0.7.4-zh-full.zip
[[email protected] ~]# unzip Ghost-0.7.4-zh-full.zip -d ghost
[[email protected] ~]# mv ghost /home/wwwroot/
[[email protected] ghost]# cd  /home/wwwroot/
[[email protected] wwwroot]# chmod -R 777 ghost
chmod: changing permissions of 'ghost/.user.ini': Operation not permitted
[[email protected] wwwroot]# cd ghost
[[email protected] ghost]# cp config.example.js config.js
[[email protected] ghost]# ls
config.example.js  content  Gruntfile.js  LICENSE       npm-shrinkwrap.json  PRIVACY-en.md  README-en.md  SECURITY-en.md
config.js          core     index.js      node_modules  package.json         PRIVACY.md     README.md
[[email protected] ghost]# vim config.js
 production: {
 url: 'http://ghost.kokwind.net', 如果选择使用sqlite则在config.js中只需要修改url地址
 mail: {},
 database: {
 client: 'sqlite3',
 connection: {
 filename: path.join(__dirname, '/content/data/ghost.db')
 },
 debug: false
 },

Ghost-0.7.4-zh-full这个版本默认集成 sqlite3 原生库,因sqlite读写数据量太大时会影响速度,我们也可以改用mysql

首先 使用phpmyadmin,添加用户和数据库

修改config.js,变成mysql

[[email protected] ~]# vim config.js
production: {  
    url: 'http://ghost.kokwind.net', //这里是你自己VPS主机的域名
    mail: {},
    database: {
        client: 'mysql'
        connection: {
            host     : '127.0.0.1',
            user     : 'ghost', //mysql用户名
            password : 'xxxxxxxx', //密码
            database : 'ghost', //之前创建的ghost数据库名称
            charset  : 'utf8'
        },
    server: {
            host: '127.0.0.1',
            port: '2368'//若修改该端口记得在nginx中做相应改变
        }
    }

配置nginx,PS:之前忘了写,在搬瓦工上配置才想起来,贴过来补上。

[[email protected] ~]# cd /usr/local/nginx/conf/vhost
[[email protected] vhost]# cp www.kokwind.net.conf blog.kokwind.net.conf
[[email protected] vhost]# vim blog.kokwind.net.conf
server
    {
        listen 80;
        #listen [::]:80;
        server_name xxx.kokwind.net; <-- 网址
        index index.html index.htm index.php default.html default.htm default.php;
        root  /home/wwwroot/ghost; <-- ghost路径

        include none.conf;
        #error_page   404   /404.html;
        include enable-php.conf;

        location / {
            proxy_set_header   X-Real-IP $remote_addr;
            proxy_set_header   Host      $http_host;
            proxy_pass         http://127.0.0.1:2368;
            proxy_set_header REMOTE-HOST $remote_addr;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        }

        access_log  /home/wwwlogs/ghost.log;
    }
[[email protected] vhost]# /etc/init.d/nginx  reload
Reload service nginx...  done

现在可以启动ghost博客了

[[email protected] ~]# cd /home/wwwroot
[[email protected] wwwroot]# cd ghost
[[email protected] ghost]# ls
config.example.js content Gruntfile.js LICENSE npm-debug.log package.json PRIVACY.md README.md
config.js core index.js node_modules npm-shrinkwrap.json PRIVACY-en.md README-en.md SECURITY-en.md
[[email protected] ghost]# npm start

> [email protected] start /home/wwwroot/ghost
> node index

Migrations: Up to date at version 004
Ghost is running in development...
Listening on 127.0.0.1:2368
Url configured as: http://localhost:2368
Ctrl+C to shut down

访问网址可以看到

如果是通过 npm start 启动 Ghost 的话,只要你关闭了远程连接,Ghost 也就停了,所以需要安装 forever

[[email protected] bin]# which node
/usr/local/bin/node
[[email protected] bin]# ln -s /usr/local/bin/node /usr/bin/node
[[email protected] bin]# npm install forever -g

注意:这条指令将 forever 安装到全局环境。安装的时候系统会提示一些 WARN,这是因为 forever 依赖的 Node.js 版本过低,没关系,不用理会。

[[email protected] ~]# service nginx restart
Stoping nginx...  done
Starting nginx...  done
[[email protected] ~]# cd /home/wwwroot/ghost
[[email protected] ghost]# NODE_ENV=production forever start index.js
warn:    --minUptime not set. Defaulting to: 1000ms
warn:    --spinSleepTime not set. Your script will exit if it does not stay up for at least 1000ms
info:    Forever processing file: index.js
[[email protected] ghost]#

不顺利的开始,顺利的结局。over!

追记: 在搬瓦工上同样配置启动时,出现了下面的错误

[[email protected] ghost]# npm start

> [email protected] start /home/wwwroot/ghost
> node index


ERROR: Cannot find module '/home/wwwroot/ghost/node_modules/sqlite3/lib/binding/node-v11-linux-ia32/node_sqlite3.node'

 Error: Cannot find module '/home/wwwroot/ghost/node_modules/sqlite3/lib/binding/node-v11-linux-ia32/node_sqlite3.node'
    at Function.Module._resolveFilename (module.js:338:15)
    at Function.Module._load (module.js:280:25)

重装了一下sqlite3就好了

[[email protected] ghost]# npm install sqlite3 --save
|
> [email protected] install /home/wwwroot/ghost/node_modules/sqlite3
> node-pre-gyp install --fallback-to-build
Copyright © OneZos all right reserved,powered by Gitbook本书发布时间: 2021-06-09 09:52:22

results matching ""

    No results matching ""