Hexo搭建

Cloudflare Pages + Hexo 搭建个人博客

介绍

Hexo

官网:Hexo

Hexo 是一个基于 Node. js 的静态网站生成器,它可以让你快速、简单地搭建个人博客或静态网站。Hexo 使用 Markdown(或其他类似的标记语言)来书写内容,并通过模板引擎将这些内容转换成静态网页。

一些主要的特点包括:

  1. 快速搭建:Hexo 具有快速搭建网站的特点,可以帮助你快速创建个人博客或者静态网站。
  2. Markdown:Hexo 支持使用 Markdown 格式来书写内容,使得发布文章变得非常方便。
  3. 主题支持:Hexo 拥有丰富的主题支持,用户可以根据自己的喜好选择合适的主题来呈现自己的网站内容。
  4. 插件系统:Hexo 具备丰富的插件系统,可以方便地扩展各种功能,例如 SEO 优化、社交分享、页面统计等。
  5. 静态网站:Hexo 生成的是静态网页,这意味着网站运行速度较快,且更易于部署和备份。

总的来说,Hexo 是一个简单、高效的静态网站生成器,适合那些喜欢书写内容、追求效率,并且希望快速搭建个人博客或静态网站的用户使用。

Cloudflare Pages

Cloudflare Pages 是一个由 Cloudflare 提供的静态网站部署服务。它允许用户轻松地将静态网站部署到 Cloudflare 的全球内容分发网络(CDN)上。

相对于 GitHub Pages,Cloudflare Pages 的优势主要体现在以下几个方面:

  1. CDN 覆盖范围:Cloudflare 在中国大陆拥有合规的 CDN 服务,这意味着您的网站可以通过 Cloudflare 在中国获得更好的访问性能,因为 Cloudflare 在全国各地都拥有较广泛的 CDN 点。
  2. 性能与稳定性:Cloudflare 的 CDN 架构致力于提供更快的加载速度和更好的可用性,并通过优化网络效率来提高页面交付速度。
  3. 安全性:Cloudflare 不仅仅提供 CDN,还提供安全防护、SSL 加密等服务,这些服务可以帮助保护您的网站免受 DDoS 攻击等安全威胁。
  4. 全球网络优势:Cloudflare 在全球拥有大量的数据中心,能够更好地为全球用户提供稳定的访问体验。

另外,Cloudflare 还提供了一定量的免费存储服务 R2,如果你愿意的话还可以把你的图床部署在这里。

本地搭建

前置条件

在部署 Hexo 之前,首先需要安装 Git 和 Node.js 服务。如果你尚未安装这些服务,你可以通过以下链接下载并安装:

这两个软件都提供了一键式安装程序,只需一直点击”下一步”即可完成安装。

安装完成后,你可以在控制台使用命令 git -vnpm -v 分别验证 Git 与 NodeJs 是否安装成功。

之后你需要拥有 Github 与 Cloudflare 的账号,其中 Cloudflare 可能需要付款方式验证,如果没有 Visa 信用卡的话可以使用 PayPal 进行验证,下面是两者的官网:

安装

  • 在 Github 中创建一个新项目用于存储 Hexo 博客

image.png

image.png

  • 在本地同步这个项目

在想要同步的目录右键打开控制台

image.png

image.png

获取项目链接

image.png

image.png

使用 git clone “项目地址” 同步项目到本地

image.png

image.png

  • 生成 Hexo 项目

保持控制台工作目录依次执行一下命令

  1. 安装 hexo-cli,npm install hexo-cli -g
  2. hexo 初始化,hexo init blog,其中 blog 是你的项目名
  3. 进入项目目录,cd blog,其中 blog 是你的项目名
  4. 项目安装,npm install
  5. 启动测试,hexo server

执行完毕后项目文件夹下应该生成很多新文件,类似下图的结构

image.png

image.png

执行 hexo server 后出现一下结果说明项目创建成功,访问 localhost: 4000 即可访问本地博客

image.png

image.png

Hexo 详细用法

Hexo 文档:文档 | Hexo

