BlueXIII's Blog

热爱技术,持续学习

0%

参考文档

常用操作

1
2
3
4
5
6
7
./mc config host add minio http://localhost:9000 admin password --api s3v4
./mc list

./mc policy get minio/images

./mc policy set public minio/images
./mc policy set-json ./policy.json minio/images

自定义policy.json

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
{
"Version": "2012-10-17",
"Statement": [
{
"Action": [
"s3:GetObject"
],
"Effect": "Allow",
"Principal": {
"AWS": [
"*"
]
},
"Resource": [
"arn:aws:s3:::images/*"
],
"Sid": ""
}
]
}

资料

安装Laravel命令行

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
# 安装laravel安装器
composer global require laravel/installer
laravel --version
Laravel Installer 4.2.9

# 查看composer配置路径
composer global about
/Users/bluexiii/.composer/vendor/bin

# 将composer的bin目录加入PATH
vi ~/.zshrc
export PATH="/Users/bluexiii/.composer/vendor/bin:$PATH"

# 新建laravel工程
laravel new blog

# 测试启动
php artisan serve

工程初始化

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
# 编辑.env
cp .env.example .env
vi .env
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=agric
DB_USERNAME=agric
DB_PASSWORD=sw123

MONGO_HOST=127.0.0.1
MONGO_PORT=27017
MONGO_DATABASE=agric
MONGO_USERNAME=agric
MONGO_PASSWORD=sw123

# 在.env中生成KEY
php artisan key:generate

# 建表
php artisan migrate

# 导入基础数据
php artisan db:seed

# 启动Server
php artisan serve

Artisan命令行用法

1
2
3
4
5
6
7
8
9
10
# 查看命令列表
php artisan list

# 查看帮助
php artisan help migrate

# 其它
php artisan config:cache # 生成配置缓存(开发环境会造成.env修改无效)
php artisan config:clear # 取消配置缓存
php artisan passport:keys # 生成Oauth密钥对

日志打印SQL

1
2
3
4
5
6
7
8
9
10
public function boot() {
Schema::defaultStringLength(191);
DB::listen(function($query) {
Log::info(
$query->sql,
$query->bindings,
$query->time
);
});
}

本地仓库

vi composer.json

1
2
3
4
5
6
7
"require": {
"harris/sw_common": "dev-master",
},
"repositories": [{
"type": "path",
"url": "/Users/bluexiii/Documents/code/evayinfo/idatasky/harris-sw_common"
}]

参考文档

Github

参数

  • -i 索引名
  • -q query dsl
  • -a 认证信息 格式:user: password
  • -u esurl 格式: http://ip:9200
  • -o 命名
  • -r qurey formated

示例

1
2
3
4
5
6
7
8
9
# 需要python2.7环境
conda create --name py27 python=2.7
conda activate py27

# 安装es2csv
pip install es2csv

# 导出
es2csv -i policies_hydrabot -u 10.20.41.30:9200 -o dump.csv -r -q '{"_source":["title","url","collectTime","createTime"],"query": {"range": {"collectTime": {"gt": "2021-10-01 00:00:00"}}}}'

参考文档

常用操作

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
40
41
42
43
44
45
46
47
48
49
50
# 查看版本
composer --version

# 升级到最新版本
composer self-update

# 版本降级为1.x最新
composer self-update --1

# 版本降级为1.X指定版本
composer self-update 1.10.20

# 版本回滚到2.X
composer self-update --rollback

# 配置阿里云镜像源
composer config -g repo.packagist composer https://mirrors.aliyun.com/composer/
composer config --unset repos.packagist

# 调试参数
-vvv

# 安装依赖包(composer.json配置)
composer install

# 安装依赖包(忽略系统依赖)
composer install --ignore-platform-reqs

# 直接安装依赖
composer require monolog/monolog

# 直接删除依赖
composer remove monolog/monolog

# 忽略内存限制
COMPOSER_MEMORY_LIMIT=-1 composer require jenssegers/mongodb

# 更新依赖
composer update

# 清理缓存
rm -rv vendor
rm composer.lock
composer clearcache

# 其它
composer search monolog # 搜索
composer show 列出所有已经安装的包
composer dump-autoload
php artisan optimize

杂项

  • Laravel6.X项目,应使用1.X版本compser,避免install时报错

composer install 报错

1
2
3
4
> @php artisan package:discover
In PackageManifest.php line 122:
Undefined index: name
Script @php artisan package:discover handling the post-autoload-dump event returned with error code 1

https://exerror.com/packagemanifest-php-line-122-undefined-index-name/

115行左右

1
2
3
# $packages = json_decode($this->files->get($path), true);
$installed = json_decode($this->files->get($path), true);
$packages = $installed['packages'] ?? $installed;

Crontab脚本

1
2
3
crontab -e

*/5 * * * * . /etc/profile; . ~/.bash_profile; isfound=$(ps -ef | grep "qixin-entrance-v2021.07.13.jar" | grep -v "grep"); if [ -z "$isfound" ]; then echo "$(date): restart qixin-entrance-v2021.07.13.jar...">>/var/log/restart.log && cd /opt/soft/enterprisedata && ./startup.sh; fi

github

过程

1
2
3
4
5
6
7
8
9
10
11
12
13
# 安装acme.sh
curl https://get.acme.sh | sh -s email=foobar@163.com

