0%

方法1 直接在git后台设置xxx分支为保护分支就可以了,比如master

方法2,进入到项目文件夹

1
2
cd .git/hooks/
cp pre-commit.sample pre-commit

在最前面加上代码,master可以替换对应分支

1
2
3
4
5
6
7
#!/bin/sh
branch="$(git rev-parse --abbrev-ref HEAD)"
if [ "$branch" = "master" ]; then
echo "You can't commit to master!"
exit 1
fi
# 后面的省略,可以不管,或者都删除了

新建git项目

1
2
首先在 GitHub 新建一个仓库(Repository),名称为 https://username}.github.io,注意这个名比较特殊,
必须要是 github.io 为后缀结尾的。比如我的GitHub用户名就叫qzy123456,那我就新建一个qzy123456.github.io,新建完成之后就可以进行后续操作了。

安装 Hexo

1
npm install -g hexo-cli

初始化项目

1
hexo init {name}

安装git推送插件

1
npm install hexo-deployer-git --save

安装图片插件

1
npm install hexo-image-link --save

修改_config.yml中的post_asset_folder: true 这个修改可以同时在source/_posts目录下建立一个同名文件夹,用于放图片

配置站点信息_config.yml 文件,找到 Site 区域

1
2
3
4
5
6
7
title: 齐朝阳的博客
subtitle: 二级title
description: PHP、Go、Python、Js、Html、Vue、Mysql、Redis、Mongo、Linux、Es、ClickHouse、K8s、Docker、分布式...
keywords: "PHP、Go、Python、Js、Html、Vue、Mysql、Redis、Mongo、Linux、Es、ClickHouse、K8s、Docker、分布式..."
author: 技术栈
language: zh-CN
timezone: Asia/Shanghai

安装主题,在项目根目录

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

修改项目根目录下的 _config.yml 文件,找到 theme 字段,修改为 next 即可,修改如下:

1
theme: next

主题配置,注意修改的 themes/next/_config.yml 文件

1
scheme: Pisces

新建页面

1
hexo new "Page Title"

生成静态文件

1
hexo g

启动本地服务

1
hexo s

删除静态文件缓存

1
hexo clean

发布到git,需要配置config

1
2
3
4
deploy:
type: git
rero: git@github.com:qzy123456/qzy123456.github.io.git
branch: main
1
hexo deploy

新建 标签 和分类 页面

1
在根目录输入命令 hexo new page categories 会自动新建 categorier 文件夹并生成一个index.md文件,将里面的代码改为:
1
2
3
4
5
---
title: categories
date: 2020-01-21 12:12:26
type: "categories"
---

同理,「标签」也一样 hexo new page tags 生成 tags 文件夹,其中会自动生成一个index.md文件,将代码改为:

1
2
3
4
5
---
title: tags
date: 2020-01-21 12:13:08
type: "tags"
---

配置菜单

1
2
3
4
5
6
7
8
9
10
11
12
13
14
在themes\next下的_config.yml中
menu:
home: / || home
#about: /about/ || user
tags: /tags/ || tags
categories: /categories/ || th
archives: /archives/ || archive
#schedule: /schedule/ || calendar
#sitemap: /sitemap.xml || sitemap
#commonweal: /404/ || heartbeat

# Enable / Disable menu icons / item badges.
menu_settings:
icons: true

使用时,如果要对文章使用「tags」「categories」,只需在文章开头添加如下代码:

1
2
3
4
5
6
---
title: 摸鱼
date: 2020-01-21 12:04:59
tags: 杂项
categories: 技术
---

为了方便,我们可以修改post模板,修改Hexo\scaffolds\post.md

1
2
3
4
5
6
---
title: {{ title }}
date: {{ date }}
tags:
categories:
---

其他

用base编码处理图片

1
{% asset_img "png;base64,iVBORw0KGgoAAAANSUhEUgAAA..." "Alt text" %}

filebeat基本配置

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# 输入
filebeat.inputs:
- type: log
enabled: true
paths:
- Z:\webman\runtime\logs\ad-*.log
#json.keys_under_root: true
#json.overwrite_keys: true
#json.add_error_key: true
fields_under_root: true
#这种配置既可以解析json,又支持原日志
processors:
- decode_json_fields:
fields: ['message']
target: ""
overwrite_keys: false
process_array: false
max_depth: 1
#过滤系统自带的字段,有几个内置的8.9删不掉,低版本貌似可以.或者用logstash删除
- drop_fields:
fields: ["log","host","input","agent","ecs","host"]
#把日志的时间当成es的时间
- date:
field: log.time # 日志里的时间字段,
formats:
- "yyyy-MM-dd HH:mm:ss" #时间字段的格式
timezone: Asia/Shanghai
target_field: "@timestamp" #要替换的字段,或者可以新增