常用命令

  • hexo new
    在项目目录中打开控制台输入 hexo new "First post"

image.png

image.png

image.png

image.png

在项目的 \source\_posts\ 目录下就会创建对应文章的 markdown 文章,上面自带部分就是 Hexo 识别文章的核心 Front-matter,它用于标识文章的分类、Tags、标题、创建日期等关键信息,下一章会详细介绍这个部分。

  • hexo clean
    用于清除缓存文件 (db.json) 和已生成的静态文件 (public)。

在某些情况(尤其是更换主题后),如果发现您对站点的更改无论如何也不生效,您可能需要运行该命令。

  • hexo generate
    用于生成静态文件,该命令可以简写为 hexo g
  • hexo server
    启动服务器。默认情况下,访问网址为: http://localhost:4000/。该命令可以简写为 hexo s
  • hexo depoly
    部署网站,构建在 Pages 的服务器中。该命令可以简写为 hexo d

配置参数

参数 描述 默认值
layout 布局 config.default_layout
title 标题 文章的文件名
date 建立日期 文件建立日期
updated 更新日期 文件更新日期
comments 开启文章的评论功能 true
tags 标签(不适用于分页)
categories 分类(不适用于分页)
permalink 覆盖文章的永久链接,永久链接应该以 /.html 结尾 null
excerpt 纯文本的页面摘要。使用 该插件 来格式化文本
disableNunjucks 启用时禁用 Nunjucks 标签 {{ }}/{% %}标签插件 的渲染功能 false
lang 设置语言以覆盖 自动检测 继承自 _config.yml
published 文章是否发布 对于 _posts 下的文章为 true,对于 _draft 下的文章为 false

主题选择

Hexo 主题:Themes | Hexo

在 Hexo 官网你可以找到很多主题,找到你想要的主题点击即可进入对应主题项目的 Github 页面,跟后根据主题给出的引导配置即可完成安装。下面使用 shana 进行介绍。

安装

1
2
3
git clone https://github.com/ShanaMaid/hexo-theme-shana themes/shana

BASH

配置

修改hexo根目录下的 _config.yml

1
2
3
4
5
`language: zh-CN`

`theme: shana`

AUTOHOTKEY

同时将themes/shana/_source/tagscategories文件夹拷贝到hexo根目录下的source文件夹下

更新

1
2
3
4
5
cd themes/shana

git pull origin master

BASH

然后创建对应主题的配置文件即可。

部署到 Cloudflare

  • 登录 Cloudflare 进入控制台页面,找到 Workers 和 Pages 并点击创建应用程序,

image.png

image.png

  • 选择 Pages ,然后选择链接到 Git

image.png

image.png

  • 然后选自存储你 Hexo 项目的仓库

image.png

image.png

  • 部署构建项目
    使用命令:npm install -g hexo; hexo clean; hexo generate

image.png

image.png

  • 构建完成后,你就可以使用 cf 生成的 pages.dev 二级域名来访问自己的博客了

image.png

image.png

  • 将博客绑定到自己的域名

image.png

image.png

之后你的域名 DNS 就会多一个你的博客的域名

image.png

copy from Cloudflare Pages + Hexo 搭建个人博客 - LeeLurker

Alacritty

How To Make Your macOS Terminal Amazing With Alacritty

Published: May 1, 2024

After recommendations from you guys, I’ve swapped out Alacritty for WezTerm! Everything is the same except the Alacritty config file, you can swap it out with this ~/.wezterm.lua file and everything should look and work very similar to Alacritty!

Alacritty is an awesome, minimal and fast terminal setup that has worked great for me as an alternative to iTerm2. Let’s set it up!

You can find my dotfiles here

Open The Terminal App

Open the default terminal app on macOs.

This setup is specifically for zsh (default) so make sure you are using that.

You can check by doing:

1
echo $0

You can change to zsh if you have it installed by doing:

1
chsh -s /bin/zsh

Install homebrew

Run the following command:

1
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"

If necessary, when prompted, enter your password here and press enter. If you haven’t installed the XCode Command Line Tools, when prompted, press enter and homebrew will install this as well.

