1. 准备
- Ubuntu 16.04
- MySQL
- NGINX (若需使用SSL, 最低版本至少1.9.5)
- Systemd
- 通过 NodeSource 安装 Node v6
- 至少1GB内存(若不足1GB内存, 可以使用swap空间)
- 如果您的系统内存少于1GB,则可能会出现错误。
- 为了克服这个问题,配置更大量的交换内存:
#使用swap空间
dd if=/dev/zero of=/var/swap bs=1k count=1024k
mkswap /var/swap
swapon /var/swap
echo '/var/swap swap swap defaults 0 0' >> /etc/fstab
- 创建一个用于运行
ghost
的非root用户
2. 在服务器上安装
- 创建一个新用户
adduser <user>
root@ECS:~# adduser blog
Adding user `blog' ...
Adding new group `blog' (1000) ...
Adding new user `blog' (1000) with group `blog' ...
Creating home directory `/home/blog' ...
Copying files from `/etc/skel' ...
Enter new UNIX password:
Retype new UNIX password:
passwd: password updated successfully
Changing the user information for blog
Enter the new value, or press ENTER for the default
Full Name []: Ghost Blog
Room Number [Ghost]:
Work Phone []:
Home Phone []:
Other []:
Is the information correct? [Y/n] y
- 赋予新用户超级用户权限
usermod -aG sudo <user>
root@ECS:~# usermod -aG sudo blog
- 用新用户登录
su <user>
root@ECS:~# su blog
password:
- 更新软件包列表
sudo apt-get update
blog@ECS:~# sudo apt-get update
...
Fetched 27.3 MB in 6s(3,909kB/s)
Reading package lists... Done
- 升级已安装的包
sudo apt-get upgrade -y
blog@ECS:~# sudo apt-get upgrade -y
...
...
17 added, 42 removed; done.
Running hooks in /etc/ca-certificates/update.d...
done.
安装 Nginx
sudo apt-get install nginx
确保防火墙允许HTTP和HTTPS连接
sudo ufw allow 'Nginx Full'
blog@ECS:~# sudo ufw allow 'Nginx Full'
Rules updated
Rules updated (v6)
- 安装MySQL
sudo apt-get install mysql-server
- 在MySQL安装过程中,系统会提示您创建一个root密码。请确定密码不为空!
- 将root密码留空将会导致Ghost-CLI无法连接到具有错误ERNOTSUPPORTEDAUTHMODE的数据库。
blog@ECS:~# sudo apt-get install mysql-server
...
...
- 将下载链接添加至仓库 Node.js
curl -sL https://deb.nodesource.com/setup_6.x | sudo -E bash
blog@ECS:~# curl -sL https://deb.nodesource.com/setup_6.x | sudo -E bash
## Installing the NodeSource Node.js v6.x LTS Boron repo...
## Populating apt-get cache...
...
## Run `apt-get install nodejs` (as root) to install Node.js v6.x LTS Boron and npm
- 安装 Node.js
sudo apt-get install -y nodejs
blog@ECS:~# sudo apt-get install -y nodejs
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following NEW packages will be installed: nodejs
0 upgraded, 1 newly installed, 0 to remove and 9 not upgraded.
Need to get 9,599 kB of archives.
After this operation, 44.0 MB of additional disk space will be used.
Get:1 https://deb.nodesource.com/node_6.x xenial/main i386 nodejs i386 6.14.1-1nodesource1 [9,599 kB]
Fetched 9,599 kB in 2s (3,226 kB/s)
Selecting previously unselected package nodejs.
(Reading database ... 101046 files and directories currently installed.)
Preparing to unpack .../nodejs_6.14.1-1nodesource1_i386.deb ...
Unpacking nodejs (6.14.1-1nodesource1) ...
Processing triggers for man-db (2.7.5-1) ...
Setting up nodejs (6.14.1-1nodesource1) ...
- 安装 Ghost-CLI
sudo npm i -g ghost-cli
blog@ECS:~# sudo npm i -g ghost-cli
...
/usr/bin/ghost -> /usr/lib/node_modules/ghost-cli/bin/ghost
/usr/lib
- 新建一个文件夹
sudo mkdir -p /var/www/ghost
- 你的用户必须拥有这个目录
sudo chown [user]:[user] /var/www/ghost
- 安装文件夹必须具有正确的权限
sudo chmod 775 /var/www/ghost
- 导航到新文件夹
cd /var/www/ghost
blog@ECS:~# sudo mkdir -p /var/www/ghost
blog@ECS:~# sudo chown blog:blog /var/www/ghost/
blog@ECS:~# sudo chmod 775 /var/www/ghost/
blog@ECS:~# cd /var/www/ghost/
blog@ECS: /var/www/ghost$
- 安装Ghost(使用Ghost-CLI)
ghost install
3. 配置
- 快速配置
blog@ECS:/var/www/ghost$ ghost install
✔ 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 v1.22.2
✔ Finishing install process
? Enter your blog URL: http://byxFei.com:2368 #输入 http://域名:端口
? Enter your MySQL hostname: localhost #你的数据库地址 默认本地
? Enter your MySQL username: root #你的数据库用户
? Enter your MySQL password: [hidden] #数据库密码
? Enter your Ghost database name: ghost_prod #数据库名称
✔ Configuring Ghost
✔ Setting up instance
Running sudo command: chown -R ghost:ghost /var/www/ghost/content
✔ Setting up "ghost" system user
? Do you wish to set up "ghost" mysql user? Yes #是否同意设置'ghost'为新的数据库用户
✔ Setting up "ghost" mysql user
? Do you wish to set up Nginx? Yes #是否同意设置'Nginx'
ℹ Setting up Nginx
ℹ Setting up SSL
? Do you wish to set up Systemd? Yes
✔ Creating systemd service file at /var/www/ghost/system/files/ghost_byxfei-com.service
Running sudo command: ln -sf /var/www/ghost/system/files/ghost_byxfei-com.service /lib/systemd/system/ghost_byxfei-com.service
Running sudo command: systemctl daemon-reload
✔ Setting up Systemd
Running sudo command: /var/www/ghost/current/node_modules/.bin/knex-migrator-migrate --init --mgpath /var/www/ghost/current
✔ Running database migrations
? Do you want to start Ghost? Yes
Running sudo command: systemctl is-active ghost_byxfei-com
✔ Ensuring user is not logged in as ghost user
✔ Checking if logged in user is directory owner
✔ Checking current folder permissions
Running sudo command: systemctl is-active ghost_byxfei-com
✔ Validating config
✔ Checking folder permissions
✔ Checking file permissions
✔ Checking content folder ownership
✔ Checking memory availability
Running sudo command: systemctl start ghost_byxfei-com
✔ Starting Ghost
Running sudo command: systemctl is-enabled ghost_byxfei-com
Running sudo command: systemctl enable ghost_byxfei-com --quiet
✔ Starting Ghost
You can access your blog at http://byxfei.com/
Ghost uses direct mail by default
To set up an alternative email method read our docs at https://docs.ghost.org/docs/mail-config
- 启动测试
打开浏览器访问 之前配置的域名, http://byxfei.com/