# 生成证书
export Ali_Key="foo"
export Ali_Secret="bar"
acme.sh --issue --dns dns_ali -d foobar.com -d www.foobar.com

# 安装证书
acme.sh --install-cert -d foobar.com \
--cert-file /etc/grafana/foobar.com.cer \
--key-file /etc/grafana/foobar.com.key \
--reloadcmd "systemctl restart grafana-server"

参考文档

安装

1
2
wget https://dl.influxdata.com/telegraf/releases/telegraf-1.20.2-1.x86_64.rpm
sudo yum localinstall telegraf-1.20.2-1.x86_64.rpm

debug

1
2
telegraf --debug
telegraf --test

log

logfile = “/var/log/telegraf/telegraf.log”

net_response

https://github.com/influxdata/telegraf/tree/master/plugins/inputs/net_response

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
[[inputs.net_response]]
protocol = "tcp"
address = "10.194.99.9:8050"

[[inputs.net_response]]
protocol = "tcp"
address = "10.194.99.10:8050"

[[inputs.net_response]]
protocol = "tcp"
address = "10.194.99.11:8050"

[[inputs.net_response]]
protocol = "tcp"
address = "10.194.99.12:8050"

[[inputs.net_response]]
protocol = "tcp"
address = "10.194.99.13:8050"

[[inputs.net_response]]
protocol = "tcp"
address = "10.194.99.14:8050"

procstat

https://github.com/influxdata/telegraf/tree/master/plugins/inputs/procstat

1
2
3
4
5
6
7
8
9
10
11
[[inputs.procstat]]
exe = "mysqld"
process_name = "10.194.99.2-mysqld"

[[inputs.procstat]]
exe = "mongod"
process_name = "10.194.99.3-mongod"

[[inputs.procstat]]
pattern = "splash"
process_name = "10.194.99.4-minio"

docker

https://github.com/influxdata/telegraf/tree/master/plugins/inputs/docker

1
[[inputs.docker]]
1
usermod -aG docker telegraf

haproxy

https://github.com/influxdata/telegraf/tree/master/plugins/inputs/haproxy
https://cbonte.github.io/haproxy-dconv/1.8/management.html#9.1

1
2
[[inputs.haproxy]]
servers = ["http://10.194.99.9:8036/","http://10.194.99.10:8036/","http://10.194.99.11:8036/","http://10.194.99.12:8036/","http://10.194.99.13:8036/","http://10.194.99.14:8036/"]

邮件配置

1
2
3
4
5
6
7
8
9
10
11
[smtp]
enabled = true
host = smtp.163.com:25
user = youraccount@163.com
password = yourpass
skip_verify = true
from_address = youraccount@163.com
from_name = 运维告警

[emails]
content_types = text/plain

邮件模板

/usr/share/grafana/public/emails/alert_notification.txt

1
2
3
4
5
6
7
8
9
10
11
{{if ne .State "ok" }}异常列表:{{range .EvalMatches}}
{{.Metric}} : {{.Value}}
{{end}}{{end}}
{{.Message}}
{{if ne .Error "" }}
报错信息:{{.Error}}
{{end}}
----------

如有问题烦请联系,谢谢。
Best Regards.

告警参数配置

  • 客户端上报间隔 10s (每10秒上报一个点)
  • 告警评估间隔 10s (越短越好,但太短影响Server性能)
  • 告警评估持续时长 1m (当持续1分钟后,由pending转为alert并发邮件)
  • 告警采样时间段 5m (逆推300个点)
  • 告警采样域值 0.93 (允许丢失20个点)

脚本

1
2
3
4
ps -A -ostat,ppid | grep -e '^[Zz]' | awk '{print }' | xargs kill -HUP > /dev/null 2>&1
ps -ef|grep chromedriver|grep -v grep|awk '{print $2}'|xargs kill -9
ps -ef|grep "/usr/bin/google-chrome"|grep -v grep|awk '{print $2}'|xargs kill -9
ps -ef|grep /usr/local/bin/chromedriver | grep -e grep

参考文档

安装过程

1
2
3
4
5
6
7
8
9
10
11
12
13
14
# npm切换至低版本
npm install -g n
sudo n 10.14.1

# 安装gitbook-cli
npm install -g gitbook-cli

# 查看版本号并自动安装最新版本gitbook
gitbook -V

# 安装低版本的gitbook(可选)
gitbook help
gitbook fetch 2.6.7

常用命令

1
2
3
4
5
6
7
8
9
gitbook -V      查看版本号
gitbook init 初始化
gitbook serve 预览
gitbook build 生成
gitbook build --gitbook=2.6.7 生成时指定gitbook的版本, 本地没有会先下载
gitbook uninstall 2.6.7 卸载指定版本号的gitbook
gitbook fetch [version] 获取[版本]下载并安装<版本>
gitbook --help 显示帮助文档
gitbook ls-remote 列出NPM上的可用版本

错误修复

1
2
3
4
5
6
7
8
9
10
11
# 错误
Error loading version latest: Error: Cannot find module 'internal/util/types'

# 修复
I updated npm to the stable version and reinstalled gitbook and it worked
npm cache clean -f
npm install n stable -g
npm cache clean -f
rm -rf ~/.gitbook/*
npm install gitbook-cli -g
gitbook init

本地HTML不能跳转问题

1
2
3
vi theme.js
if(m)for(n.handler&&
将if(m)改成if(false)