Ubuntu搭建Ghost博客

2019年3月28日 657 次阅读 0 条评论 4.33k 个文字

环境准备

  • Ubuntu 16.04或Ubuntu 18.04
    Nginx
    Node.js 10.x
    Mysql 5.5,5.6或5.7
    Systemd
  • 在开始之前,把域名做好解析,必须提前完成此操作,以便在安装过程中正确配置SSL。

开始

创建一个新用户

adduser 用户名

注意:Ghost官网已经说明了 使用ghost作为用户名会导致与Ghost-CLI冲突 具体未测试。

# 输出
Enter new UNIX password:                        #盲输密码
Retype new UNIX password:                       #盲输密码
passwd: password updated successfully
Changing the user information for ghostt
Enter the new value, or press ENTER for the default
	Full Name []:                            #直接回车
	Room Number []:                          #直接回车
	Work Phone []:                           #直接回车
	Home Phone []:                           #直接回车
	Other []:                                #直接回车
Is the information correct? [Y/n]                #输y
# 将用户添加到超级用户组以解锁管理员权限
usermod -aG sudo 用户名

# 切换用户
su 用户名

更新包列表和已安装的包

sudo apt-get update
sudo apt-get upgrade

安装NGINX

sudo apt-get install nginx

#如果防火墙已开启 ,则允许HTTP和HTTPS连接

sudo ufw allow 'Nginx Full'

安装MySQL

sudo apt-get install mysql-server

#需要密码才能确保MySQL兼容Ghost-CLI

# 创建root密码
ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY '密码';

# 退出
quit

安装Node.js

curl -sL https://deb.nodesource.com/setup_10.x | sudo -E bash -
sudo apt-get install -y nodejs

# 检查是否安装成功
node -v

安装Ghost-CLI

# 安装
sudo npm install ghost-cli@latest -g

# 检查状态
ghost -v

创建目录

# 在这个例子中将其命名为'ghost',你可以随心修改它
sudo mkdir -p /var/www/ghost

# 将当前用户替换为将拥有此目录的用户
sudo chown 用户名:用户名 /var/www/ghost

# 设置权限
sudo chmod 775 /var/www/ghost

# 进入目录
cd /var/www/ghost

运行安装

ghost install

示例:安装过程中

+ sudo chown -R ghostt:ghostt /home/ghostt/.config
✔ 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.19.1
✔ Finishing install process
? Enter your blog URL:                # 输入你的域名
? Enter your MySQL hostname: localhost     # 回车
? Enter your MySQL username: root             # root
? Enter your MySQL password: [hidden]       # 盲输密码
? Enter your Ghost database name: ghost_prod         #回车
✔ Configuring Ghost
✔ Setting up instance
+ sudo useradd --system --user-group ghost
+ sudo chown -R ghost:ghost /var/www/ghost/content
✔ Setting up "ghost" system user
? Do you wish to set up "ghost" mysql user? Yes           # 输y
✔ Setting up "ghost" mysql user
? Do you wish to set up Nginx? Yes                                # 输y
✔ Creating nginx config file at /var/www/ghost/system/files/a.cllay.org.conf
+ sudo ln -sf /var/www/ghost/system/files/a.cllay.org.conf /etc/nginx/sites-available/a.cllay.org.conf
+ sudo ln -sf /etc/nginx/sites-available/a.cllay.org.conf /etc/nginx/sites-enabled/a.cllay.org.conf
+ sudo nginx -s reload
✔ Setting up Nginx
? Do you wish to set up SSL? Yes          # 输y
? Enter your email (For SSL Certificate)                      # 输入你的邮箱
+ sudo mkdir -p /etc/letsencrypt
+ sudo ./acme.sh --install --home /etc/letsencrypt
+ sudo /etc/letsencrypt/acme.sh --issue --home /etc/letsencrypt --domain a.cllay.org --webroot /var/www/ghost/system/nginx-root --reloadcmd "nginx -s reload" --accountemail souloog@gmail.com
+ sudo openssl dhparam -out /etc/nginx/snippets/dhparam.pem 2048
+ sudo mv /tmp/ssl-params.conf /etc/nginx/snippets/ssl-params.conf
✔ Creating ssl config file at /var/www/ghost/system/files/a.cllay.org-ssl.conf
+ sudo ln -sf /var/www/ghost/system/files/a.cllay.org-ssl.conf /etc/nginx/sites-available/a.cllay.org-ssl.conf
+ sudo ln -sf /etc/nginx/sites-available/a.cllay.org-ssl.conf /etc/nginx/sites-enabled/a.cllay.org-ssl.conf
+ sudo nginx -s reload
✔ Setting up SSL
? Do you wish to set up Systemd? Yes             # 输y
✔ Creating systemd service file at /var/www/ghost/system/files/ghost_a-cllay-org.service
+ sudo ln -sf /var/www/ghost/system/files/ghost_a-cllay-org.service /lib/systemd/system/ghost_a-cllay-org.service
+ sudo systemctl daemon-reload
✔ Setting up Systemd
? Do you want to start Ghost? Yes         # 输y
+ sudo systemctl is-active ghost_a-cllay-org
✔ Ensuring user is not logged in as ghost user
✔ Checking if logged in user is directory owner
✔ Checking current folder permissions
+ sudo systemctl is-active ghost_a-cllay-org
✔ Validating config
✔ Checking folder permissions
✔ Checking file permissions
✔ Checking content folder ownership
✔ Checking memory availability
+ sudo systemctl start ghost_a-cllay-org
✔ Starting Ghost
+ sudo systemctl is-enabled ghost_a-cllay-org
+ sudo systemctl enable ghost_a-cllay-org --quiet
✔ Enabling Ghost instance startup on server boot

Ghost uses direct mail by default. To set up an alternative email method read our docs at https://docs.ghost.org/concepts/config/#mail

------------------------------------------------------------------------------

Ghost was installed successfully! To complete setup of your publication, visit: 

    https://a.cllay.org/ghost/

ghostt@git:/var/www/ghost$ 

登录后台

https://你的域名/ghost

点击Create your account

按照填写即可

放个图

未来的维护

使用Ghost-CLI相对容易。运行ghost help以获取可用命令的列表,或浏览完整的Ghost-CLI文档

现在您可以开始自定义您的网站了。查看Ghost的教程

 

头像

这个人很懒 只留下了遗憾