微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

如何在CentOS7上部署Ghost博客系统

目录

CentOS版本 CentOS-7-x86_64-DVD-1810
Ghost版本 2.23.4


本文以下所有操作和命令均是根据官网setup说明进行,官网仅针对Ubuntu有安装说明,没有在CentOS里的安装说明,网上能Google或Baidu到的所有文章,均是比较老的Ghost版本,很多命令已经有所变化了

准备工作

  • 对系统进行更新

    yum update

新建用户

安装Nginx服务

  • 因为yum安装里面没有Nginx,因此我们需要通过epel来安装

    yum -y install epel-release
    yum -y install Nginx

将端口添加到防火墙里或者关闭防火墙

systemctl stop firewalld

安装MysqL5.7

  • 更新安装MysqL的源

    sudo rpm -Uvh https://dev.MysqL.com/get/MysqL80-community-release-el7-3.noarch.rpm
    //根据选择要安装的版本来确定下列代码disable或enable
    sudo yum-config-manager --disable MysqL80-community
    sudo yum-config-manager --enable MysqL57-community
    yum -y install MysqL-community-server
  • 启动MysqL服务并查看安装时的root密码

    systemctl start MysqLd.service
    sudo grep 'temporary password' /var/log/MysqLd.log
  • 修改MysqLroot密码

    MysqL -uroot -p
    ALTER USER 'root'@'localhost' IDENTIFIED BY 'yourpassword';

    安装Nodejs

    curl -sL https://rpm.nodesource.com/setup_10.x | sudo bash -
    sudo yum -y install nodejs
    node --version    //查看是否安装成功,如果显示Nodejs版本号则成功

安装官方的Ghost工具ghost-cli

sudo npm install ghost-cli@latest -g

网站目录准备,此目录必须为空目录

sudo mkdir -p /home/wwwroot/ghost
sudo chown <user>:<user> /home/wwwroot/ghost
sudo chmod 775 /home/wwwroot/ghost

安装Ghost

cd /home/wwwroot/ghost
ghost install

如果安装失败或者连接断开可以用ghost setup重试

启动ghost

在安装的过程中,ghost-cli会自动配置MysqLNginx,但不知为何无论我怎么试,都会提示找不到Nginx,但后面可以自己配置Nginx

//官方工具是针对Ubuntu的,所以最后的启动命令会报错,使用下面的命令即可
sudo systemctl start ghost_localhost
//配置了Nginx后可以需要重新启动
sudo systemctl restart Nginx

Nginx的反向代理配置

location / {
       proxy_pass http://127.0.0.1:2368;
       proxy_next_upstream error timeout invalid_header http_500 http_502 http_503 http_504;
       proxy_redirect off;
       proxy_set_header X-Real-IP $remote_addr;
       proxy_set_header Host $http_host;
       proxy_set_header X-Nginx-Proxy true;
       proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
       proxy_set_header X-Forwarded-Proto $scheme;          
      }

需要指出的是 CentOS 7 的 SELinux,使用反向代理需要打开网络访问权限。

sudo setsebool httpd_can_network_connect 1 

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。

相关推荐