这篇文章上次修改于 1272 天前,可能其部分内容已经发生变化,如有疑问可询问作者。
title: 博客创建记录
date: 2020/09/03 22:00:00
updated: 2020/09/05 01:23:00
permalink: record-of-blog-setup/
toc: true
环境
远程:hexo + nginx
本地:vscode + sftp
过程
sshd修改
修改22端口并使用key访问
首先生成私钥,注意提前创建/path/to/save/.ssh这个目录,当然也可以默认路径,另外输入密码时不会有任何显示。
ssh-keygen -t rsa
{% codeblock 生成私钥 lang:sh %}
Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa): /path/to/save/.ssh/id_rsa
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /path/to/save/.ssh/id_rsa.
Your public key has been saved in /path/to/save/.ssh/id_rsa.pub.
The key fingerprint is:
SHA256:QZ97tnQYLIw+w4KQNS+pRe8X4sCmDbyBJpJYWd6B0bM root@hostname
The key's randomart image is:
+---[RSA 2048]----+
| o. o+o. . |
| o + .oo.o |
|.= = =. o= o |
|. B + E.+ o |
|+ @ * +S. o o |
| + oo * = . |
| o o o o |
| . |
| |
+----[SHA256]-----+
{% endcodeblock %}
进入私钥和公钥的目录,并添加到authorized_keys
cd /path/to/save/.ssh
cat id_rsa.pub >> authorized_keys
设置权限
chmod 600 authorized_keys
chmod 700 /path/to/save/.ssh
修改/etc/ssh/sshd_config
nano /etc/ssh/sshd_config
主要修改部分,PubkeyAuthentication默认是yes就不用管了
Port 6666
AuthorizedKeysFile /path/to/save/authorized_keys
将/path/to/save/.ssh/id_rsa.pub保存到本地,然后导入使用,会提示输入密码,这个密码就是生成时输入的密码。
记得也修改端口,链接确认无误后将sshd_config的PasswordAuthentication改为no就可以禁止密码登录了。
安装curl、git、nginx、nodejs、npm
{% codeblock 安装命令 lang:bash %}
apt-get update
apt-get install curl
apt-get install git
apt-get install nginx
curl -sL https://deb.nodesource.com/setup_14.x | bash -
apt-get install -y nodejs
{% endcodeblock %}
root@hostname:~# curl -V
curl 7.52.1 (x86_64-pc-linux-gnu) libcurl/7.52.1 OpenSSL/1.0.2l zlib/1.2.8 libidn2/0.16 libpsl/0.17.0 (+libidn2/0.16) libssh2/1.7.0 nghttp2/1.18.1 librtmp/2.3
Protocols: dict file ftp ftps gopher http https imap imaps ldap ldaps pop3 pop3s rtmp rtsp scp sftp smb smbs smtp smtps telnet tftp
Features: AsynchDNS IDN IPv6 Largefile GSS-API Kerberos SPNEGO NTLM NTLM_WB SSL libz TLS-SRP HTTP2 UnixSockets HTTPS-proxy PSL
root@hostname:~# node -v
v14.9.0
root@hostname:~# npm -v
6.14.8
root@hostname:~# git --version
git version 2.11.0
安装hexo
如果没有预先建立博客目录,那就在init后面指定
cd /home/blog
npm install hexo-cli -g
/usr/bin/hexo -> /usr/lib/node_modules/hexo-cli/bin/hexo
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@~2.1.2 (node_modules/hexo-cli/node_modules/chokidar/node_modules/fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for [email protected]: wanted {"os":"darwin","arch":"any"} (current: {"os":"linux","arch":"x64"})
+ [email protected]
added 61 packages from 315 contributors in 8.953s
hexo init
INFO Cloning hexo-starter https://github.com/hexojs/hexo-starter.git
Submodule 'themes/landscape' (https://github.com/hexojs/hexo-theme-landscape.git) registered for path 'themes/landscape'
Cloning into '/home/blog/themes/landscape'...
Submodule path 'themes/landscape': checked out '73a23c51f8487cfcd7c6deec96ccc7543960d350'
INFO Install dependencies
added 183 packages from 420 contributors and audited 189 packages in 18.908s
8 packages are looking for funding
run `npm fund` for details
found 0 vulnerabilities
INFO Start blogging with Hexo!
npm install
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: [email protected] (node_modules/fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for [email protected]: wanted {"os":"darwin","arch":"any"} (current: {"os":"linux","arch":"x64"})
added 5 packages from 1 contributor and audited 189 packages in 3.766s
8 packages are looking for funding
run `npm fund` for details
found 0 vulnerabilities
hexo server
INFO Validating config
INFO Start processing
INFO Hexo is running at http://localhost:4000 . Press Ctrl+C to stop.
(node:5152) Warning: Accessing non-existent property 'lineno' of module exports inside circular dependency
(Use `node --trace-warnings ...` to show where the warning was created)
(node:5152) Warning: Accessing non-existent property 'column' of module exports inside circular dependency
(node:5152) Warning: Accessing non-existent property 'filename' of module exports inside circular dependency
(node:5152) Warning: Accessing non-existent property 'lineno' of module exports inside circular dependency
(node:5152) Warning: Accessing non-existent property 'column' of module exports inside circular dependency
(node:5152) Warning: Accessing non-existent property 'filename' of module exports inside circular dependency
初始化完成访问,效果如下:
设置主题
建议先进入博客目录,然后再执行命令
npm install hexo-theme-icarus
npm WARN [email protected] requires a peer of [email protected] but none is installed. You must install peer dependencies yourself.
npm WARN [email protected] requires a peer of hexo-component-inferno@^0.8.2 but none is installed. You must install peer dependencies yourself.
npm WARN [email protected] requires a peer of hexo-renderer-inferno@^0.1.3 but none is installed. You must install peer dependencies yourself.
npm WARN [email protected] requires a peer of hexo-renderer-stylus@^1.1.0 but none is installed. You must install peer dependencies yourself.
npm WARN [email protected] requires a peer of inferno@^7.3.3 but none is installed. You must install peer dependencies yourself.
npm WARN [email protected] requires a peer of inferno-create-element@^7.3.3 but none is installed. You must install peer dependencies yourself.
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: [email protected] (node_modules/fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for [email protected]: wanted {"os":"darwin","arch":"any"} (current: {"os":"linux","arch":"x64"})
+ [email protected]
added 1 package from 1 contributor and audited 190 packages in 5.181s
8 packages are looking for funding
run `npm fund` for details
found 0 vulnerabilities
hexo config theme icarus
INFO Validating config
INFO =======================================
██╗ ██████╗ █████╗ ██████╗ ██╗ ██╗███████╗
██║██╔════╝██╔══██╗██╔══██╗██║ ██║██╔════╝
██║██║ ███████║██████╔╝██║ ██║███████╗
██║██║ ██╔══██║██╔══██╗██║ ██║╚════██║
██║╚██████╗██║ ██║██║ ██║╚██████╔╝███████║
╚═╝ ╚═════╝╚═╝ ╚═╝╚═╝ ╚═╝ ╚═════╝ ╚══════╝
=============================================
INFO === Checking package dependencies ===
ERROR Package bulma-stylus is not installed.
ERROR Package hexo-component-inferno is not installed.
ERROR Package hexo-renderer-inferno is not installed.
ERROR Package hexo-renderer-stylus's version (2.0.0) does not satisfy the required version (^1.1.0).
ERROR Package inferno is not installed.
ERROR Package inferno-create-element is not installed.
ERROR Please install the missing dependencies your Hexo site root directory:
ERROR npm install --save [email protected] hexo-component-inferno@^0.8.2 hexo-renderer-inferno@^0.1.3 hexo-renderer-stylus@^1.1.0 inferno@^7.3.3 inferno-create-element@^7.3.3
ERROR or:
ERROR yarn add [email protected] hexo-component-inferno@^0.8.2 hexo-renderer-inferno@^0.1.3 hexo-renderer-stylus@^1.1.0 inferno@^7.3.3 inferno-create-element@^7.3.3
可能会有错误,按提示安装上
npm install --save [email protected] hexo-component-inferno@^0.8.2 hexo-renderer-inferno@^0.1.3 hexo-renderer-stylus@^1.1.0 inferno@^7.3.3 inferno-create-element@^7.3.3
然后再执行配置
hexo config theme icarus
INFO Validating config
Inferno is in development mode.
INFO =======================================
██╗ ██████╗ █████╗ ██████╗ ██╗ ██╗███████╗
██║██╔════╝██╔══██╗██╔══██╗██║ ██║██╔════╝
██║██║ ███████║██████╔╝██║ ██║███████╗
██║██║ ██╔══██║██╔══██╗██║ ██║╚════██║
██║╚██████╗██║ ██║██║ ██║╚██████╔╝███████║
╚═╝ ╚═════╝╚═╝ ╚═╝╚═╝ ╚═╝ ╚═════╝ ╚══════╝
=============================================
INFO === Checking package dependencies ===
INFO === Checking theme configurations ===
WARN None of the following configuration files is found:
WARN - /home/blog/_config.icarus.yml
WARN - /home/blog/node_modules/hexo-theme-icarus/_config.yml
INFO Generating theme configuration file...
INFO /home/blog/_config.icarus.yml created successfully.
INFO To skip configuration generation, use "--icarus-dont-generate-config".
INFO === Registering Hexo extensions ===
现在再刷新页面就可以看到新的主题了,如图:
图中可以看到一些错误,因为这个时候配置还没有完成。
hexo正式部署
由于计划使用是通过ftp,所以要安装hexo-deployer-sftp
npm install hexo-deployer-sftp --save
修改_config.yml的deploy配置
反正是直接生成到public文件夹,就不配置deploy了,反正是正常生成的...
生成文章(由于计划是用nginx,所以只需要generate就行,不用deploy)
hexo g
配置证书
不建议使用apt-get这种方式
apt-get install certbot
因为在我的服务器上遇到有python3.5然后不知道乱安装了一堆python的包,最后搞得很乱。
然后经过一下午的折腾,建议通过pip安装
如果没有pip,先把pip装上
curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py
注意使用的python版本,如果有py2,那么也会安装pip,后执行的会覆盖前面的
python get-pip.py
python3 get-pip.py
也就是说/usr/local/bin下有pip、pip2、pip3,后执行get-pip的,pip就是那个python版本的pip,pip2和pip3互不影响
这里用python3,现在安装certbot
pip3 install certbot
然后你会发现有个/usr/local/bin/certbot
/usr/local/bin/certbot certonly -d yourdomain.com -d *.yourdomain.com --manual --preferred-challenges dns-01 --server https://acme-v02.api.letsencrypt.org/directory
按提示选择你的软件,比如nginx
然后有个ip什么的必须要同意,接着还有个同意的输入A
就会显示一段字符,然后去域名服务商那里添加一个TXT记录,添加完等一会儿,然后回车确定
最后会提示Congratulations!字样就OK了
然后将nginx配置更改如下
server {
listen 80;
listen [::]:80;
listen 443 ssl;
listen [::]:443 ssl;
ssl on;
ssl_certificate /etc/letsencrypt/live/yourdomain/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/yourdomain/privkey.pem;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_ciphers HIGH:!aNULL:!MD5;
root /path/to/blog;
index index.html index.htm index.nginx-debian.html;
server_name blog.yourdomain.com;
location / {
try_files $uri $uri/ =404;
}
}
没有评论