tidb初体验
安装
docker-compose:
https://github.com/pingcap/tidb-docker-compose
pd tikv tidb各单个节点,单个副本,限制内存,cpu等,防止给服务器搞宕机
先使用docker快速安装一个tidb体验一下子
version: '2.1' services: pd0: image: pingcap/pd:latest ports: - "2379:2379" volumes: - ./config/pd.toml:/pd.toml:ro - ./data:/data - ./logs:/logs command: - --name=pd0 - --client-urls=http://0.0.0.0:2379 - --peer-urls=http://0.0.0.0:2380 - --advertise-client-urls=http://pd0:2379 - --advertise-peer-urls=http://pd0:2380 - --initial-cluster=pd0=http://pd0:2380 - --data-dir=/data/pd0 - --config=/pd.toml - --log-file=/logs/pd0.log restart: on-failure mem_limit: 2g cpu_quota: 50000 cpu_period: 20ms # networks: # - default # extra_hosts: # - "prometheus-dev.xx.com:192.168.100.96" tikv0: image: pingcap/tikv:latest ports: - "20180:20180" - "20160:20160" volumes: - ./config/tikv.toml:/tikv.toml:ro - ./data:/data - ./logs:/logs command: - --addr=0.0.0.0:20160 - --advertise-addr=tikv0:20160 - --data-dir=/data/tikv0 - --status-addr=0.0.0.0:20180 - --pd=pd0:2379 - --config=/tikv.toml - --log-file=/logs/tikv0.log depends_on: - "pd0" restart: on-failure mem_limit: 2g cpu_quota: 50000 cpu_period: 20ms # networks: # - default # extra_hosts: # - "prometheus-dev.xx.com:192.168.100.96" tidb: image: pingcap/tidb:latest ports: - "4000:4000" - "10080:10080" volumes: - ./config/tidb.toml:/tidb.toml:ro - ./logs:/logs command: - --store=tikv - --path=pd0:2379 - --config=/tidb.toml - --log-slow-query=/logs/tidb_slow_query.log - --log-file=/logs/tidb.log - --advertise-address=tidb depends_on: - "tikv0" restart: on-failure mem_limit: 2g cpu_quota: 50000 cpu_period: 20ms # networks: # - default # extra_hosts: # - "prometheus-dev.xx.com:192.168.100.96" #networks: # default: # external: true # name: gibsdev_default
可以接入已有的prometheus监控
修改配置,限制内存为2g
配置
不要使用默认的配置,里面会有废弃的参数
[root@xuliang config]# cat pd.toml ## [pd-server] metric-storage = "http://prometheus-dev.xx.com" [replication] max-replicas = 1 [schedule] leader-schedule-limit = 4 region-schedule-limit = 2048 replica-schedule-limit = 64 [root@xuliang config]# cat tidb.toml mem-quota-query = 209715200 oom-use-tmp-storage = true oom-action = "cancel" [binlog] enable = true ignore-error = false [log] slow-threshold = 300 [performance] txn-total-size-limit = 204857600 stmt-count-limit = 500000 [root@xuliang config]# cat tikv.toml [raftstore] sync-log = false store-pool-size = 4 [readpool] [readpool.coprocessor] use-unified-pool = true [readpool.storage] use-unified-pool = false [storage] reserve-space = 0 [storage.block-cache] capacity = "2048MB" [root@xuliang config]#
配置主要参数,其他默认,看需要改:
主要参数:副本数,内存,cpu限制等,磁盘。。。
tidb:
txn-total-size-limit = 204857600
tikv:
capacity =
"2048MB" 此参数一定不能大于tikv最大内存,不然会oom
用户管理:
CREATE USER 'benchmark'@'%' IDENTIFIED BY '123456';
GRANT all on gid_test.* to benchmark@'%';
flush privileges;
show grants for 'benchmark';
revoke DROP on gid_test.* from 'benchmark'@'%';