CentOS7上部署Ghost部落格系統
阿新 • • 發佈:2020-12-07
準備工作
-
對系統進行更新
yum update
## 新建使用者
* 由於Ghost不能在root下進行安裝,因此需要新建一個使用者
```shell
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