TiDB单节点部署生产环境

部署离线环境TiDB与TiUP组件
准备TiDB离线组件包
将包上传到目标集群中,执行以下命令安装TiDB组件
tar xzvf tidb-community-server-v8.1.1-linux-amd64.tar.gz
sh tidb-community-server-v8.1.1-linux-amd64/local_install.sh
source /root/.profile

which tiup


WXWorkLocalPro_17286293671479.png

vim /etc/ssh/sshd_config
把MaxSessions 改成20

MaxSessions 20
AuthorizedKeysFile      /root/.ssh/id_ed25519(ssh的位置)

service sshd restart
配置初始化参数文件
按下面的配置模板,编辑配置文件,命名为 topo.yaml,其中:
user: "tidb":表示通过 tidb 系统用户(部署会自动创建)来做集群的内部管理,默认使用 22 端口通过 ssh 登录目标机器
replication.enable-placement-rules:设置这个 PD 参数来确保 TiFlash 正常运行
host:设置为本部署主机的 IP
vim /app/topo.yaml

# # Global variables are applied to all deployments and used as the default value of
# # the deployments if a specific deployment value is missing.
global:
 user: "root"
 ssh_port: 22
 deploy_dir: "/tidb-deploy"
 data_dir: "/tidb-data"

# # Monitored variables are applied to all the machines.
monitored:
 node_exporter_port: 9100
 blackbox_exporter_port: 9115

server_configs:
 tidb:
   instance.tidb_slow_log_threshold: 300
 tikv:
   readpool.storage.use-unified-pool: false
   readpool.coprocessor.use-unified-pool: true
 pd:
   replication.enable-placement-rules: true
   replication.location-labels: ["host"]
 tiflash:
   logger.level: "info"

pd_servers:
 - host: 10.0.8.87

tidb_servers:
 - host: 10.0.8.87

tikv_servers:
 - host: 10.0.8.87
   port: 20160
   status_port: 20180
   config:
     server.labels: { host: "logic-host-1" }

 - host: 10.0.8.87
   port: 20161
   status_port: 20181
   config:
     server.labels: { host: "logic-host-2" }

 - host: 10.0.8.87
   port: 20162
   status_port: 20182
   config:
     server.labels: { host: "logic-host-3" }

tiflash_servers:
 - host: 10.0.8.87

monitoring_servers:
 - host: 10.0.8.87

grafana_servers:
 - host: 10.0.8.87

执行集群部署命令:

参数 <cluster-name> 表示设置集群名称
参数 <version> 表示设置集群版本,例如 v8.1.1。可以通过 tiup list tidb 命令来查看当前支持部署的 TiDB 版本
参数 -p 表示在连接目标机器时使用密码登录

tiup cluster deploy tidb-online v8.1.1 /app/topo.yaml --user root -p
按照引导,输入”y”及 root 密码,来完成部署:

Do you want to continue? [y/N]:  y
Input SSH password:

如果报错:


WXWorkLocalPro_17286264035725.png

解决:
配置ssh-keygen
1、ssh-keygen
2、vim /etc/ssh/sshd_config把AuthorizedKeysFile的位置改为ssh-key的位置

AuthorizedKeysFile      /root/.ssh/id_ed25519(ssh的位置)

启动集群

tiup cluster start tidb-online
WXWorkLocalPro_17286254196501.png

确认当前已经部署的集群列表:

tiup cluster list
WXWorkLocalPro_17286254018468.png

执行以下命令查看集群的拓扑结构和状态:

tiup cluster display tidb-online
WXWorkLocalPro_17286254389170.png

安装 MySQL 客户端。

apt-get install mysql-client

访问 TiDB 数据库,密码为空:

mysql -h 10.0.1.1 -P 4000 -u root

访问 TiDB 的 Grafana 监控:

通过 [http://{grafana-ip}:3000](http://{grafana-ip}:3000) 访问集群 Grafana 监控页面,默认用户名和密码均为 `admin`。

访问 TiDB 的 Dashboard:

通过 [http://{pd-ip}:2379/dashboard](http://{pd-ip}:2379/dashboard) 访问集群 [TiDB Dashboard](https://docs.pingcap.com/zh/tidb/stable/dashboard-intro) 监控页面,默认用户名为 `root`,密码为空。

关闭集群

关闭集群操作会按 Alertmanager -> Grafana -> Prometheus -> TiCDC -> Drainer -> TiFlash -> TiDB -> Pump -> TiKV -> PD 的顺序关闭整个 TiDB 集群所有组件(同时也会关闭监控组件):

tiup cluster stop ${cluster-name}

start 命令类似,stop 命令也支持通过 -R-N 参数来只停止部分组件。

例如,下列命令只停止 TiDB 组件:

tiup cluster stop ${cluster-name} -R tidb

下列命令只停止 1.2.3.41.2.3.5 这两台机器上的 TiDB 组件:

tiup cluster stop ${cluster-name} -N 1.2.3.4:4000,1.2.3.5:4000

清除集群数据

此操作会关闭所有服务,并清空其数据目录或/和日志目录,并且无法恢复,需要谨慎操作

清空集群所有服务的数据,但保留日志:

tiup cluster clean ${cluster-name} --data

清空集群所有服务的日志,但保留数据:

tiup cluster clean ${cluster-name} --log

清空集群所有服务的数据和日志:

tiup cluster clean ${cluster-name} --all

清空 Prometheus 以外的所有服务的日志和数据:

tiup cluster clean ${cluster-name} --all --ignore-role prometheus

清空节点 172.16.13.11:9000 以外的所有服务的日志和数据:

tiup cluster clean ${cluster-name} --all --ignore-node 172.16.13.11:9000

清空部署在 172.16.13.12 以外的所有服务的日志和数据:

tiup cluster clean ${cluster-name} --all --ignore-node 172.16.13.12

销毁集群

销毁集群操作会关闭服务,清空数据目录和部署目录,并且无法恢复,需要谨慎操作

tiup cluster destroy ${cluster-name}

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容