数据库

数据库

etcd

# 创建快照备份
export ETCDCTL_API=3
etcdctl --endpoints localhost:2379 snapshot save snapshot.db \
          --cacert=/etc/kubernetes/pki/etcd/ca.crt  \
          --cert=/etc/kubernetes/pki/etcd/server.crt \
          --key=/etc/kubernetes/pki/etcd/server.key

# 快照恢复命令
etcdctl snapshot restore snapshot.db --name m3 --data-dir=/home/etcd_data

memached

# run
memcached -d -p 39001 -m 30 -P memcached.pid

# 清空缓存
echo flush_all | nc 10.2.1.5 21101

# show
echo stats | nc 10.2.1.5 21101
echo stats | nc 10.2.1.5 21101 | grep curr_connections

# 查看 lru 淘汰的key数量
echo stats | nc 10.2.1.5 21101 | grep evictions

# get
echo -ne "get key_name\r\n" | nc 10.2.1.5 21101

# del
echo "delete jtsysconfig_traffic_control_config_12028" | nc 10.2.1.5 21101

# set
printf "set key008 0 5 10\r\noldboy0987\r\n"|nc 10.2.1.5 11211

set wait 0 180 9
chenwx716

consul


consul acl set-agent-token default 0bc6bc46-f25e-4262-b2d9-ffbe1d96be6f

consul agent -dev

consul agent -config-dir config

consul agent -server -bootstrap -bind=127.0.0.1 -client=127.0.0.1 -node=redis1 \
    -config-dir conf -enable-script-checks -data-dir=data -ui -node=127.0.0.1


http://127.0.0.1:8500

consul.exe agent -server -bootstrap-expect 1 \
    -data-dir "D://app//consul_1.11.2//data" \
    -advertise 127.0.0.1 -ui -node=node1 \
    -bind 127.0.0.1 -client 0.0.0.0 -rejoin -config-dir "D://app//consul_1.11.2//config"

es


curl 'http://localhost:9200/_cat/indices?v'

# 获取全部数据,默认只显示10条
curl -XGET 'http://localhost:9200/index-name/doc-type/_search?pretty'

# 根据ID查询数据
curl -XGET 'http://localhost:9200/index-name/doc-type/id?pretty'

# 查询条件,参数 q=
curl -XGET 'http://localhost:9200/megacorp/employee/_search?q=name:Smith'

curl -XGET 'http://localhost:29200/nginx_access/_search?q=x_forwarded_for:117.136.38.182&pretty'

# del index
curl -X DELETE "http://localhost:19200/indexName?pretty"'&timeout=5m'

# 时间范围数量统计
curl -XGET 'http://10.27.10.30:29200/cd-nginx-2020.11.01/_count?pretty' \
-H 'content-type: application/json' -d '
{
  "query": {
    "range":{
      "@timestamp":{
        "gte": "2020-11-01 10:00:00",
        "lte": "2020-11-01 11:00:00",
        "format": "yyyy-MM-dd HH:mm:ss||yyyy-MM-dd",
        "time_zone": "+08:00"
      }
    }
  }
}'

kibana

常用查询语句

# 指定路径+耗时范围
request_uri:"/services/LoginForApp" AND request_time:[0.500 TO 9.000]

redis

慢查询


slowlog get                                     # 查询慢查询记录

# 配置
config set slowlog-log-slower-than 1000         # 1ms
config set slowlog-max-len 500
CONFIG GET slowlog-*                            # 获取配置

客户端

# 连接集群
redis-cli --cluster 10.27.10.1 21101
redis-cli --cluster -p 21101
redis-cli -c -h 10.27.10.1 -p 11102
redis-cli -c -h 192.168.0.1 -p 6389 -a password

数据管理

FLUSHALL                # 清空所有库
FLUSHDB                 # 清空单个库 - 当前库

DBSIZE                  # show key number
TTL key                 # 获取key的剩余过期时间s

监控

redis-cli MONITOR

MONITOR
INFO
STATS

CLUSTER info
CLIENT LIST
cluster nodes

集群管理

# 添加从节点
./redis-cli --cluster add-node <新节点> <连接的主节点> --cluster-slave --cluster-master-id <主节点ID>

./redis-cli --cluster add-node 10.1.99.91:16483 10.1.99.70:16379 --cluster-slave --cluster-master-id feb7b92d1a183b14e5528c667e58592d8131057b

sqlite

.databases              # show current db
.tables                 # show all tables
.indices [table]        # 获取表的索引列
.schema [table]         # 显示表结构 DDL

# 非交互查询
sqlite3 test.db "sleect * from t_file"
最后更新于