#数据库托管

YashanDB支持将某个单节点数据库或者数据库集群托管到指定的集群内。

# 托管注意事项

1.托管过程主要使用yasboot,请先了解该工具各命令选项含义及说明。

# 托管步骤

除特殊说明,以下步骤均在yasboot工具所在的环境上操作,且命令中的路径、用户、密码等需更换为实际值

  1. 终止yasom和yasagent进程。

    如要托管的数据库已属于某个数据库集群,需要先对该集群的运维服务执行停止操作。否则,请直接进行下一步操作。

    本步骤须在数据库的安装包存放路径中(即存放hosts.toml文件的目录)执行,可通过如下命令进入该目录:

    $ cd /home/yashan/install
    

    通过执行如下语句终止yasom和yasgant进程:

    $ ./bin/yasboot process yasom stop -c yashandb -t hosts.toml && yasboot process yasagent stop -c yashandb -t hosts.toml
    stop yasom successfully
    stop agent host0002 successfully
    stop agent host0001 successfully
    

    其中:

    -c, --cluster 集群名称
    -t, --toml  需要主机配置文件如hosts.toml,这里是指部署旧版本时生成的hosts.toml文件
    
  2. 生成主机配置文件。

    通过执行如下命令生成主机配置文件:

    $ ./bin/yasboot package config gen --cluster yashandb -u yashan -p password --ip ip1,ip2,...,ipn --install-path /var/database/yashan
    

    其中:

    -c,--cluster	生成的集群名称,这里可以任意取一个名称
    -u,--username	主机ssh用户名
    -p,--password	主机ssh登录密码
    -N,--no-password   如果用户配置了免密,请使用这个参数替代-p参数
    --ip			部署的ip地址,如果涉及到多个主机,格式为:ip1,ip2,ip3
    --port			主机ssh连接端口
    -i, --install-path	数据库安装路径(HOME目录),这里指定的路径是新版本的home目录,必须要是空目录
    -t, --yas-type		数据库部署的架构类型:
    * SE:单机
    * DE:分布式
    --db             单机db组及节点部署的节点规模,请根据实际主备情况调整此参数
    

    Note

    该命令会生成主机hosts.toml和数据库yashandb.toml两个配置文件,将直接替换/home/yashan/intall目录下原有的hosts.toml及yashandb.toml文件,托管只需要hosts.toml配置文件,yashandb.toml可以忽略。

  3. 部署主机,并将yasom和yasagent初始化。

    可通过执行如下命令进行初始化:

    $ ./bin/yasboot package install -i yashandb-22.2.0.9-linux-x86_64.tar.gz -t hosts.toml
    checking install package...
    install version: yashandb 22.2.0.9
    host0001 100% [====================================================================]    3s
    update host to yasom...
    

    其中:

    -i, --install-pkg  软件包文件本地路径
    -t, --toml 主机配置文件,即hosts.toml
    
  4. 生成托管配置模板文件。

    可通过如下命令生成于目录中生成托管模板文件:

    $ ./bin/yasboot package config join-demo -t SE
    

    其中:

    -t, --type 托管集群的类型,SE表示单机,DE表示分布式
    
  5. 修改托管配置文件。

    如下为托管模板文件各参数描述,请根据实际情况修改模板文件中的参数值:

    cluster = "tt"  			--集群名称
    sys_password = "yasdb_123"  --数据库sys用户的密码
    yas_type = "SE"  			--部署形态
    
    [primary_config]
      manage_ip = "127.0.0.1"  								--主节点ip
      yasdb_home = "/opt/yasom/yashandb/tt"					--主节点的yasdb_home目录
      node_path = "/opt/yasom/yashandb/data/tt/db-1-1"		--主节点的yasdb_data目录
      node_id = "1-1:1"										--主节点的nodeid
    
    [[standby_config]]										--备节点按照主节点的示例修改
      manage_ip = "127.0.0.1"
      yasdb_home = "/opt/yasom/yashandb/tt"
      node_path = "/opt/yasom/yashandb/data/tt/db-1-2"
      node_id = "1-2:1"
    
    [[standby_config]]                    --备节点按照主节点的示例修改,没有就删除
      manage_ip = "127.0.0.1"
      yasdb_home = "/opt/yasom/yashandb/tt"
      node_path = "/opt/yasom/yashandb/data/tt/db-1-3"
      node_id = "1-3:1"
    
  6. 执行托管命令:

    通过执行如下命令进行托管操作:

    $ ./bin/yasboot cluster join -t SE --config join_demo.toml
    

    其中:

    -t, --type 托管集群的类型,SE表示单机,DE表示分布式
    -c, --config 托管配置文件
    

    命令执行结果如下所示:

    the cluster status is as follow:
    |key         |value
    |------------+------
    |clusterName |tp
    |version     |22.2.0.9
    
    the cluster status is as follow:
     hostid   | node_type | nodeid | pid   | instance_status | database_status | database_role | listen_address | data_path
    -------------------------------------------------------------------------------------------------------------------------------------------------
     host0001 | db        | 1-1:1  | 46689 | open            | normal          | primary       | 127.0.0.1:1688   | /home/yashan/yashandb/db-1-1
    ----------+-----------+--------+-------+-----------------+-----------------+---------------+----------------+------------------------------------
    Check success
    Are you sure you to add yasdb tp to yasom[yes/no]: yes
     type | uuid             | name             | hostid | index | status  | return_code | progress | cost
    -------------------------------------------------------------------------------------------------------
     task | e2007922a317a02c | JoinYasdbCluster | -      | tp    | SUCCESS | 0           | 100      | -
    ------+------------------+------------------+--------+-------+---------+-------------+----------+------
    task completed, status: SUCCESS
    
  7. 查看数据库状态。

    通过执行如下语句查看数据库状态:

    $ ./bin/yasboot cluster status -c yashandb -d
     hostid   | node_type | nodeid | pid   | instance_status | database_status | database_role | listen_address | data_path
    -----------------------------------------------------------------------------------------------------------------------------------------
     host0001 | db        | 1-1:1  | 46689 | open            | normal          | primary       | 127.0.0.1:1688   | /home/yashan/yashandb/db-1-1
    ----------+-----------+--------+-------+-----------------+-----------------+---------------+----------------+----------------------------