前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >玩转 PAI:Ghost 博客搭建

玩转 PAI:Ghost 博客搭建

原创
作者头像
谛听
修改2019-12-29 20:01:08
8240
修改2019-12-29 20:01:08
举报
文章被收录于专栏:随意记录随意记录

本文基于 PAI 搭建博客。

PAI 购买页:/solution/pai

PAI 使用示例:https://github.com/TencentCloudBase/pai-instance-document

购买完后需等待几分钟 PAI 的安装。通过 https://域名:5523 访问成功后,说明 PAI 安装结束。

远程登陆到 PAI

代码语言:txt
复制
ssh root@域名或IP

配置 node.js

PAI 中已经安装了 node.js,可以用如下命令进行查看:

代码语言:txt
复制
node -v

如果显示“-bash: node: 未找到命令”,执行:

代码语言:txt
复制
echo "export PATH=/usr/local/node/bin:$PATH" >> ~/.bashrc
source ~/.bashrc

安装 mysql

代码语言:txt
复制
yum install mariadb-server mariadb -y

systemctl start mariadb

配置:

代码语言:txt
复制
mysql_secure_installation

回车后,以下都选 y

代码语言:txt
复制
Set root password? [Y/n]   # 设置root密码,需输入密码

anonymous users? [Y/n]    # 删除匿名用户 

Disallow root login remotely? [Y/n]   # 禁止root用户远程登录 

Remove test database and access to it? [Y/n]   # 删除默认的 test 数据库 

Reload privilege tables now? [Y/n]   # 刷新授权表使修改生效

设置 mysql 编码:

代码语言:txt
复制
vim /etc/my.cnf

添加内容:

代码语言:txt
复制
[client]

default-character-set=utf8 

[mysql]

default-character-set=utf8

[mysqld]

character-set-server=utf8 

collation-server=utf8_general_ci

重启 mysql:

代码语言:txt
复制
systemctl restart mariadb

新建一个数据库:

代码语言:txt
复制
mysql -u root -p   # 输入设置好的密码 

create database ghost;    # 创建ghost数据库 

create user ghost@localhost identified by '123456';     # 新建一个用户ghost,密码为123456,这里自己设置 

grant all privileges on  *.* to 'ghost'@'localhost';

flush privileges; # 重新读取权限表中的数据到内存,不用重启mysql就可以让权限生效 

exit

安装 ghost

代码语言:txt
复制
mkdir /var/www

cd /var/www

wget https://ghost.org/zip/ghost-latest.zip    # 大概十几分钟

unzip -d /var/www/ghost /var/www/ghost-latest.zip

cd ghost

npm install --production --unsafe-perm=true --allow-root   # 大概十几分钟

将默认使用的 dev 开发模式修改为 prod 生产模式:

代码语言:txt
复制
sed -i "s#development#production#g" core/index.js
sed -i "s#development#production#g" core/server/config/index.js

修改数据库配置:

代码语言:txt
复制
vim core/server/config/env/config.production.json

修改:

代码语言:txt
复制
{
    "database": {
        "client": "mysql",
        "connection": {
            "host"     : "127.0.0.1",
            "user"     : "ghost",
            "password" : "123456",
            "database" : "ghost"
        }
    },
    "paths": {
        "contentPath": "content/"
    },
    "logging": {
        "level": "info",
        "rotation": {
            "enabled": true
        },
        "transports": ["file", "stdout"]
    }
}

修改 url:

代码语言:txt
复制
vim core/server/config/defaults.json
代码语言:txt
复制
{
    "url": "http://你的域名",
    "server": {
        "host": "127.0.0.1",
        "port": 3000    # PAI 中的 nginx 默认代理 3000 端口
    },
    "updateCheck": {
        "url": "https://updates.ghost.org",

启动 ghost 博客:

也可以将启动命令写到 .pai.yml 文件中,这样就可以通过 PAI 界面管理应用了,详见 https://github.com/TencentCloudBase/pai-instance-document

代码语言:txt
复制
npm run start --production  

可能会报错:

ERROR Please run knex-migrator init

解决:

代码语言:txt
复制
npm install -g knex-migrator --unsafe-perm=true --allow-root
knex-migrator init
npm run start --production 

访问

在浏览器中输入域名可访问:

图片.png
图片.png

在浏览器中输入“域名/ghost” 可进入后台管理页面:

图片.png
图片.png

参考

https://ghost.org/docs/install/ubuntu/

https://www.jianshu.com/p/77953f7f076b

原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。

如有侵权,请联系 cloudcommunity@tencent.com 删除。

原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。

如有侵权,请联系 cloudcommunity@tencent.com 删除。

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 远程登陆到 PAI
  • 配置 node.js
  • 安装 mysql
  • 安装 ghost
  • 访问
  • 参考
相关产品与服务
云数据库 SQL Server
腾讯云数据库 SQL Server (TencentDB for SQL Server)是业界最常用的商用数据库之一,对基于 Windows 架构的应用程序具有完美的支持。TencentDB for SQL Server 拥有微软正版授权,可持续为用户提供最新的功能,避免未授权使用软件的风险。具有即开即用、稳定可靠、安全运行、弹性扩缩等特点。
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档
http://www.vxiaotou.com