標籤:
安裝MySQL
# 安裝MySql$ apt-get update # 更新群組件$ apt-get install mysql-server mysql-client -y # 快速安裝-y代表預設選擇y省去了斷行符號,這時只需要設定mysql的root密碼# 設定mysql的編碼$ sudo vi /etc/mysql/mysql.cnf # 搜尋到[mysqld] 插入collation-server = utf8_unicode_ci init-connect = 'SET NAMES utf8' character-set-server = utf8$ service mysql restart # 重啟生效$ mysql -u root -p # 輸入上面設定的密碼$ show variables like 'char%'$ show variables like 'collation%' # 查看是否改成utf-8了否則之後資料庫記憶體中文存放的是亂碼# 建立Ghost資料庫$ create database mousycoder # 這裡把mousycoder換成你想換成的資料庫名,建議和網域名稱保持一致,方便以後維護。$ create database mousycoderDev # 這個是Ghost啟動有2種模式 一種開發模式 一種生產模式 這個是開發模式的資料庫,如果不想那麼麻煩,只用建立一個資料庫即可。$ create user 'mousycoder'@'localhost' identified by '123456' # 這裡建立一個使用者mousycoder密碼為123456,當然我的密碼肯定不是123456咯,換成你自己的啦 = =,同樣也建議使用者名稱,資料庫名,服務名,組名,都和網域名稱保持一致,這裡是建立一個只有本地操作的使用者,遠程無法操作,安全性原則。$ grant all privileges on mousycoder.* to 'mousycoder'@'localhost'$ grant all privileges on mousycoderDev.* to 'mousycoder'@'localhost' # 這裡是賦予mousycoder這個本機使用者所有對資料庫mousycoder以及mousycoderDev的許可權,當然這裡你可以根據實際需要賦予許可權。$ FLUSH PRIVILEGES # 重新讀取許可權表中的資料到記憶體,不用重啟mysql就可以讓許可權生效,好處可以防止修改錯誤後,沒有餘地再去反悔。
補充說明
-
mysql 移除匿名賬戶,禁用root遠程登入: $ sudo mysql_secure_installation; 回答n,y,y,y,y
-
grant 用法:grant 許可權1,許可權2,…許可權n on 資料庫名稱.表名稱 to 使用者名稱@使用者地址 identified by ‘口令‘
其中許可權1,許可權2,…許可權n代表 select,insert,update,delete,create,drop,
index,alter,grant,reload,references,shutdown,process,file14個許可權。
例如:`grant select,insert,update,delete,create,drop on mousycoder.employee to
[email protected] identified by ‘123456′`
代表給來自10.163.225.87的使用者hello分配可對資料庫mousycoder的employee表進行select,insert,update,delete,create,drop等操作的許可權,並設定口令為123456。
安裝Nginx
# 安裝nginx$ apt-get install nginx -y $ apt-get install curl -y # curl是一種命令列工具,作用是發出網路請求,然後得到和提取資料。$ curl -i 127.0.0.1 # 確保Nginx 運行,預設監聽80連接埠# 設定web目錄和cache目錄$ mkdir /var/www$ mkdir -p /var/cache/nginx # -p 可以一下子把中間路徑中不存在的檔案夾也一起建立,非常實用$ chown www-data:www-data /var/www # nginx安裝會自動建立使用者www-data並且預設用這個使用者操作$ chown www-data:www-data /var/cache/nginx# 修改設定檔(一般不操作這個檔案)$ cp /etc/nginx/nginx.conf /etc/nginx/nginx.conf.old # 備份原來配置$ vi /etc/nginx/nginx.conf # 可以修改預設使用者為其他使用者# 為Ghost單獨建立nginx設定檔$ rm /etc/nginx/sites-enabled/default # 刪掉預設的配置$ vi /etc/nginx/sites-available/mousycoder # 建立一個nginx設定檔
nginx設定檔
server { listen 0.0.0.0:80; # 監聽的連接埠號碼 server_name mousycoder.com; # 把mousycoder.com換成自己的網域名稱,如果沒有網域名稱或者網站還沒備案下來這裡可以寫ip,例如120.25.150.209,如果配置多個網站的話,這裡可以通過不同的連接埠對應不同的網站,例如:120.25.150.209:81等 前提是這些連接埠外網還能訪問。 access_log /var/log/nginx/mousycoder.log; location / { proxy_set_header Host $http_host; proxy_set_header X-NginX-Proxy true; proxy_set_header X-Real-IP $remote_addr; proxy_pass http://127.0.0.1:2368; # 這裡是Ghost啟動時的預設連接埠,可以根據實際情況變化,預設也可以 #proxy_buffering off; proxy_redirect off; }}
然後重啟服務
$ ln -s /etc/nginx/sites-available/mousycoder /etc/nginx/sites-enabled/mousycoder # 建立軟連結到到實際配置路徑,方便統一維護設定檔變化。$ service nginx restart # nginx安裝好時已經預設註冊了系統的服務,我們就可以直接重啟nginx服務,讓設定檔生效
補充說明
nginx 這裡主要是做連接埠轉寄映射作用,當然它非常能抗壓。
安裝Node.Js
$ wget http://nodejs.org/dist/v0.10.39/node-v0.10.39-linux-x64.tar.gz $ tar zxf node-v0.10.39-linux-x64.tar.gz && cd node-v0.10.39-linux-x64$ cp bin/* /usr/bin # 拷貝執行目錄,相當於去設定一個環境變數到使用者的bin目錄
補充說明
這裡下載的並不是最新版的nodejs,為了穩定。
Ghost官網解釋
從 Ghost 0.6.0 版本開始,Ghost 中文版完整包已經整合了 Nodejs 0.12 版本的 sqlite3 原生庫,在 windows(32/64 bit)、Linux(32/64 bit)、Mac(64 bit)作業系統上可以直接在 Nodejs 0.10.x 和 0.12.x 版本上運行。但是,我們強烈建議使用 Node.js 0.10.x 最新版本。對 Node.js 0.12.x 版本的支援還有待考驗!
詳情見 ghost中文網,當然NodeJs有很多種安裝方法,個人覺得這種是在這裡最適合的方法。
安裝Ghost下載Ghost
$ cd /var/www/$ curl -L http://dl.ghostchina.com/Ghost-0.6.3-zh.zip -o mousycoder.zip$ unzip mousycoder.zip -d mousycoder$ cd mousycoder/
配置Ghost
Ghost有兩種運行模式:開發模式和產品模式,通過config.js配置
$ cp config.example.js config.js$ vi config.js
在config.js設定檔裡配置
- production # 生產模式 production:{ url: 'http://mousycoder.com', main:{}, database:{ client :'mysql', connection:{ host:'127.0.0.1', user:'root', # 資料庫連接的使用者 password:'123456', database:'mousycoder', charset:'utf-8' } } }- development # 開發模式 production:{ url: 'http://mousycoder.com', main:{}, database:{ client :'mysql', connection:{ host:'127.0.0.1', user:'root', # 資料庫連接的使用者 password:'123456', database:'mousycoderDev', charset:'utf-8' } } }
安裝與運行
根據package.json 安裝依賴包,進入當前mousycoder目錄下
$ cd /var/www/mousycoder$ npm install --production # 產品模式;只安裝啟動並執行包$ npm install # 開發模式,預設是開發模式
npm start --production
用mousycoder運行Ghost(非root賬戶運行Ghost更安全)
$ adduser -shell /bin/bash --gecos 'mousycoder blog' mousycoder$ chown -R mousycoder:mousycoder /var/www/mousycoder
安裝forever,保持Ghost一直在後台運行
$ cd /var/www/mousycoder$ npm install forever -g # 全域安裝forever模組$ NODE_ENV=production forever start index.js # 生產模式後台運行ghost
安裝系統服務
$ curl https://raw.githubusercontent.com/TryGhost/Ghost-Config/master/init.d/ghost -o /etc/init.d/mousycoder # 下載Ghost提供的指令碼到/etc/init.d/目錄,該目錄是系統服務類別目錄$ chmod +x /etc/init.d/mousycoder # 給指令碼賦予執行許可權$ usermod -aG mousycoder www-data # 把www-data使用者加入mousycoder組,讓其可以操作源檔案等目錄$ update-rc.d mousycoder defaults # 用update-rc.d 安裝服務 mousycoder$ update-rc.d mousycoder enable # 重新整理一遍服務,防止之前有重名的$ service mousycoder status # 查看mousycoder 服務的狀態$ service mousycoder start # 這樣開機就會自動啟動ghost生產環境,不信reboot一下
補充說明
drwxr-xr-x 第一列d 目錄 第2-4列 擁有者許可權 rwx 5-7列 r-x同組使用者權限 r-x是其他組使用者權限,其中rwx對應4,2,1
-
系統服務啟動順序
-
$ update-rc.d A start 50 1 2 3 4 5 stop 51 0 6$ start 50 1 2 3 4 5 # 表示在1,2,3,4,5這5個運行層級中,按先後順序,由小到大執行,第50個開始運行指令碼$ stop 50 0 6 # 表示在0,6這兩個運行層級中,按照先後順序,由小到到執行,第52個停止這個指令碼運行$ update-rc.d mousycoder remove # 卸載mousycoder開機服務
啟動
開啟瀏覽器,輸入之前配置的ip或者網域名稱
首頁 http://hostname.com/ghost
Ghost後台 http://hostname.com/ghost
現在你就可以盡情享受Ghost帶給你的極致簡潔了,快來書寫吧!
搭建Ghost 基於Node.js的開源部落格系統