使用Vagrant + VirtualBox虚拟机快速搭建TiDB v5.4实验环境

网友投稿 485 2024-03-05



实例环境配置信息

硬件信息: Intel i7(8c) + 16G 内存 + 1T ***

使用Vagrant + VirtualBox虚拟机快速搭建TiDB v5.4实验环境

软件:*** VM Virtual Box 6.1.26 + Vagrant 2.2.16

ISO:CentOS-7.9-x86_64-DVD-2009

TiDB版本:TiDB V5.4

虚拟机VM数量:5个

各个VM配置:Cpu:1c , Memory:2G 硬盘50G

各个虚拟机节点信息:

组件虚拟机名称机器名称IP地址数量pdtidb-pdtidb-pd192.168.56.1601altermanagertidb-pdtidb-pd192.168.56.160prometheustidb-pdtidb-pd192.168.56.160grafanatidb-pdtidb-pd192.168.56.160tidb-servertidb-servertidb-tidb192.168.56.1611tikv1tidb-tikv1tidb-tikv1192.168.56.1621tikv2tidb-tikv2tidb-tikv2192.168.56.1631tiflashtidb-tiflashtidb-tiflash192.168.56.1641

各组件网络端口配置要求

组件默认端口说明TiDB4000应用及 DBA 工具访问通信端口TiDB10080TiDB 状态信息上报通信端口TiKV20160TiKV 通信端口TiKV20180TiKV 状态信息上报通信端口PD2379提供 TiDB 和 PD 通信端口PD2380PD 集群节点间通信端口TiFlash9000TiFlash TCP 服务端口TiFlash8123TiFlash HTTP 服务端口TiFlash3930TiFlash RAFT 服务和 Coprocessor 服务端口TiFlash20170TiFlash Proxy 服务端口TiFlash20292Prometheus 拉取 TiFlash Proxy metrics 端口TiFlash8234Prometheus 拉取 TiFlash metrics 端口Pump8250Pump 通信端口Drainer8249Drainer 通信端口CDC8300CDC 通信接口Prometheus9090Prometheus 服务通信端口Node_exporter9100TiDB 集群每个节点的系统信息上报通信端口Blackbox_exporter9115Blackbox_exporter 通信端口,用于 TiDB 集群端口监控Grafana3000Web 监控服务对外服务和客户端(浏览器)访问端口Alertmanager9093告警 web 服务端口Alertmanager9094告警通信端口

Windows 10 下安装VirtualBox和Vagrant

软件***

*** VM VirtualBox下载网址:https://www.virtualbox.org/wiki/Downloads

Vagrant下载网址:https://www.vagrantup.com/downloads

Vagrant Box文件地址:

安装VritualBox *** VM

下载安装文件

VirtualBox 是一款开源的虚拟机软件,和VMWare是同类型的软件,用于在当前的电脑上创建虚拟机。

VirtualBox 6.1.34 *** https://download.virtualbox.org/virtualbox/6.1.34/VirtualBox-6.1.34a-150636-Win.exe

VirtualBox 6.1.34 *** VM VirtualBox 扩展包*** https://download.virtualbox.org/virtualbox/6.1.34/***_VM_VirtualBox_Extension_Pack-6.1.34.vbox-extpack

安装VirtualBox

双击下载好的VirtualBox-6.1.34a-150636-Win.exe文件进行安装,

点击“下一步”

设置安装位置,点击“下一步”

点击“下一步”

点击”是“

点击”安装"

点击“完成”。

安装过程非常简单,根据提示点击一下就完成对VirtualBox的安装。

安装VirtualBox 扩展包

双击下载的“***_VM_VirtualBox_Extension_Pack-6.1.34.vbox-extpack” 扩展包文件,根据提示进行安装。

修改VirtualBox 配置信息

修改虚拟机默认存放路径

点击菜单“管理”-->“全局设定” 修改 "默认虚拟电脑位置:" 的值为 g:\ovm_machine

