Ghost 1.0+ 安装(非ghost-cli方式)

系统:Centos 7.3

安装Node.js (6.X)

参考 https://nodejs.org/en/download/package-manager/

  1. curl --silent --location https://rpm.nodesource.com/setup_6.x | sudo bash -
  2. sudo yum -y install nodejs

安装Mariadb

Mariadb 官方

  1. 添加源 使用清华源 /etc/yum.repos.d/mariadb.repo

    # MariaDB 10.2 CentOS repository list - created 2017-08-15 08:02 UTC
    # http://downloads.mariadb.org/mariadb/repositories/
    [mariadb]
    name = MariaDB
    baseurl = https://mirrors.tuna.tsinghua.edu.cn/mariadb/yum/10.2/centos7-amd64
    gpgkey= https://mirrors.tuna.tsinghua.edu.cn/mariadb/yum/RPM-GPG-KEY-MariaDB
    gpgcheck=1````
    
    
  2. sudo yum install MariaDB-server MariaDB-client

安装Ghost

  1. 下载
    mkdir ghost && cd ghost && \
    wget https://github.com/TryGhost/Ghost/releases/download/1.7.1/Ghost-1.7.1.zip -O ghost.zip && \
    unzip ghost.zip && \
    npm install --production 
    
  2. 新建文件 config.production.json 参考:config
{
  "url":"网站",
      "database": {
          "client": "mysql",
          "connection": {
              "host": "127.0.0.1",
              "user": "数据库用户名",
              "password": "密码",
              "database": "ghost"
          }
      }, 
      "logging": {
          "level": "info",
          "rotation": {
              "enabled": true
          },
          "transports": [
              "stdout"
          ]
      }
  }

3.初始化数据库 NODE_ENV=production knex-migrator init
4. 运行 npm start --production
5. 添加到系统服务 /etc/systemd/system/ghost.service

[Unit]
Description=ghost
After=network.target

[Service]
Type=simple
WorkingDirectory=/home/ghost #目录
User=ghost  #用户名 
Group=ghost #用户组   

ExecStart=/usr/bin/npm start --production
  
#ExecStart=/home/ghost/.nvm/versions/node/v6.11.2/bin/node index
#Environment=NODE_ENV=production
#Environment=PATH=/usr/bin:/usr/local/bin:/home/ghost/.nvm/versions/node/v6.11.2/bin

Restart=always
SyslogIdentifier=Ghost

[Install]
WantedBy=multi-user.target  
  1. 启动 systemctl start ghost
  2. 开机启动 systemctl enable ghost

安装Nginx

Nginx

  1. 添加源 /etc/yum.repos.d/nginx.repo
    [nginx]
    name=nginx repo
    baseurl=http://nginx.org/packages/centos/7/$basearch/
    gpgcheck=0
    enabled=1
    
  2. yum install nginx
  3. 配置ngixn反代 /etc/nginx/conf.d/ghost.conf
    server{  
        listen 80 ;
        server_name 域名;
    
        charset utf-8;
        location / {
            client_max_body_size 120m; 
            proxy_set_header X-Forwarded-For ass;
            proxy_set_header   Host      $http_host;
            proxy_set_header X-Forwarded-Proto $scheme;
    
            proxy_hide_header X-Powered-By;
            proxy_pass	 http://127.0.0.1:2368;
            }
       
    }