ghost介绍
ghost是一款用 Node.js 编写,功能强大的无头 CMS。它的强大之处在于提供了丰富、免费、可自定义的主题,用户可以自由搭配轻松建站。专业的会员订阅和数据可视化功能,让内容创作者可以围绕内容,尝试发展商业化业务。除此之外,它还拥有先进的所见即所得编辑器。
相比WordPress的大而全,Ghost要清新的多,后台简洁,并提供了完整的Markdown编辑器进行博客创作。
Ghost的优点:
- 可使用轻量的SQLite作为数据库,对于小型博客,维护起来更方便(同时也支持MySql)
- 完全的Markdown编辑器支持
github地址:
https://github.com/TryGhost/Ghost
本文使用kubernetes的方式来进行部署ghost服务
ghost部署
deployment.yaml文件
容器内Ghost的配置目录是/var/lib/ghost/content,映射到本地宿主机/data/ghost目录下,便于备份。
apiVersion: apps/v1
kind: Deployment
metadata:
name: ghost
spec:
selector:
matchLabels:
app: ghost
template:
metadata:
labels:
app: ghost
spec:
containers:
- name: ghost
image: ghost:latest
env:
- name: url
value: "http://xxx.xxx.xxx"
resources:
limits:
cpu: 1000m
memory: 1Gi
ports:
- containerPort: 2368
volumeMounts:
- name: ghost-data
mountPath: /var/lib/ghost/content
volumes:
- name: ghost-data
hostPath:
path: /data/ghost
type: Directory
nodeSelector:
app: ghost
service.yaml
apiVersion: v1
kind: Service
metadata:
name: ghost
spec:
selector:
app: ghost
ports:
- port: 80
targetPort: 2368
部署完成后,可以通过ghost的serviceIP地址在浏览器访问,可以查看到ghost的默认首页。url后添加/ghost,进入后台管理页面,首次进入需要创建博客账户。
注意:
设置博客的url地址:
在ghost容器的配置文件里,默认配置的url地址是localhost:2368,部署完服务以后,会导致有些链接不发使用,页面提示localhost无法连接。
需要到Ghost的配置目录/var/lib/ghost,修改config.development.json文件,修改url为正确的地址:
{
"url": "http://xxx.xxx.xxx:2368", //修改这个地址
"server": {
"port": 2368,
"host": "0.0.0.0"
},
"database": {
"client": "sqlite3",
"connection": {
"filename": "/var/lib/ghost/content/data/ghost.db"
}
},
"mail": {
"transport": "Direct"
},
"logging": {
"transports": [
"file",
"stdout"
]
},
"process": "systemd",
"paths": {
"contentPath": "/var/lib/ghost/content"
}
}
但是由于是直接在pod里修改的,后面重启会导致又变回原样。我这边直接在部署文件deployment.yaml中以环境变量的方式来修改。添加完环境变量以后,执行kubectl apply -f deployment.yaml就可以了
spec:
containers:
- name: ghost
image: ghost:latest
env:
- name: url
value: "http://xxx.xxx.xxx"