添加网卡管理

菜单“管理”-->“主机网络管理器”,点击“创建”

安装Vagrant

Vagrant 2.2.19 Windows版本*** https://releases.hashicorp.com/vagrant/2.2.19/vagrant_2.2.19_x86_64.msi

双击“vagrant_2.2.19_x86_64.msi"进行安装

点击”Next“

点选“复选框”,点击”Next”

设置安装路径,点击”Next“

点击”Install"。

点击“Finish”完成安装。

Vagrant设置Path环境变量

点击“此电脑”右键选“属性”,点“高级系统设置”,

在调出窗口中点击“高级”标签栏,点击“环境变量”

选择系统变量的“Path”,点击“编辑”,新增“G:\HashiCorp\Vagrant\bin”变量值。

查看Vagrant安装版本

打开cmd窗口,输入vagrant -v

vagrant 使用

vagrant创建虚拟机

查找虚拟镜像

在线查找需要的box,官方网址:https://app.vagrantup.com/boxes/search 搜索centos7虚拟机box。

在线安装

#PS G:\HashiCorp\vagrant_vbox_data\centos7_test> pwd agrant init generic/centos7 A `Vagrantfile` has been placed in this directory. You are now ready to `vagrant up` your first virtual environment! Please read the comments in the Vagrantfile as well as documentation on

备注: 使用vagrant创建虚拟机后,默认创建了vagrant用户,密码是vagrant。 root用户密码也是vagrant。

vagrant 命令

描述命令描述命令在初始化完的文件夹内启动虚拟机vagrant up查找虚拟机的运行状态vagrant statusssh登录启动的虚拟机vagrant ssh挂起启动的虚拟机vagrant suspend唤醒虚拟机vagrant resume重启 虚拟机vagrant reload关闭虚拟机vagrant halt删除当前虚拟机vagrant destroy在终端里对开发环境进行打包vagrant package修改文件重启(相当于先 halt,再 up)vagrant reload

box管理命令

描述命令描述命令查看本地box列表vagrant box list添加box到列表vagrant box add name url从box列表移除vagrant box remove name输出用于ssh连接的一些信息vagrant ssh-config

安装TiDB过程使用shell文件

## 文件存放路径

Vagrantfile 配置文件及shell文件存放路径

  Length Name ----                 -------------         ------ ---- d-----       2022/06/16     17:24               .vagrant d-----       2022/06/16     17:12               shared_scripts │ Vagrantfile │ └─shared_scripts       root_setup.sh       setup.sh       shell_init_os.sh       tiup_deploy.sh

备注:

shared_scripts 目录存放虚拟机初始化的系统配置脚本。

setup.sh:Vagrantfile 调用shell文件进行系统配置,此脚本内容是执行root_setup.sh

root_setup.sh:设置主机名与sshd配置,调用shell_init_os.sh 脚本

shell_init_os.sh:对安装tidb前进行操作系统进行配置。

tiup_deploy.sh:安装tiup工具软件

Vagrantfile 文件是vagrant 的虚拟机配置文件

setup.sh 文件内容

#/bin/bash sudo bash -c sh /vagrant_scripts/root_setup.sh

root_setup.sh文件内容

