In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)05/31 Report--
How to use ACM to achieve zookeeper dependent service transparent Failover migration, many novices are not very clear about this, in order to help you solve this problem, the following editor will explain in detail for you, people with this need can come to learn, I hope you can get something.
Introduction to transparent Failover migration scenarios using ACM to implement zookeeper dependent services
In a data center, a zookeeper cluster often serves multiple lines of business or business systems, each of which has its own development team, while public services such as zookeeper will have special operations or teams responsible for ensuring its service availability and continuity.
The business application accesses the zookeeper service through the Apache Curator client or the native zookeeper client. In this process, you must specify connectString in the application, that is, the ip list of the machine where the zookeeper service resides. The code example is as follows:
Final String connectString = "192.168.1.151lav 2181192.168.1.152Vera 2181192.168.1.153Rd 2181192.168.1.154Rd 2181192.168.1.155Vl2181"; final int sessionTimeoutInMs = 15000; final int connectionTimeoutInMs = 1000; final String appNs = "app1"; CuratorFrameworkFactory.Builder builder = CuratorFrameworkFactory.builder () CuratorFramework zkClient = builder .connectString (connectString) .connectionTimeoutMs (connectionTimeoutInMs) .sessionTimeoutMs (sessionTimeoutInMs) .namespace (appNs) .retryPolicy (new RetryNTimes (6) 100)) .build () ZkClient.start ()
However, during the production and operation of zookeeper, the zookeeper service cluster may encounter machine failures, machine migration and so on. This process requires zookeeper operators to replace nodes and migrate services to new ip nodes. The whole process is shown in the following figure.
Scenario 1 Service Discovery Scheme using DNS or VIP
The scheme is shown in the figure:
In this scenario, the zk service ip can be hung on a dns domain name or vip. In this way, when the zookeeper replaces the node, the unaware is applied, which is the service discovery scheme.
Advantages
It is easy to understand, but due to DNS ttl cache invalidation, there will be convergence time.
Shortcoming
If you want to set the timeout time for the zookeeper cluster at the same time, apply the chroot/namespace using zookeeper, the user name, password and other configuration items used to connect the zookeeper service, and dynamically change these connection-related configurations according to the load and other conditions can not be achieved through the DNS,VIP system.
Scenario 2 uses the ACM scheme
We put the service ip list, connection timeout, session timeout parameters, chroot, current user name, password, etc., of the zookeeper cluster in an ACM configuration.
Then listen for changes to the configuration through ACM SDK. Here, we can use the EnsembleProvider feature provided by curator client to combine ACM to dynamically listen for changes in the ip list of the configuration service.
The sample code is as follows
Import java.io.IOException;import java.io.StringReader;import java.util.Properties;import java.util.concurrent.Executor;import java.util.concurrent.Executors;import java.util.concurrent.atomic.AtomicReference;import org.apache.curator.ensemble.EnsembleProvider;import com.alibaba.edas.acm.listener.ConfigChangeListener;import com.alibaba.edas.acm.ConfigService;import com.alibaba.edas.acm.exception.ConfigException;public class ACMEnsembleProvider implements EnsembleProvider {private static final String ACM_ZK_CFG_DATAID = "com.taobao.zookeeper.connCfg" Private static final String ACM_ZK_CFG_GROUP = "zookeeper"; private static final int ACM_TIME_OUT_MS = 3000; private final static Executor acmCallBackExecutor = Executors.newSingleThreadScheduledExecutor (); private ConfigChangeListener configChangeListener; private final AtomicReference connectionString = new AtomicReference (""); private Properties cfg = new Properties () Public String getZkHosts () {/ / copy the corresponding value ConfigService.init ("${domain}", "${namespace}", "${accessKey}", "${secretKey}") from the "sample code" of the configuration in the ACM console. Try {String zkServiceCfg = ConfigService.getConfig (ACM_ZK_CFG_DATAID, ACM_ZK_CFG_GROUP, ACM_TIME_OUT_MS); cfg.load (new StringReader (zkServiceCfg)); String connectString = cfg.getProperty ("connectString"); connectionString.set (connectString) Return connectString;} catch (ConfigException E1) {/ / logger.warn ("acm.getConfig error with dataId:" + / / dataIdZkHosts, e); e1.printStackTrace (); return null } catch (IOException e) {e.printStackTrace (); return null;}} public void start () throws Exception {configChangeListener = new ConfigChangeListener () {public Executor getExecutor () {return acmCallBackExecutor } public void receiveConfigInfo (String configInfo) {/ / logger.warn ("receive zkHosts change in diamond, dataId:" + / / dataIdZkHosts + ", changed zkHosts:" / / + configInfo) Try {cfg.load (new StringReader (configInfo));} catch (IOException e) {/ / process exception e.printStackTrace () } String connectString = cfg.getProperty ("connectString"); connectionString.set (connectString);}}; ConfigService.addListener (ACM_ZK_CFG_DATAID, ACM_ZK_CFG_GROUP, configChangeListener) } public String getConnectionString () {return connectionString.get ();} public void close () throws IOException {/ / ConfigService.removeListener (ACM_ZK_CFG_DATAID, ACM_ZK_CFG_GROUP, / / configChangeListener);}}
When the node of the zookeeper cluster dies, the ip list needs to be changed or the timeout parameter needs to be modified. When the znode quota quota is applied, the zookeeper operation and maintenance personnel only need to modify the relevant configuration items on the ACM, and the ACM will be automatically distributed to all application systems.
The scheme is shown in the figure:
In the above example, we can see that there is no communication cost between the application developer (Dev) and the operation and maintenance staff (Ops), and the application system also saves the cost of restarting or releasing the application due to connection-related configuration changes.
Is it helpful for you to read the above content? If you want to know more about the relevant knowledge or read more related articles, please follow the industry information channel, thank you for your support.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.