开发环境腾讯云主机配置:操作系统 ubuntu server 16.04.1 lts 64位
cpu 1 核
内存 2 gb
公网带宽 1 mbps
官方推荐的安装条件ubuntu 16.04或ubuntu 18.04
内存至少为1gb的服务器
注册域名
在开始之前,首先去解析域名,指向服务器的ip地址并确保它正确解析。必须提前完成此操作,以便在安装过程中正确配置ssl。
开始操作1. 创建一个新用户打开终端并以root用户身份登录服务器,创建一个非root用户,官方不推荐在root下安装ghost(注意这里很多坑,搞不定就重装系统吧,我已经重装很多次了)
创建一个新用户(非root),命令如下:替换为你自己的用户名称即可如sudo adduser blog,期间会让你输入两次新用户的密码
sudo adduser 将新创建的用户添加到组。
usermod -ag sudo 输入完一些信息就yes下一步。
注意事项:如果使用用户名“ghost”会导致与ghost-cli冲突,不允许使用“ghost”这个用户名。
2. 更新包确保包列表和已安装的包是最新的。
sudo apt-get updatesudo apt-get upgrade3. 安装node.js执行以下命令,安装node.js
sudo curl -sl https://deb.nodesource.com/setup_10.x | sudo -e bash -sudo apt-get install -y nodejs注意了,ghost支持的版本如下:
推荐使用10.x
如果想选择其他版本的话,可以在安装的时候修改sudo curl -sl https://deb.nodesource.com/setup_10.x | sudo -e bash -中的setup_10.x,改为你需要的版本即可。
安装完成后,执行以下命令查看node.js版本和npm版本。
node -vnpm -v回显信息:
ubuntu@vm-0-10-ubuntu:~$ node -vv10.15.1ubuntu@vm-0-10-ubuntu:~$ npm -v6.4.14. 安装nginxghost使用nginx服务器,ssl配置需要nginx 1.9.5或更高版本。
执行命令:
sudo apt-get updatesudo apt-get install nginxufw(uncomplicated firewall)是一个 iptables 的接口,可以简化配置防火墙的过程。ubuntu 默认安装了 ufw,执行以下命令查看防火墙的状态。
sudo ufw status如果你没有也不想开启防火墙,则可以直接跳过此步骤,如果你想要开启防火墙可以通过以下命令实现。
sudo ufw enable之后再次检查防火墙状态验证是否成功开启防火墙。
在测试nginx之前,需要重新配置我们的防火墙软件以允许访问nginx。执行以下命令,将nginx自动 注册在 ufw。
sudo ufw app list如果ufw已激活,则防火墙允许http和https连接。打开防火墙:
sudo ufw allow 'nginx full'输出信息:
ubuntu@vm-0-10-ubuntu:~$ sudo ufw app listavailable applications: nginx full nginx http nginx https openssh配置nginx
# 新建配置文件sudo vim /etc/nginx/sites-available/ghost.conf把以下配置内容粘贴进你的配置文件中,修改server_name 的内容
server { listen 80; server_name 119.3.xx.xxx.com; #这里写你的域名或者ip地址 location / { proxy_set_header x-real-ip $remote_addr; proxy_set_header host $http_host; proxy_pass http://127.0.0.1:2368; }}把配置文件软链接到sites-enabled中:
sudo ln -s /etc/nginx/sites-available/ghost.conf /etc/nginx/sites-enabled/ghost.conf重启nginx
sudo service nginx restart验证nginx是否正常工作
在浏览器中通过域名或者 ip 地址进行访问nginx,如果nginx正常启动则会打开welcome to nginx的欢迎页面。
使用浏览器访问 http://云服务器ip地址,显示如下页面,说明nginx安装成功。
安装nginx成功
5. 安装mysql安装mysql以用作数据库。
sudo apt-get updatesudo apt-get install mysql-server安装的过程中会让你输入密码,安装输入即可,我是为了方便记录,用户、数据库都输入了一样的密码。
执行这个命令
mysql_secure_installation根据提示,前两项是 n ,后面的y即可
securing the mysql server deployment.enter password for user root: #输入上一步骤中获取的安装mysql时自动设置的root用户密码the existing password for the user account root has expired. please set a new password.estimated strength of the password: 100change the password for root ? ((press y|y for yes, any other key for no) : n #是否更改root用户密码,输入nremove anonymous users? (press y|y for yes, any other key for no) : y #是否删除匿名用户,输入ysuccess.disallow root login remotely? (press y|y for yes, any other key for no) : y #禁止root远程登录,输入ysuccess.remove test database and access to it? (press y|y for yes, any other key for no) : y #是否删除test库和对它的访问权限,输入y - dropping test database...success.reload privilege tables now? (press y|y for yes, any other key for no) : y #是否重新加载授权表,输入ysuccess.all done!测试数据库状态:
systemctl status mysql.service结果如下:(按ctrl+c退出)
ubuntu@vm-0-10-ubuntu:~$ systemctl status mysql.service● mysql.service - mysql community server loaded: loaded (/lib/systemd/system/mysql.service; enabled; vendor preset: en active: active (running) since sun 2019-02-24 13:56:36 cst; 1h 3min ago main pid: 7203 (mysqld) cgroup: /system.slice/mysql.service └─7203 /usr/sbin/mysqldfeb 24 13:56:35 vm-0-10-ubuntu systemd[1]: stopped mysql community server.feb 24 13:56:35 vm-0-10-ubuntu systemd[1]: starting mysql community server...feb 24 13:56:36 vm-0-10-ubuntu systemd[1]: started mysql community server.lines 1-10/10 (end)ubuntu@vm-0-10-ubuntu:~$为了避免数据库存放的中文是乱码,执行以下命令设置mysql的编码:
sudo vi /etc/my.cnf复制粘贴以下内容:
[client]default-character-set=utf8 [mysql]default-character-set=utf8 [mysqld]character-set-server=utf8 collation-server=utf8_general_ci保存退出,执行以下命令重启 mysql 生效:
sudo /usr/sbin/service mysql restart建立ghost依赖的数据库以 root 身份登录mysql然后创建一个名为 ghost 的数据库并验证创建结果,强调!!!进入数据库必须是root(超级用户,比如默认用户 ubuntu )。
首先执行命令:(他会提示你输入密码)
mysql -u root -p;进入数据库界面:
执行创建数据库,名字随意,我使用的是ghost(注意要有分号)
create database ghost;创建完显示一下当前数据库:
show databases;结果(当然我这里有好几个数据库,列表中有你的数据库名称就行了)
mysql> show databases;+--------------------+| database |+--------------------+| information_schema || blog || ghost || mysql || performance_schema || sys |+--------------------+6 rows in set (0.00 sec)由于很多教程都是没有让数据库给非root用户(即我们刚开始创建的用户)分配权限,在这里我们要补充这点。
数据库分配权限执行:
grant all privileges on mysql_name.* to 'user_name'@'%' identified by 'xxxxxxxxx';参数说明:
mysql_name:在前面创建数据库时候的名称,我的是ghost
user_nam:在刚开始创建的用户名称,我的是blog
xxxxxxxxx:是访问数据库的密码(口令),要记牢
结果:
mysql> grant all privileges on ghost.* to 'blog'@'%' identified by '************';query ok, 0 rows affected, 1 warning (0.00 sec)退出数据库
mysql> exit最好在这里重启一下数据库
sudo /usr/sbin/service mysql restartghost 安装与配置安装ghost-clighost v1.0.0 及以上版本已加入了ghost-cli,因此可以直接安装配置ghost-cli。
ghost-cli是一个命令行工具,可帮助您快速轻松地安装和配置ghost。可以用npm或安装yarn。
sudo npm i -g ghost-cli安装后,可以运行ghost help以查看可用命令列表。
安装ghost正确设置服务器并ghost-cli安装后,即可安装ghost。
注意:在/root或home/目录中安装ghost会导致设置损坏。始终使用具有正确配置权限的自定义目录。
首先创建一个文件夹,官方推荐在 /var/www/目录下安装ghost
sudo mkdir -p /var/www/ghost配置文件夹权限:
sudo chown [user]:[user] /var/www/ghost其中[user]替换为一开始创建的用户(我的是blog)
sudo chown blog:blog /var/www/ghost配值文件夹权限:
sudo chmod 775 /var/www/ghost切换路径:
cd /var/www/ghost由于官方指定安装ghost不允许在root用户下,因此我们去到一开始创建的用户(非root用户)下安装, 替换为你的用户名称即可,然后输入密码 :
su 结果可以看到ubuntu用户已经切换为blog用户。
ubuntu@vm-0-10-ubuntu:/var/www/ghost$ su blogpassword: blog@vm-0-10-ubuntu:/var/www/ghost$ ls如果你已经做到了这一点,说明已经完成90%了,是时候用一个命令安装ghost了
ghost install结果:
blog@vm-0-10-ubuntu:/var/www/ghost$ ghost install✔ downloading and installing ghost v2.15.0✔ finishing install process? enter your blog url: http://jiejietop.cn #输入博客的路径? enter your mysql hostname: localhost #使用本地数据库? enter your mysql username: blog #用户名字? enter your mysql password: [hidden] #密码(为了方便用户名与数据库最好设置为一样的密码)? enter your ghost database name: ghost #数据库名字✔ configuring ghost✔ setting up instance+ sudo chown -r ghost:ghost /var/www/ghost/content? sudo password [hidden] #输入密码✔ setting up ghost system user ℹ setting up ghost mysql user [skipped]+ sudo ln -sf /etc/nginx/sites-available/jiejietop.cn.conf /etc/nginx/sites-enabled/jiejietop.cn.conf+ sudo nginx -s reload☲ setting up nginx✔ setting up nginx? do you wish to set up ssl? yes #输入 y ? enter your email (for ssl certificate) 1161959934@qq.com #你自己的邮箱,可能是防止忘了密码吧 + sudo /etc/letsencrypt/acme.sh --issue --home /etc/letsencrypt --domain jiejietop.cn --webroot /var/www/ghost/system/nginx-root --reloadcmd nginx -s reload --accountemail 1161959934@qq.com✔ creating ssl config file at /var/www/ghost/system/files/jiejietop.cn-ssl.conf+ sudo ln -sf /var/www/ghost/system/files/jiejietop.cn-ssl.conf /etc/nginx/sites-available/jiejietop.cn-ssl.conf+ sudo ln -sf /etc/nginx/sites-available/jiejietop.cn-ssl.conf /etc/nginx/sites-enabled/jiejietop.cn-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_jiejietop-cn.service+ sudo ln -sf /var/www/ghost/system/files/ghost_jiejietop-cn.service /lib/systemd/system/ghost_jiejietop-cn.service+ sudo systemctl daemon-reload✔ setting up systemd? do you want to start ghost? yes #输入 y + sudo systemctl is-active ghost_jiejietop-cn✔ 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_jiejietop-cn✔ validating config✔ checking folder permissions✔ checking file permissions✔ checking content folder ownership✔ checking memory availability+ sudo systemctl start ghost_jiejietop-cn✔ starting ghost+ sudo systemctl is-enabled ghost_jiejietop-cn+ sudo systemctl enable ghost_jiejietop-cn --quiet✔ enabling ghost instance startup on server bootghost 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: http://jiejietop.cn/ghost/ #表示安装正常,通过这个就能配置你的博客虽然啥都没有,但是搭起来还是很爽的,我是踩了很多坑的,什么数据库分配权限啥的,还有配置ghost文件夹权限什么的,还有root用户,乱七八糟的东西,也是一步步查资料解决的
博客配置界面
搭建ghost参考:如何在ubuntu上安装ghost
手工搭建ghost博客(ubuntu 16.04)
ghost 安裝在 ubuntu 環境底下
ghost博客安装、使用、更新一条龙教程-中文版
解决问题参考:mysql学习笔记(一)ubuntu16.04中mysql安装配置(5.6优化、错误日志、dns解决)
mysql列出所有数据库
【mysql】创建普通用户,分配权限,取消权限
同时还要感谢 谷歌翻译 ,它解决了我很多问题!!
ChatGPT识别恶意域名的回答,我差点破防!
华为发力折叠屏手机,下半年推出三款入门级产品
五张图了解河南调电价:全面落实电网清费政策
开关电源的电感选择和PCB布局布线设计
鸡年礼物!iOS10.2越狱更新了,附上越狱工具下载地址
腾讯云Ubuntu主机搭建Ghost
认识三坐标测量机的结构形式
温-压信号转换电路图
西门子Simatic S7-200 Smart PLC,让智能车库停车,不再难
2020年海上风电将形成1779亿产业集群
智能变电站的作用和结构
环球仪器与奇隆合作在波兰建立了一个Fuzion生产线
影响电子书普及的因素有哪些?
科大讯飞股份有限公司:人工智能领域产业的领军者
昂宝电子推出高兼容性的欧洲高效无频闪单段线性可控硅调光方案
意大利伦巴第地方政府拨款1000万欧元用于补贴太阳能+储能系统 每位申请人最多可获得10万欧元的补贴
信用货币理论详解
索尼推出世界最小监控用CMOS图像传感器IMX415
荣耀V30系列首发 突破性地带来了Matrix Camera相机矩阵
alyx首次提出全球第二代VR显示定义 独家沉浸屏树立VR新标杆