# 指定索引的分区数
setup.template.settings:
index.number_of_shards: 3
# 输出到指定ES的配置
output.elasticsearch:
hosts: ["localhost:9200"]
index: "emps-ad-log-%{+yyyy.MM.dd}"
setup.template.name: "emps-ad-log"
setup.template.pattern: "emps-ad-log-*"

logstash的简单配置

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
input {
file {
path => [ "/home/ubuntu/php/webman/runtime/logs/ad-*.log" ]
#从头开始读,sincedb_path 文件存在时,会从记录的开始读
start_position => "beginning"
#不记录读取文件的位置,测试时候用
sincedb_path => "/dev/null"
}
}

filter {
json {
source => "message"
}

mutate {
remove_field => ["event",'file','log', "path", "host", "@version"]
}
#把日志时间作为es的时间
date {
match =>["time","yyyy-MM-dd HH:mm:ss"] #把日志的time解析成对应的格式
timezone => "Asia/Shanghai"
}
}


output {
#stdout {
# codec => rubydebug
#}
elasticsearch {
hosts => ["localhost:9200"] # Elasticsearch 服务器的地址和端口
index => "your_custom_index" # 自定义索引名称,替换为你想要的索引名
template_name => "your_custom_template"
#template_overwrite => true
template_pattern => "your_pattern*" # 指定匹配索引名称的模式
}
}

es,可以选择自己想要的版本

1
docker run --name elasticsearch -p 9200:9200 -p 9300:9300 -e "discovery.type=single-node" -e ES_JAVA_OPTS="-Xms512m -Xmx512m" -d elasticsearch:7.16.2

kibana

1
2
3
4
5
6
7
8
docker run --name kibana -e ELASTICSEARCH_HOSTS=http://192.168.252.128:9200 -p 5601:5601 -d kibana:7.16.2
或者
docker run -d --name kibana -p 5601:5601 \
-e ELASTICSEARCH_HOSTS=http://192.168.252.128:9200 \ #Es Url
-e ELASTICSEARCH_USERNAME=root \ #Es 账号,Es不开启认证可不设置
-e ELASTICSEARCH_PASSWORD=123456 \ #Es 密码 ,Es不开启认证可不设置
-e I18N_LOCALE=zh-CN \ #汉化
kibana:7.16.2

修改kibana的配置

1
docker exec -it kibana  /bin/sh

修改kibana.yml,然后保存退出::wq

1
2
3
4
5
6
7
server.name: kibana
server.host: "0"
#注意这里的ip不能是localhost,是本地的ip地址
elasticsearch.hosts: [ "http://192.168.252.128:9200" ]
xpack.monitoring.ui.container.elasticsearch.enabled: true
#设置kibana中文显示
i18n.locale: zh-CN

访问 http://192.168.1.1:5601http://192.168.1.1:9200

安装

docker

1
docker run --name clickhouse-server --ulimit nofile=262144:262144 --volume=$HOME/clickhouse:/var/lib/clickhouse -p 8123:8123 -p 9000:9000 -p 9004:9004 clickhouse/clickhouse-server

apt

1
sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv 8919F6BD2B48D754

向 /etc/apt/sources.list.d/ 目录添加 ClickHouse 存储库:

1
echo "deb https://packages.clickhouse.com/deb stable main" | sudo tee /etc/apt/sources.list.d/clickhouse.list

更新 apt 包索引:

1
sudo apt-get update

安装 ClickHouse 服务器和客户端:

1
sudo apt-get install -y clickhouse-server clickhouse-client

启动 ClickHouse 服务:

1
sudo service clickhouse-server start

连接到 ClickHouse 服务器:

1
clickhouse-client

apt安装的中间会让你输入密码。下面是如何修改密码

1
echo -n 密码 | openssl dgst -sha256

修改对应的xml文件,apt的在/etc/clickhouse-server/users.d/。docker的在刚才的$HOME/clickhouse

1
2
3
4
5
6
7
8
9
<clickhouse>
<users>
<default>
<password remove='1' />
#### 修改这个
<password_sha256_hex>86250f09bcf44ec7efb5864e12201a8e63f04e9d377f6a66470e2604325523c7</password_sha256_hex>
</default>
</users>
</clickhouse>

使用默认账号,登陆。PS:docker需要进入到容器内 docker exec -it

1
2
clickhouse-client 
#输入密码

剩下的基本跟mysql一样了

建库

1
CREATE DATABASE IF NOT EXISTS my_database;

显示所有库 show database;

