您的位置:首页 > 运维架构 > Linux

hexo-迁移到linux所遇到的问题

2017-12-08 14:52 260 查看
在安装了linux后,我决定将hexo博客移到linux上,其配置过程和在windows上大致相同,但是转移过程中还是遇到了很多困难,以防万一我将其记录下来。

Nodejs 安装(参考 Linux下安装Nodejs

首先可以直接使用命令安装

$ sudo apt-get install nodejs
$ sudo apt-get install npm


但是我使用这种方法安装出现了各种问题,可能是版本太低,而且它会直接安装在
/usr/local/bin/
下,所以如果这种方法行不通一定要将其下的
npm
nodejs
文件删掉。

然后就是选择在[]Nodejs官网](https://nodejs.org/en/)上下载推介的比较新的版本v6.9.2 LTS,但是下载比较慢,我将我下载的上传

点击下载

下载解压好后

#path_to为解压文件后实际地址
$ ln -s /path_to/bin/node /usr/local/bin/node
$ ln -s /path_to/bin/npm /usr/local/bin/npm


这样在
/usr/local/bin/
中也会生成
nodejs
npm
文件,以后在任意路径下都可以执行
node
npm
两个命令了。

安装Git

$ sudo apt-get install git


安装hexo

$ sudo npm install hexo-cli -g


安装Hexo安成后,使用如下命令快速新建一个博客系统

$ hexo init blog
$ cd blog
$ npm install


如果npm安装失败,请使用sudo安装

http://0.0.0.0:4000/ 无法访问

在执行
hexo server
进行预览时,我发现http://0.0.0.0:4000/ 无法显示,原因是为了翻墙我曾经覆盖过hosts文件,新的hosts文件缺了
127.0.0.1   localhost
127.0.1.1 ed//用户名
,补回后便可预览。

转移原备份博客

将原来博客目录下的
source
theme
_config.yml
覆盖到新的博客目录中

hexo deploy失败

修改_
config.yml
deploy type: git

$ npm install hexo-deployer-git --save


hexo deploy必须使用sudo

ctrl H
显示隐藏文件夹
.deploy_git
,其中的文件都有个上锁的标号(权限不够)

$ sudo chmod -R 777 .deploy_git
我索性将其权限最大化(可能700等也可以),这样就省掉了sudo的麻烦

添加SSH后deploy仍然需要输入账户和密码

生成本地SSH密匙

首先打开命令行工具,通常我们可以直接右键鼠标任意位置打开 Git Bash Here,然后输入以下命令

$ cd ~/.ssh
# Checks to see if there is a directory named ".ssh" in your user directory


使用
ssh-keygen
生成密钥

$ ssh-keygen -t rsa -C "your_email@example.com"
# Creates a new ssh key using the provided email
Generating public/private rsa key pair.
Enter file in which to save the key (/home/you/.ssh/id_rsa):


使用默认的文件名直接enter,接下来显示如下

Enter passphrase (empty for no passphrase): [Type a passphrase]
Enter same passphrase again: [Type passphrase again]


按提示输入密码即可(简化流程的话在键入命令
ssh-keygen -t rsa -C "your_email@example.com"
以后的三次提示输入都可以直接回车跳过)。

密钥生成成功

Your identification has been saved in /home/you/.ssh/id_rsa.
Your public key has been saved in /home/you/.ssh/id_rsa.pub.
The key fingerprint is:
…………………此处是密钥内容…………………… your_email@example.comba


设置github SSH keys

可以选择是在用户设置中添加密钥(Settings –> SSH GPG keys)还是单个项目中添加密钥,在这里我就在我们的博客项目中添加密钥,此处以我的博客为例。

eddyguo.github.io
的首页菜单栏中点击 Settings –> Deploy keys –> Add deploy key,然后将生成的
id_rsa.pub
中的内容全选复制到 key 输入框中,然后点击 Add key 完成添加公钥。

接下来测试配置是否成功

$ ssh -T git@github.com


如果出现以下内容即表示配置完成并且成功!

Hi username! You've successfully authenticated, but GitHub does not
provide shell access.


解决SSH不起作用的问题

将https改成git:

把博客目录下_
config.yml
/.deploy_git/.git/config
中url都改成
git@github.com:Name/project.git
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  linux