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

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


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

准备工作

  • 对系统进行更新

    yum update

新建用户

  • 由于Ghost不能在root下进行安装,因此需要新建一个用户

    adduser username      //添加新用户或者用已有的用户,用户名为username
    passwd username     //修改新建用户的密码
  • 新添加的用户需要有sudo的权限

    vi /etc/sudoers           //编辑权限文件

    找到下面这行并在后面添加上前面设置好的新用户名

    root    ALL=(ALL)       ALL
    username ALL=(ALL)       ALL

安装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
  • 修改MySql的root密码

    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会自动配置MySql和Nginx,但不知为何无论我怎么试,都会提示找不到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 

猜你喜欢

转载自www.cnblogs.com/5kyRang3r/p/11025830.html