使用某个库 use my_database;

建表略有不同,引擎常用的是MergeTree,ORDER BY是定义主键

注意,不支持主键自增,需要自己维护主键,或者使用uuid。例如 id UUID DEFAULT generateUUIDv4(),

partition by (id) 分区,可选

PRIMARY KEY (id) 主键,可选

ORDER BY 必选

1
2
3
4
5
6
7
8
9
10
11
CREATE TABLE my_database.my_table
(
`id` UInt32,
`name` String,
`timestamp` DateTime,
`value` Float32
)
ENGINE = MergeTree()
partition by (id)
PRIMARY KEY (id)
ORDER BY id;

插入数据,插入多行数据

1
2
INSERT INTO my_database.my_table (id, name, timestamp, value) VALUES (1, 'John Doe', '2021-01-01 00:00:00', 1.0);
INSERT INTO my_database.my_table (id, name, timestamp, value) VALUES (2, 'Jane Doe', '2021-01-02 00:00:00', 2.0), (3, 'Mike Smith', '2021-01-03 00:00:00', 3.0);

查询数据,查询特定列,条件查询,范围查询,排序查询结果,限制查询结果数量

1
2
3
4
5
6
SELECT * FROM my_database.my_table;
SELECT name, value FROM my_database.my_table;
SELECT * FROM my_database.my_table WHERE id = 1;
SELECT * FROM my_database.my_table WHERE timestamp >= '2021-01-01 00:00:00' AND timestamp <= '2021-01-31 23:59:59';
SELECT * FROM my_database.my_table ORDER BY timestamp DESC;
SELECT * FROM my_database.my_table LIMIT 10;

更新数据,ClickHouse 支持 ALTER TABLE 来修改表结构,例如添加或删除列,但不支持传统意义上的 UPDATE 语句来修改现有数据。需要使用 ALTER TABLE。

1
ALTER TABLE my_database.my_table UPDATE name = 'new_value' WHERE id = 2;

删除数据

1
2
3
DELETE FROM my_database.my_table WHERE id = 1

ALTER TABLE my_database.my_table DELETE WHERE id = 1;

使用python操作

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
from clickhouse_driver import Client

# 连接到ClickHouse服务器
client = Client(host='127.0.0.1', user='default', password='123456')

# 创建数据库
#client.execute('CREATE DATABASE IF NOT EXISTS test_db')

# 使用特定数据库
client.execute('USE my_database')

# 创建表
#client.execute("CREATE TABLE my_table(`id` UInt32,`name` String,`timestamp` DateTime,`value` Float32)ENGINE = MergeTree() ORDER BY id;")

# 插入数据
#client.execute("INSERT INTO my_database.my_table (id, name, timestamp, value) VALUES (2, 'Jane Doe', '2021-01-02 00:00:00', 2.0), (3, 'Mike Smith', '2021-01-03 00:00:00', 3.0);")

# 查询数据
result = client.execute('SELECT * FROM my_table')
for row in result:
print(row)

# 关闭客户端连接
client.disconnect()

hyperf框架的orm其实就是基于laravel改造的。会laravel就会hyperf,只不过目前为止hyperf的文档都没有填充相关的。

生成迁移文件,这点文档有,具体可以参考文档 https://hyperf.wiki/3.1/#/zh-cn/db/migration

1
php bin/hyperf.php gen:migration create_users_table

修改migrations文件夹下的对应文件(驼峰命名修改了create_users_table),为了测试,数据库只有2个字段

1
2
3
4
5
6
7
public function up(): void
{
Schema::create('users', function (Blueprint $table) {
$table->bigIncrements('id');
$table->string('name');
});
}

开始迁移

1
php bin/hyperf.php migrate

迁移+填充,得有填充文件

1
php bin/hyperf.php migrate --seed

迁移单个

1
php bin/hyperf.php migrate --path=migrations/xx.php

生成填充文件。PS:这点详细的可以参考laravel的文档。

1
php bin/hyperf.php gen:seeder UserSeeder

修改seeders文件夹下的对应文件,如果有表关系映射,跟laravel的写法一样

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
<?php

declare(strict_types=1);

use Hyperf\Database\Seeders\Seeder;
use Hyperf\DbConnection\Db;

class UserSeeder extends Seeder
{
public function run()
{
DB::table('users')->insert([
['name' => "hello1"],
['name' => "hello2"]
]);
}
}

执行填充,单个填充跟laravel有区别,要指定路径+文件名

1
2
3
4
 //全部填充
php bin/hyperf.php db:seed
//根据绝对路径进行单个填充
php bin/hyperf.php db:seed --path=seeder/user_seeder.php