February 22, 2017
给xlbd.me办了新身份证
每次博客迁移或者升级我都会写一篇日志,来记录博客的历程。这次也不例外。
最近逛v2ex发现Linode在情人节推出了5$/mo
的套餐,2015年10月份以来一直用的Linode的10$/mo
套餐,因为机房在美国速度感觉越来越慢。对比下新的五刀VPS只是内存降低到了1个G。对于我这小流量的博客来说已经够用了。看来我的VPS得换个IP了。正好借此机会升级下Ghost。每个月还可以省下一杯Coffee☕️,2333。
# 备份博客信息
- 博客配置文件,打包
/home/ghost
目录 - CentOS配置文件
.bash_profile
和.vimrc
- nginx 虚拟主机配置文件
- 导出博客数据为
.json
文件
# 选择新的Linode
这次在离国内较近的新加坡服务器和日本服务器之间做了选择。经过测试,日本服务器速度更快些。所以五刀VPS选择了日本服务器。
# Add a Linode
选择Linode 1024 $5/month
# Deploy an Image
我比较熟悉CentOS系统,所以我的博客就是跑在CentOS 7
上的。
# Boot and Login VPS with iTerm2
使用SSH默认端口22登录,每次重新发布镜像我都会改掉SSH默认端口,为了Linode安全考虑,建议VPS新装的系统改掉SSH端口。
$> ssh root@139.162.78.70
1
2
2
# 搭建Ghost环境
# 安装lnmp
因为Ghost用到了nginx
和mysql
,所以我选择了lnmp来搭建环境,非常实用的脚本。
$> install.sh lnmp
1
2
2
# 安装Ghost
$> npm install --production
1
2
2
# 安装pm2
$> npm install pm2 -g
1
2
2
# 迁移配置文件
主要迁移的配置文件是nginx
的虚拟主机配置文件
$> vi /usr/local/nginx/conf/vhost/ghost.conf
1
2
2
server {
listen 80;
server_name www.xlbd.me xlbd.me;
if ( $host = 'www.xlbd.me' )
{
rewrite ^/(.*)$ http://xlbd.me/$1 permanent;
}
location / {
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header Host $http_host;
proxy_pass http://127.0.0.1:2368;
}
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
2
3
4
5
6
7
8
9
10
11
12
13
14
15
# 创建数据库
使用phpMyAdmin
网页工具创建数据库
ghost_dev
- 开发环境ghost_pro
- 生产环境
分别配置在/home/ghost/config.js
中
database: {
client: 'mysql',
connection: {
host : '127.0.0.1',
user : 'user',
password : 'password',
database : 'ghost_dev',
charset : 'utf8'
}
}
1
2
3
4
5
6
7
8
9
10
11
2
3
4
5
6
7
8
9
10
11
导入.json
博客数据备份到开发环境,测试ghost是否正常。一切正常之后使用生产环境配置,切换生产数据库。
# pm2守护ghost后台运行
$> NODE_ENV=production pm2 start index.js --name "ghost"
1
2
2
# 切换IP
修改在Godaddy 中域名配置中的A
记录为新IP。
# 版本升级
node
版本为6.9.5
lnmp
版本为v1.3
ghost
版本为0.11.4
pm2
版本为2.4.0