Add To Path (Only Apple Silicon Macbooks)

After installing, add it to the path. This step shouldn’t be necessary on Intel macs.

Run the following command to add the necessary line to ~/.zprofile:

1
echo 'eval "$(/opt/homebrew/bin/brew shellenv)"' >> ~/.zprofile

Now source ~/.zprofile by doing:

1
source ~/.zprofile

Install Alacritty

Now you can install alacritty:

1
brew install --cask alacritty

Install git

Next install git:

1
brew install git

Install Meslo Nerd Font

Nerd Fonts are great for showing icons in the terminal. I personally use Meslo Nerd Font, but there are others.

You can install a nerd font with homebrew. Take a look at the fonts in the hombrew casks repo: homebrew-cask

It is no longer necessary to tap the homebrew-cask-fonts repo as the fonts have been added to homebrew-cask.

Then you can install the nerd font you’d like

1
brew install font-meslo-lg-nerd-font

Setup Alacritty Config File

Next we’ll setup the ~/.config/alacritty/alacritty.toml configuration file to configure Alacritty.

First create the necessary directory:

1
mkdir -p ~/.config/alacritty

Then move into it:

1
cd ~/.config/alacritty

Now add the alacritty.toml file like so:

1
touch alacritty.toml

Then open it with your editor of choice. I use Neovim, but you can use whatever you prefer.

To open with Neovim do:

1
nvim alacritty.toml

You can also open with Vim:

1
vim alacritty.toml

Or TextEdit:

1
open -a TextEdit alacritty.toml

Or VSCode:

1
code alacritty.toml

Add the configuration to alacritty.toml

See this for all the available options. See this to learn more about the toml.

Add the following configuration to this file. You can modify this to suit your needs.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
[env]
TERM = "xterm-256color"

[window]
padding.x = 10
padding.y = 10

decorations = "Buttonless"

opacity = 0.7
blur = true

option_as_alt = "Both"

[font]
normal.family = "MesloLGS Nerd Font Mono"

size = 18

Install powerlevel10k theme

Powerlevel10k is an awesome theme for zsh.

Install it like so:

1
brew install powerlevel10k

Then run the following:

1
echo "source $(brew --prefix)/share/powerlevel10k/powerlevel10k.zsh-theme" >> ~/.zshrc

This will add what you need to ~/.zshrc to enable it.

Now source ~/.zshrc:

1
source ~/.zshrc

The powerlevel10k configuration wizard should show up now.

If you want to open the wizard manually do: p10k configure.

Answer the prompts to make the theme look like you would like it to. For the colors of my coolnight theme to work use either lean (with the 8 colors option) or rainbow.

Setup the colorscheme for powerlevel10k and the terminal

Now we’ll setup the colorscheme.

Navigate to ~/.config/alacritty

1
cd ~/.config/alacritty

Then clone this repo which has a bunch of different alacritty themes like so:

1
git clone https://github.com/alacritty/alacritty-theme themes

Make sure you use the command as shown above to create a themes directory inside of ~/.config/alacritty.

Add my coolnight theme to the themes folder

I’ve put together my own theme called coolnight, inspired by my previous iTerm2 theme.

You can add it to the themes directory with this command:

1
curl https://raw.githubusercontent.com/josean-dev/dev-environment-files/main/.config/alacritty/themes/themes/coolnight.toml --output ~/.config/alacritty/themes/themes/coolnight.toml

Now open the alacritty.toml file with your editor of choice. With Neovim it would be:

1
nvim alacritty.toml

Now add the following to the top of this file:

1
2
3
import = [
"~/.config/alacritty/themes/themes/coolnight.toml"
]

Save this file and go back to the command line.

Fix directory background color (only for p10k rainbow style)

If you’re using the rainbow version of powerlevel10k, I recommend you change the directory background color from blue to black.

Open ~/.p10k.zsh with your editor of choice. With Neovim it would be:

1
nvim ~/.p10k.zsh

And then look for POWERLEVEL9K_DIR_BACKGROUND and change the color from 4 to 0 like so:

