in 工具 ~ read.
ghost2 安装使用

ghost2 安装使用

环境

  • Linux ghost 4.18.9-1.el7.elrepo.x86_64 #1 SMP Thu Sep 20 09:04:54 EDT 2018 x86_64 x86_64 x86_64 GNU/Linux
  • mysql Ver 14.14 Distrib 5.7.23, for Linux (x86_64) using EditLine wrapper
  • nginx version: nginx/1.14.0
  • node version: v6.9.5

安装

# 登录
ssh root@<ip>
# 添加系统新用户(需要一个root权限的非root用户,不能为ghost)
adduser <username>
# 提高该用户权限
usermod -aG sudo <username>
# 登录到这个用户
su <username>
# 更新
sudo yum update
# 安装Ghost CLI
sudo npm i -g ghost-cli
# 创建ghost安装目录,并赋予权限
sudo mkdir -p /var/www/ghost
sudo chown <username>:<username> /var/www/ghost # 比如我的用户名是test,那就用test:test
sudo chmod 775 /var/www/ghost # 赋予该目录读写权限
# 将工作环境切换到ghost安装目录
cd /var/www/ghost
# 安装ghost
ghost install # 安装会默认使用mysql数据库,另外可以选择使用sqlite,生产环境当然用mysql了

输入

ghost install --no-stack

输出

yuki@ghost:/var/www/ghost$ ghost install --no-stack
✔ Checking system Node.js version
✔ Checking logged in user
✔ Checking current folder permissions
✔ Checking operating system compatibility
✔ Checking for a MySQL installation
✔ Checking memory availability
✔ Checking for latest Ghost version
✔ Setting up install directory
✔ Downloading and installing Ghost v2.1.0
✔ Finishing install process
? Enter your blog URL: (http://localhost:2368) https://www.ccyuki.com

后面还会有使用Nginx,创建mysql用户(ghost),创建mysql数据库,等一系列的操作,如果没有特殊的需求,直接输入Y保持默认即可。

最后的Systemd完成后,不要直接启动,输入'n'退出即可,因为是centos系统,无法用它的命令启动

启停

sudo systemctl status ghost_www-ccyuki-com
sudo systemctl stop ghost_www-ccyuki-com
sudo systemctl start ghost_www-ccyuki-com

卸载

ghost uninstall

添加Disqus评论框

  1. 注册Disqus

  2. 在Disqus中添加站点

  3. 在上一步中,会产生一段代码,保留下来,继续下一步,直至添加站点操作完成。

  4. 进入ghost主题中修改 post.hbs文件,一般以下代码放在footer和article中间

    <section class="post-full-comments">      
          <div id="disqus_thread"></div>
                    <script>
                    /**
                     *  RECOMMENDED CONFIGURATION VARIABLES: EDIT AND UNCOMMENT THE SECTION BELOW TO INSERT DYNAMIC VALUES FROM YOUR PLATFORM OR CMS.
                     *  LEARN WHY DEFINING THESE VARIABLES IS IMPORTANT: https://disqus.com/admin/universalcode/#configuration-variables
                     */
                     /* 如果不使用这段代码, Discus会根据url进行唯一标识
                    var disqus_config = function () {
                        this.page.title = '{{title}}';
                        this.page.url = '{{url absolute="true"}}';  // Replace PAGE_URL with your page's canonical URL variable
                        this.page.identifier = 'ghost-{{comment_id}}'; // Replace PAGE_IDENTIFIER with your page's unique identifier variable
                    };
                    */
                    (function() { // DON'T EDIT BELOW THIS LINE
                         var d = document, s = d.createElement('script');
                         s.src = 'https://yuki-bobo.disqus.com/embed.js';
                         s.setAttribute('data-timestamp', +new Date());
                         (d.head || d.body).appendChild(s);
                     })();
                    </script>
                    <noscript>Please enable JavaScript to view the <a href="https://disqus.com/?ref_noscript">comments powered by Disqus.</a></noscript>
    </section>
    

Nginx配置

vim /etc/nginx/nginx.conf

user  nginx;
worker_processes  1;

error_log  /var/log/nginx/error.log warn;
pid        /var/run/nginx.pid;


events {
    worker_connections  1024;
}


http {
    include       /etc/nginx/mime.types;
    default_type  application/octet-stream;

    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for"';

    access_log  /var/log/nginx/access.log  main;

    sendfile        on;
    #tcp_nopush     on;

    keepalive_timeout  65;
    client_max_body_size 20m;  # 这行是设置上传文件的大小限制为20M,否则向博客上传文件时很容易受到限制

    #gzip  on;

    include /etc/nginx/conf.d/*.conf;
}

Ghost配置

vim ghost/config.production.json

{
  "url": "http://www.ccyuki.com",
  "server": {
    "port": 2368,
    "host": "127.0.0.1"
  },
  "database": {
    "client": "mysql",
    "connection": {
      "host": "*****",
      "user": "*****",
      "password": "******",
      "database": "*****"
    }
  },
  "mail": {
    "transport": "SMTP",
    "from":"ccyuki@qq.com",
    "options": {
        "service": "QQ",
        "auth": {
            "user": "1073071892@qq.com",
            "pass": "****"
        }
    }
  },
  "logging": {
    "transports": [
      "file",
      "stdout"
    ]
  },
  "process": "systemd",
  "paths": {
    "contentPath": "/var/www/ghost/content"
  }
}

主题

我选用的主题是 uno-zen