在CentOS7.2上安装Ghost

  1. 部署环境
    CentOS7.2 1核1G

  2. 安装g++编译器

    yum update -y
    yum list gcc-c++
    yum install gcc-c++.x86_64 -y
  3. 安装Nodejs
    目前Node.js v4.2.0 LTS 已经成为Ghost推荐版本

    wget https://nodejs.org/download/release/v4.2.0/node-v4.2.0.tar.gz
    tar zxvf node-v4.2.0.tar.gz
    cd node-v4.2.0
    ./configure 
    make && make install  

    编译安装大约15分钟

  4. 安装Nginx

    vi /etc/yum.repos.d/nginx.repo 

    写入以下内容

    [nginx] 
    name=nginx repo  
    baseurl=http://nginx.org/packages/centos/$releasever/$basearch/  
    gpgcheck=0  
    enabled=1  

    安装Nginx

    yum install nginx -y

    运行Nginx

    systemctl start nginx

    配置文件

    vi /etc/nginx/conf.d/ghost.conf 

    写入以下内容

    server {  
    listen 80;
    server_name example.com; #将 example.com 改为自己的域名
    
    location / {
      proxy_set_header   X-Real-IP $remote_addr;
      proxy_set_header   Host      $http_host;
      proxy_pass         http://127.0.0.1:2368;
    }
    }

    重启Nginx

    systemctl restart nginx

    设置为开机启动

    systemctl enable nginx
  5. 安装MariaDB

    sudo yum install mariadb-server -y
    sudo systemctl enable mariadb
    sudo systemctl start mariadb
    sudo mysql_secure_installation
    

    登录MariaDB

    mysql -u root -p

    使用q来退出

    为了避免数据库存放的中文是乱码,我们还需要设置Mysql的编码

    vi /etc/my.cnf

    写入以下内容

    [client]
    default-character-set=utf8  
    [mysql]
    default-character-set=utf8  
    [mysqld]
    character-set-server=utf8  
    collation-server=utf8_general_ci  

    重启MariaDB

    systemctl restart mariadb

    新建一个数据库,用来存放Ghost博客的数据
    登录数据库 mysql -u root -p
    创建ghost数据库 create database ghost;
    新建一个用户ghost,密码为123456 grant all privileges on ghost.* to 'ghost'@'%' identified by '123456';
    让权限生效 flush privileges;

  6. 安装Ghost(Ghost v0.7.4 full (zh))

    mkdir /var/www && cd /var/www
    wget http://dl.ghostchina.com/Ghost-0.7.4-zh-full.zip
    unzip Ghost-0.7.4-zh-full.zip -d ghost
    cd ghost 
    cp config.example.js config.js

    配置文件vi config.js
    Ghost有产品模式、开发模式和测试模式等多种运行模式,这里我们需要在配置文件中找到production模式,如下图所示
    在CentOS7.2上安装Ghost

    见证奇迹的时刻(启动Ghost)

    npm start --production  

    在CentOS7.2上安装Ghost

  7. 让 Ghost 一直运行
    参考Ghost中文社区的文章 http://docs.ghostchina.com/zh...

  8. 参考资料
    https://www.linode.com/docs/d...
    https://snowz.me/how-to-insta...
    http://www.loyalsoldier.me/de...
    http://docs.ghostchina.com/zh...