【TARS】扩容与负载均衡

目录

0.参考链接

1.环境说明

1.1机器

1.2.准备

2.在扩容机器上安装tarsnode启动tarnode使其能与框架通信

3.在主控机web管理平台点击预扩容,扩容,上传安装包

4.确保扩容机被安装成架构能管理到的一个节点并安装

5.发布服务

6.简单的轮询策略的负载均衡测试


0.参考链接

参考链接1

TARSNODE部署-官方提供的文档

TARS框架更新及扩容-官方提供的文档

1.环境说明

1.1机器

框架器:虚拟机A,Centos7,IP:192.168.118.138

扩容机:虚拟机B,Centos7,IP:192.168.118.180

1.2.准备

(1)分别关闭主控机和扩容器防火墙

    systemctl stop firewalld.service 
    systemctl disable firewalld.service

(2)设置主控机和扩容机 SELINUX状态

    vim /etc/sysconfig/selinux
    SELINUX=enforcing 改为 SELINUX=disabled  ,reboot重启生效

 

2.在扩容机器上安装tarsnode启动tarnode使其能与框架通信

将主节点上的tarsnode copy到/usr/local/app/tars/
修改/usr/local/app/tars/tarsnode/conf/tars.tarsnode.config.conf
将localip换成自己的本机ip即可

同时将registry的ip换成TarsFramework框架的ip(可以是多个), 例如:
locator=tars.tarsregistry.QueryObj@tcp -h xxx2 -p 17890:tcp -h xxx2 -p 17890

然后执行脚本,启动tarsnode:
/usr/local/app/tars/tarsnode/util/start.sh

在crontab配置一个进程监控,确保TARS框架服务在出现异常后能够重新启动。
* * * * * /usr/local/app/tars/tarsnode/util/monitor.sh

3.在主控机web管理平台点击预扩容,扩容,上传安装包

主控机web管理平台点击预扩容,扩容,上传安装包后可在【服务管理】【服务管理】中看到多了一个
192.168.118.180的一个尚未启动的服务.

 

 

4.确保扩容机被安装成架构能管理到的一个节点并安装

执行下面的步骤,将扩容机加入到架构的组织中,可通过图中的【安装节点】【自动安装节点】来完成这个工
作.用【自动安装节点】按钮之后如果一切正常会尝试将服务扩容机上的直接拉起来(其实之前我们已经将其启动
了),这里的步骤就是确保框架机与扩容机之间可以通信,方便框架对扩容机的管理.

 

5.发布服务

如果在web管理平台扩容机192.168.118.180节点的状态为active,并且在扩容机存在/usr/local/app/tars/tarsnode/data/TestApp.HelloServer/bin/HelloServer

且它成功启动说明扩容成功.

6.简单的轮询策略的负载均衡测试

Tars负载均衡支持三种方式:权重、轮询和hash,默认是轮询方式。验证负载均衡的前提是扩容,对业务服务
HelloServer进行扩容之后,可以修改客户端代码,验证负载均衡(轮询方式).
日志路径:/usr/local/app/tars/app_log/TestApp/HelloServer
轮询测试代码:
#include <iostream>
#include "servant/Communicator.h"
#include "Hello.h"

using namespace std;
using namespace TestApp;
using namespace tars;
#define N 10
int main(int argc,char ** argv)
{
    
    Communicator comm;
    //comm.setProperty("locator","tars.tarsregistry.QueryObj@tcp -h 192.168.118.138 -p 16344:tcp -h 192.168.118.180 -p 27434"); 
    try
    {
        HelloPrx prx;
        comm.stringToProxy("TestApp.HelloServer.HelloObj@tcp -h 192.168.118.138 -p 16344:tcp -h 192.168.118.180 -p 27434" , prx);
       
        try
        {
            std::string strsz[N];
            strsz[0] = "hello-0";strsz[1] = "hello-1";
            strsz[2] = "hello-2";strsz[3] = "hello-3";
            strsz[4] = "hello-4";strsz[5] = "hello-5";
            strsz[6] = "hello-6";strsz[7] = "hello-7";
            strsz[8] = "hello-8";strsz[9] = "hello-9";

            for(int i=0;i<N;++i)
            {
                
                std::string strTest = strsz[i];
                string sReq(strTest);
                string sRsp("");

                int iRet = prx->testHello(sReq, sRsp);
                cout<<"iRet:"<<iRet<<" sReq:"<<sReq<<" sRsp:"<<sRsp<<endl;
            }
        }
        catch(exception &ex)
        {
            cerr << "ex:" << ex.what() << endl;
        }
        catch(...)
        {
            cerr << "unknown exception." << endl;
        }
    }
    catch(exception& e)
    {
        cerr << "exception:" << e.what() << endl;
    }
    catch (...)
    {
        cerr << "unknown exception." << endl;
    }
    return 0;
}

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值