一開始將本身hexo
部署到github
,結果發現打開頁面速度有點慢,而後又將其同時部署到coding
,實現雙線路訪問,國內解析記錄到coding
,國外解析到github
,這樣確實網站的速度能提升很多,可是國內訪問由於是通過coding
,因此打開網站會有廣告,這點不能容忍,因而想到本身的服務器也還空閒着,因而想到能夠部署到本身的服務器上,折騰開始
演示站點php
Windows10
(64位)CentOS
7.2 64位)git
,NodeJs
,hexo
..)git
,Nginx
)dnspod
)ssh-keygen -t rsa -C "郵件地址"
~/.ssh
目錄中,看到有id_rsa
,id_rsa.pub
這些文件便可bash yum install git #安裝NodeJS curl --silent --location https://rpm.nodesource.com/setup_5.x | bash -
bash adduser git chmod 740 /etc/sudoers vim /etc/sudoers
## Allow root to run any commands anywhere root ALL=(ALL) ALL
bash git ALL=(ALL) ALL
bash chmod 400 /etc/sudoers
bash sudo passwd git
git
用戶,建立 ~/.ssh
文件夾和 ~/.ssh/authorized_keys
文件,並賦予相應的權限bash su git mkdir ~/.ssh vim ~/.ssh/authorized_keys #而後將本地電腦中執行 cat ~/.ssh/id_rsa.pub | pbcopy ,將公鑰複製粘貼到 authorized_keys chmod 600 ~/.ssh/authorzied_keys chmod 700 ~/.ssh
git
ssh -v git@SERVER
SERVER
爲填寫本身的雲主機IP
bash # repo 做爲爲git倉庫目錄 mkdir -R /var/repo # hexo 做爲網站根目錄 mkdir -R /var/www/hexo
nginx
(固然Apache
也是能夠的,nginx
的安裝步驟省略)ngixn -t
找到配置文件,個人是在/etc/nginx/nginx.conf
,配置SERVER
server { listen 80; # server_name 填寫本身的域名 server_name www.fayne.cn; # 這裏root填寫本身的網站根目錄 root /var/www/hexo; index index.html index.php index.htm; #/usr/local/tomcat/webapps/Forum # Load configuration files for the default server block. include /etc/nginx/default.d/*.conf; location / { } location ~ .php$ { } error_page 404 /404.html; location = /40x.html { } error_page 500 502 503 504 /50x.html; location = /50x.html { } }
dnspod
設置解析記錄,設置解析A
記錄www
解析到服務器IP地址
, 解析線路默認CNAME
解析使www
解析到xxx.github.io
,解析線路國外,這裏的xxx
爲hexo
部署在github
的倉庫名稱,這樣保證了在國外訪問速度也是極佳的git
自動化部署博客自動化部署主要用到了git
-hooks
同步html
git
用戶登陸,確保git
用戶擁有倉庫全部權su git cd /var/repo/ git init --bare blog.git
post-update
這個鉤子(也有多是post-receive
,具體進入文件就知道了),當git有收發的時候就會調用這個鉤子。 在 /var/repo/blog.git
裸庫的 hooks
文件夾中vim /var/repo/blog.git/hooks/post-update # 編輯文件,寫入如下內容
#!/bin/sh git --work-tree=/var/www/hexo --git-dir=/var/repo/blog.git checkout -f
chmod +x post-update
_config.yml
,完成自動化部署_config.yml
, 找到deploy
deploy: type: git repo: github: git@github.com:Finhoo/Finhoo.github.io.git www: git@www.fayne.cn:/var/repo/blog.git branch: master
hexo clean && hexo g -d
github
快多了,國外速度也是很好我在部署過程當中,執行 hexo d
發現部署總是出錯,什麼權限不容許之類的,這裏咱們須要檢查咱們在上述的git操做部署是否使用了git
用戶操做,如果沒有,須要給相應的目錄更改用戶組
使用chown -R git:git /var/repo/
這條命令遞歸的將repo
目錄及其子目錄用戶組設置爲git
,同時chown -R git:git /var/www/hexo
,這樣便可解決此類問題node