1
typeset -g POWERLEVEL9K_DIR_BACKGROUND=0

Better zsh history completion with up, down arrows

Let’s improve the history completion with the up and down arrows.

Open ~/.zshrc and add the following to the bottom of this file:

1
2
3
4
5
6
7
8
# history setup
HISTFILE=$HOME/.zhistory
SAVEHIST=1000
HISTSIZE=999
setopt share_history
setopt hist_expire_dups_first
setopt hist_ignore_dups
setopt hist_verify

This will allow zsh to save the history to a file and configure how it should do so.

Then go back to the command line and run:

1
cat -v

Now press on your up and down arrow keys.

Copy the codes that you get as output.

Open the ~/.zshrc file again and add the following to the bottom of this file:

1
2
3
# completion using arrow keys (based on history)
bindkey '^[[A' history-search-backward
bindkey '^[[B' history-search-forward

Replace ^[[A and ^[[B with the key codes you got for up and down arrow keys if they are different.

Setup zsh-autosuggestions plugin

This plugin provides some really nice auto completion functionality as you type out commands.

Install it like so:

1
brew install zsh-autosuggestions

Then run the following:

1
echo "source $(brew --prefix)/share/zsh-autosuggestions/zsh-autosuggestions.zsh" >> ~/.zshrc

This will add what you need to ~/.zshrc.

Now source it:

1
source ~/.zshrc

Now you can use the plugin! When you get a suggestion and want to use it, use the right arrow key.

Setup zsh-syntax-highlighting

This will provide some really nice syntax highlighting as you type out commands.

Install it like so:

1
brew install zsh-syntax-highlighting

Then run:

1
echo "source $(brew --prefix)/share/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh" >> ~/.zshrc

This adds what you need to ~/.zshrc to enable the plugin.

Now source ~/.zshrc:

1
source ~/.zshrc

You should be getting the syntax highlighting now!

Install eza (better ls)

eza is a better version of ls with lots of different options.

Install it:

1
brew install eza

Now you can start using it!

You can create an alias for it in ~/.zshrc like so:

1
2
3
# ---- Eza (better ls) -----

alias ls="eza --icons=always"

Install zoxide (better cd)

zoxide is an amazing alternative to cd.

It will remember the directories you’ve visited in the past and make it really easy to navigate back to them by just typing out a portion of the name of the directory you want to visit.

Install it like so:

1
brew install zoxide

Then add the following to ~/.zshrc:

1
2
# ---- Zoxide (better cd) ----
eval "$(zoxide init zsh)"

If you want to keep using cd then create an alias in ~/.zshrc:

1
2
3
4
# ---- Zoxide (better cd) ----
eval "$(zoxide init zsh)"

alias cd="z"

Save and then run:

1
source ~/.zshrc

Now you can use z as a much smarter replacement to cd.

Setup tmux

I have a dedicated video that goes in depth as to how I setup and use tmux.

It is very useful for managing sessions in the terminal as well as different windows and panes.

Let’s install tmux:

1
brew install tmux

Then you’ll want to add a config for it and it should be located in ~/.tmux.conf.

You can automatically use mine with this command:

1
curl https://raw.githubusercontent.com/josean-dev/dev-environment-files/main/.tmux.conf --output ~/.tmux.conf

Also install tpm (tmux plugin manager):

1
git clone https://github.com/tmux-plugins/tpm ~/.tmux/plugins/tpm

Now you can start tmux by running:

1
tmux

Then install the plugins I use with it by pressing CTRL-A (my prefix) followed by Shift-I.

If this doesn’t work or tmux was already running, try reloading the tmux config first:

1
tmux source ~/.tmux.conf

Then try pressing CTRL-A followed by Shift-I again.

For the tmux theme that I’m using to work properly, you’ll probably need to install a newer version of bash:

1
brew install bash

Then reload the tmux configuration by doing CTRL-A (my prefix) followed by r.

You’re Done!! 🚀

copy from https://www.josean.com/posts/how-to-setup-alacritty-terminal

grep保留表头

linux下使用grep过滤信息如何保留第一行列头标题?

方法一:组合shell命令

通过head获取第一行,再通过grep进行过滤

例如:

ps axuw | head -1; ps axuw | grep ssh;

方法二:grep结合正则表达式

grep -E 使用扩展正则表达式,通过正则表达式的或条件实现

例如:

ps axuw | grep -E “^USER|ssh”;

说明:

    需要使用双引号,避免正则表达式的或|被识别为管道;
    其中^USER为匹配以USER开头的行,结合不同命令的列头标题的开头内容进行使用。

————————————————

原文链接:https://blog.csdn.net/justCJH/article/details/139861062

二进制安装mysql

[Ubuntu 24.04 二进制安装 MySQL

安装必要的依赖

apt -y install numactl libaio1t64 -y

ln -sv /usr/lib/x86_64-linux-gnu/libtinfo.so.6.4 /usr/lib/x86_64-linux-gnu/libtinfo.so.5
ln -sv /usr/lib/x86_64-linux-gnu/libaio.so.1t64.0.2 /usr/lib/x86_64-linux-gnu/libaio.so.1

添加用户和用户组

groupadd -r mysql
useradd -M -g mysql -r -s /bin/false -c “MySQL Server” mysql

下载和解压 mysql 二进制安装包

mkdir /data/software -p
cd /data/software
wget https://cdn.mysql.com/archives/mysql-8.0/mysql-8.0.20-linux-glibc2.12-x86_64.tar.xz
tar -xvf mysql-8.0.20-linux-glibc2.12-x86_64.tar.xz
cp -rf mysql-8.0.20-linux-glibc2.12-x86_64 /usr/local/mysql8_3306

创建数据和日志目录

cd /data/
mkdir mysql8_3306/{data,log,log-bin} -p
touch mysql8_3306/log/mysql-err.log
chown -R mysql:mysql /data/mysql8_3306

创建配置

cat >> /usr/local/mysql8_3306/my.cnf << EOF
[mysqld]
port=3306
log-error=/data/mysql8_3306/log/mysql-err.log
basedir=/usr/local/mysql8_3306
datadir=/data/mysql8_3306/data
socket=/data/mysql8_3306/mysql.sock
server-id=1
log-bin=/data/mysql8_3306/log-bin/mysql-bin
character-set-server=utf8mb4
default-storage-engine=INNODB
user=mysql
lower_case_table_names=1
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLE
max_connect_errors=2000
max_connections=1500
default-authentication-plugin=mysql_native_password

[client]
socket=/data/mysql8_3306/mysql.sock
default-character-set=utf8mb4
EOF

初始化数据库

cd /usr/local/mysql8_3306
./bin/mysqld –defaults-file=/usr/local/mysql8_3306/my.cnf –initialize –console –user=mysql

创建 systemctl 配置

cat >/etc/systemd/system/mysqld8_3306.service <<EOF
[Unit]
Description=MySQL Server
Documentation=man:mysqld(8)
Documentation=http://dev.mysql.com/doc/refman/en/using-systemd.html
After=network.target
After=syslog.target
[Install]
WantedBy=multi-user.target
[Service]
User=mysql
Group=mysql
ExecStart=/usr/local/mysql8_3306/bin/mysqld –defaults-file=/usr/local/mysql8_3306/my.cnf
LimitNOFILE = 5000
EOF

启动数据库和设置开机启动

systemctl start mysqld8_3306
systemctl enable mysqld8_3306

获取数据库初始密码

grep “password” /data/mysql8_3306/log/mysql-err.log

使用初始密码登录数据库

cd /usr/local/mysql8_3306
./bin/mysql –socket=/data/mysql8_3306/mysql.sock -uroot -p

修改密码

alter user root@localhost identified by “KLVCHEN123456”;
flush privileges;
use mysql;
update user set host = ‘%’ where user = ‘root’;
flush privileges;
ALTER USER ‘root‘@’%’ PASSWORD EXPIRE NEVER;
flush privileges;

Copy from Ubuntu 24.04 二进制安装 MySQL 8.0.20 - klvchen - 博客园 (cnblogs.com)