安装配置使用
- 由于系统官方源太旧了Debian stretch 才4.8.2版本,所以我是下载官方的新版,下载地址如下。
Latest LTS Version: 10.15.0 includes npm 6.4.1
Windows X64 | Linux X64
- 安装hexo
官方默源安装:npm install hexo-cli -g
淘宝镜像加速:npm install hexo-cli -g --registry=https://registry.npm.taobao.org
- 克隆文件到当前路径下的
www
并初始化
1 2 3 4
| hexo init www cd www npm install
|
必须要到 www 目录下才能执行 hexo server 及 hexo generate ,否则一直出现hexo help界面。
打开hexo服务器 hexo server -p 8080
静态化博客 hexo generate
服务器的部署
- 下载和配置服务端的NodeJs
1 2 3 4 5 6
| sudo apt remove nodejs sudo chown -R leux:leux /opt/ wget https://nodejs.org/download/release/v10.15.0/node-v10.15.0-linux-x64.tar.gz tar -xzvf node-v10.15.0-linux-x64.tar.gz mv node-v10.15.0-linux-x64 /opt/nodejs
|
- 下载安装服务端的Hexo
1 2 3 4 5 6
| export PATH=$PATH:/opt/nodejs/bin/ npm install hexo-cli -g hexo init /opt/nodejs/www cd /opt/nodejs/www npm install
|
- 下载安装服务端的Hexo主题Next
1 2 3 4
| wget https://github.com/theme-next/hexo-theme-next/archive/v6.0.0.tar.gz tar -xzvf v6.0.0.tar.gz mv hexo-theme-next-6.0.0 /opt/nodejs/www/themes/next
|
- 配置和启用服务端的Hexo主题Next
1 2 3 4 5
| wget https://leux.cn/dl/hexo_config.diff wget https://leux.cn/dl/next_config.diff patch /opt/nodejs/www/_config.yml hexo_config.diff patch /opt/nodejs/www/themes/next/_config.yml next_config.diff
|
- 打开hexo server测试无误后静态化博客试试
1 2 3 4
| cd /opt/nodejs/www/ hexo server -p 8080 hexo generate
|
- 在服务器上搭建Git仓库来存放文章
1 2 3 4 5 6 7
| sudo apt install git mkdir /opt/doc.git cd /opt/doc.git git init --bare ./ chown -R git:git /opt/doc.git
|
- 设置自动部署网站(即每次push成功后都会执行静态化到WEB服务器目录下)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
| vi /opt/doc.git/hooks/post-receive && chmod +x /opt/doc.git/hooks/post-receive
git --work-tree=/opt/nodejs/www/source/_posts --git-dir=/opt/doc.git checkout -f
WEB_DIR=/opt/www TAR_DIR=/opt/nodejs/www HEXO_DIR=/opt/nodejs/bin
cd $TAR_DIR $HEXO_DIR/hexo clean $HEXO_DIR/hexo generate rm -rf $WEB_DIR/404 $WEB_DIR/about $WEB_DIR/archives $WEB_DIR/categories $WEB_DIR/css $WEB_DIR/doc $WEB_DIR/images $WEB_DIR/js $WEB_DIR/lib $WEB_DIR/page $WEB_DIR/tags $WEB_DIR/index.html mv $TAR_DIR/public/* $WEB_DIR/
|
客户端的部署
- 在客户端上使用仓库
1 2 3 4 5 6 7 8 9
| cd /opt/nodejs/www/source/_posts git clone ssh://name@IP:Port/opt/doc.git ./ git config core.autocrlf false git config core.filemode false git config core.quotepath false git add . git commit -m "Initial" git push origin master
|
- 指定密钥登陆
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
| mv publickey C:\Users\git\.ssh\id_rsa mv publickey /home/git/.ssh/id_rsa
sudo chown -R git:git /home/git/.ssh/ sudo chown -R git:git /opt/doc.git
ssh-add ~/.ssh/id_rsa_me
Host github.com User git HostName github.com PreferredAuthentications publickey IdentityFile ~/.ssh/.ssh/github
|