#/bin/bash if [ -f /vagrant_config/install.env ]; then . /vagrant_config/install.env fi #设置代理 echo "******************************************************************************" echo "set http proxy." `date` echo "******************************************************************************" if [ "$HTTP_PROXY" != "" ]; then echo "http_proxy=http://${HTTP_PROXY}" >> /etc/profile echo "https_proxy=http://${HTTP_PROXY}" >> /etc/profile echo "export http_proxy https_proxy" >> /etc/profile source /etc/profile fi #安装package yum install -y wget net-tools sshpass #设置PS1 export LS_COLORS=no=00:fi=00:di=01;33;40:ln=01;36;40: export PS1="\[\033[01;35m\][\[\033[00m\]\[\033[01;32m\]\u@\h\[\033[00m\] \[\033[01;34m\]\w\[\033[00m\]\[\033[01;35m\]]\[\033[00m\]\$ " echo "alias l=ls -lrtha" >>/root/.bashrc #echo "alias vi=vim" >>/root/.bashrc source /root/.bashrc #修改root密码 if [ "$ROOT_PASSWORD" == "" ]; then ROOT_PASSWORD="rootpasswd" fi echo "******************************************************************************" echo "Set root password and change ownership." `date` echo "******************************************************************************" echo -e "${ROOT_PASSWORD}\n${ROOT_PASSWORD}" | passwd #设置时区 timedatectl set-timezone Asia/Shanghai #关闭firewalld systemctl stop firewalld.service systemctl disable firewalld.service #设置selinux sed -i /etc/selinux/config setenforce 0 #设置sshd_config echo "******************************************************************************" echo "Set sshd service and disable firewalld service." `date` echo "******************************************************************************" sed -i /etc/ssh/sshd_config sed -i /etc/ssh/sshd_config sed -i /etc/ssh/sshd_config sed -i /StrictHostKeyChecking/s/^#//; /StrictHostKeyChecking/s/ask/no/ /etc/ssh/ssh_config systemctl restart sshd.service #设置主机名 if [ "$PUBLIC_SUBNET" != "" ]; then IP_NET=`echo $PUBLIC_SUBNET |cut -d"." -f1,2,3` IPADDR=`ipaddr|grep $IP_NET |awk -F"/" {print $1}|awk -F" " {print $2}` PRIF=`grep $IPADDR /vagrant_config/install.env |awk -F"_" {print $1}` if [ "$PRIF" != "" ]; then HOSTNAME=`grep $PRIF"_HOSTNAME" /vagrant_config/install.env |awk -F"=" {print $2}` hostnamectl set-hostname $HOSTNAME #设置/etc/hosts CNT=`grep $IPADDR /etc/hosts|wc -l ` if [ "$CNT" == "0" ]; then echo "$IPADDR $HOSTNAME">> /etc/hosts fi fi fi #初化始系统配置信息 if [ -f /vagrant_scripts/shell_init_os.sh ]; then sh /vagrant_scripts/shell_init_os.sh fi

shell_init_os.sh文件内容

#/bin/bash #1.检测及关闭系统 swap echo "vm.swappiness = 0">> /etc/sysctl.conf swapoff -a && swapon -a sysctl -p #2.检测及关闭目标部署机器的防火墙 #关闭firewalld systemctl stop firewalld.service systemctl disable firewalld.service #设置selinux sed -i /etc/selinux/config setenforce 0 #3.检测及安装 NTP 服务 yum -y install numactl yum -y install ntp ntpdate #设置NTPsystemctl status ntpd.service systemctl start ntpd.service systemctlenable ntpd.service ntpstat #4.检查和配置操作系统优化参数 #关闭THP和NUMA RESULT=`grep "GRUB_CMDLINE_LINUX" /etc/default/grub |grep "transparent_hugepage"` if [ "$RESULT" == "" ]; then \cp /etc/default/grub /etc/default/grub.baksed -i s#quiet#quiet transparent_hugepage=never numa=off#g /etc/default/grub grub2-mkconfig -o /boot/grub2/grub.cfg if [ -f /boot/efi/EFI/redhat/grub.cfg ]; then grub2-mkconfig -o /boot/efi/EFI/redhat/grub.cfg fi fi #关闭透明大页 if [ -d /sys/kernel/mm/transparent_hugepage ]; then thp_path=/sys/kernel/mm/transparent_hugepageelif [ -d /sys/kernel/mm/redhat_transparent_hugepage ]; then

版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。

上一篇:使用TiOperator部署TiDB集群的步骤
下一篇:修复Etcd API未授权访问漏洞的策略
相关文章