Centos7.3搭建Ghost博客

一、nvm安裝

1、nvm
沒有wget先安裝

image.png

根據(jù)=>提示,.bashrc文件已經(jīng)有以下三行命令,直接運行這三行命令

image.png

安裝成功


image.png

二、安裝nodejs

查看所有版本


image.png

查看長久支持的版本

image.png

根據(jù)官方介紹安裝合適版本,這里選擇4.2.0版本


$ nvm install 4.2.0

三、安裝nginx

//安裝
$ yum install nginx -y
//啟動
$ systemctl start nginx
//設(shè)置開機啟動
$ systemctl enable nginx

防火墻配置

查看正在監(jiān)聽的端口,80端口已開啟

image.png

查看防火墻默認Zone

image.png
//開放80端口
$ firewall-cmd --permanent --zone=public --add-port=80/tcp
//查看所有開放的端口,80端口已開放
$ firewall-cmd --permanent --list-port

瀏覽器訪問linux主機ip

image.png

配置Nginx

$ cd /etc/nginx/conf.d/
//該目錄下創(chuàng)建ghost.conf
$ vim ghost.conf
//粘貼以下代碼
server {
        listen 80;
        server_name 192.168.1.21; # 服務(wù)器Ip地址
        location / {
                proxy_set_header  X-Real-IP $remote_addr;
                proxy_set_header  Host      $http_host;
                proxy_pass        http://127.0.0.1:2368;
        }
}
//保存
$ :wq
//重啟Nginx
$ systemctl restart nginx

四、安裝MySQL

ghost默認使用sqlite數(shù)據(jù)庫,也可使用MySQL數(shù)據(jù)庫

//CentOS7 yum中沒有MySQL,先下載repo源
$ wget http://repo.mysql.com/mysql-community-release-el7-5.noarch.rpm
//安裝rpm包
$ rpm -ivh mysql-community-release-el7-5.noarch.rpm
//安裝MySQL
$ yum install mysql-server

配置MySQL

//啟動MySQL
$ systemctl start mysqld
//設(shè)置開機啟動
$ systemctl enable mysqld
//使用命令mysql_secure_installation對mysql進行安全配置
$ mysql_secure_installation

Set root password? [Y/n] #設(shè)置root密碼  
anonymous users? [Y/n] #刪除匿名用戶  
Disallow root login remotely? [Y/n] #禁止root用戶遠程登錄  
Remove test database and access to it? [Y/n] #刪除默認的 test 數(shù)據(jù)庫  
Reload privilege tables now? [Y/n] #刷新授權(quán)表使修改生效  

避免數(shù)據(jù)庫存放的中文亂碼,需要設(shè)置編碼,執(zhí)行命令vim /etc/my.cnf
粘貼以下內(nèi)容

[client]
default-character-set=utf8  
[mysql]
default-character-set=utf8  
[mysqld]
character-set-server=utf8  
collation-server=utf8_general_ci

重啟MySQL

systemctl restart mysqld

創(chuàng)建ghost數(shù)據(jù)庫并配置

$ mysql -u root -p # 輸入設(shè)置好的密碼 
$ create database ghost; # 創(chuàng)建ghost數(shù)據(jù)庫 
$ grant all privileges on ghost.* to 'ghost'@'%' identified by '123456'; # 新建一個用戶ghost,密碼為123456,這里自己設(shè)置 
$ flush privileges; # 重新讀取權(quán)限表中的數(shù)據(jù)到內(nèi)存,不用重啟mysql就可以讓權(quán)限生效 

五、下載Ghost

//var目錄下創(chuàng)建www
$ cd /var/www
//下載
$ wegt http://dl.ghostchina.com/Ghost-0.7.4-zh-full.zip
//解壓
$ unzip Ghost-0.7.4-zh-full.zip -d ghost
//進入ghost
$ cd ghost
//修改配置
$ cp config.example.js config.js 
$ vim config.js
image.png

運行

$ npm start --production

如果出現(xiàn)504錯誤頁面,檢查selinux是否開啟

$ sestatus
//禁用selinux
$ vim /etc/selinux/config
//修改為
SELINUX=disabled
//重啟
init 6

六、運行

安裝pm2

$ cd /var/www/ghost
$ npm install pm2 -g
$ NODE_ENV=production pm2 start index.js --name "ghost"  #生產(chǎn)模式啟動
$ pm2 startup centos #開機啟動
$ pm2 save

參考學(xué)習(xí):
Ghost 博客搭建日記

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容