搭建Ghost博客詳細教程之Ghost安裝與部署
網上大多數的教程都是安裝Ghost0.7.4的,相對來說比較老了,安裝起來也比較複雜了,Ghost1.0之後Ghost自帶了cli安裝工具,相較於以前方便很多。
前期準備
yum update #更新yum源
yum groupinstall "Development Tools" #安裝開發工具包
yum install wget #安裝wget下載工具
安裝Node.js 6.x LTS
官方建議6.x,我裝的時候沒注意,直接最新的8.x了,不過感覺問題也不是很大,最好還是安裝官方的來吧
curl -sL https://rpm.nodesource.com/setup_6.x bash -
yum install nodejs
驗證是否安裝配置成功:node -v
安裝Mysql
CentOS7默認資料庫是mariadb ,但是CentOS7的yum源中默認好像是沒有mysql的。所以得自己下載源安裝了。
安裝完之後,密碼為隨機密碼,所以需要重置密碼,輸入下面指令查看隨機密碼
grep "password" /var/log/mysqld.log
然後輸入下面指令進入MySql
mysql -u root -p 密碼
接下來重置密碼(為了安全密碼,必須包含 數字字母符號)
alter user "root"@"localhost" identified by "你的密碼";
為了更好的體驗和安全,還可以進行一些常規設置。
chkconfig mysqld on # 設置開機啟動Mysql
anonymous users? [Y/n] # 刪除匿名用戶
Disallow root login remotely? [Y/n] # 禁止root用戶遠程登錄
Remove test database and access to it? [Y/n] #刪除默認的 test 資料庫
Reload privilege tables now? [Y/n] # 刷新授權表使修改生效
為了避免資料庫存放的中文是亂碼,我們還需要設置Mysql的編碼:
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:
service mysqld restart
最後我們需要新建一個資料庫,用來存放博客的數據:
mysql -u root -p # 輸入設置好的密碼
create database ghost; # 創建ghost資料庫
grant all privileges on ghost.* to "ghost"@"%" identified by "123456"; # 新建一個用戶ghost,密碼為123456
flush privileges # 重新讀取許可權表中的數據到內存,不用重啟mysql就可以讓許可權生效
安裝Nginx
vi /etc/yum.repos.d/nginx.repo
寫入以下內容:
[nginx]
name=nginx repo
baseurl=http://nginx.org/packages/centos/$releasever/$basearch/
gpgcheck=0
enabled=1
保存退出。
(按i編輯,按Esc結束編輯,:x 保存修改並退出,:q! 強制退出,放棄修改)
繼續執行以下指令:
yum install nginx -y # 安裝Nginx
service nginx start # 動Nginx
chkconfig nginx on # 設置開機啟動Nginx
這樣Nginx就安裝成功了,在瀏覽器中輸入你的VPS的IP就可以看到提示:「Welcome to Nginx!」
配置Nginx
安裝好了nginx後,我們需要設置一個代理伺服器讓我們的博客可以使用域名訪問。 在/etc/nginx/conf.d目錄下創建一個配置文件ghost.conf:
vi /etc/nginx/conf.d/ghost.conf
寫入以下內容:
server {
listen 80;
server_name example.com; #將 example.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;
}
}
保存退出,重啟nginx:
service nginx restart
安裝Ghost-CLI
npm i -g ghost-cli
添加 ghost 運行用戶和創建安裝目錄
假設你的博客要放在/var/www/ghost目錄,那麼我們就創建一個並賦予許可權
adduser ghost
mkdir /var/www/ghost
chown ghost /var/www/ghost
安裝 Ghost
默認以SQLite3為資料庫安裝模式,我們安裝Mysql模式
cd /var/www/ghost
ghost install local --db=mysql
修改相應配置:
啟動 Ghost
ghost start #啟動
ghost restart #重啟
ghost stop #停止
這裡會讓你填寫mysql的地址、用戶名、密碼、資料庫名稱等,填寫你之前設置的就可以了
開機自動啟動Ghost
可以直接在==rc.local==中設置
vi /etc/rc.d/rc.local #打開rc.local
寫入以下內容:
cd /var/www/ghost #你ghost安放的路徑
ghost start #啟動
保存退出後,可以試下重啟下伺服器。(之前的Mysql,Nginx都已經設置開機自啟動)
這樣如果不出意外的話,你的博客應該順利起來了。


TAG:Bug生活2048 |