Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to build Cluster in CentOS 7 under Linux system

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/01 Report--

This article mainly introduces "how to build a cluster in CentOS 7 under the Linux system". In the daily operation, I believe that many people have doubts about how to build a cluster in the CentOS 7 under the Linux system. The editor consulted all kinds of materials and sorted out a simple and easy-to-use method of operation. I hope it will be helpful to answer the doubts about how to build a cluster in CentOS 7 under the Linux system. Next, please follow the editor to study!

How to build a high availability cluster under CentOS 7. High availability cluster is a server cluster technology that aims to reduce service outage time. It minimizes the impact of software / hardware / man-made failures on business by protecting the uninterrupted services provided by users' business programs. So how to build a highly available cluster under the new centos.

Environment: this paper implements a dual-set hot standby high availability cluster with two machines. The IP of the host name node1 is 192.168.122.168 and the IP of the host name node2 is 192.168.122.169.

First, the installation of cluster software must be software pcs,pacemaker,corosync,fence-agents-all, if you need to configure related services, but also to install the corresponding software

Second, configure the firewall

1. Prohibit firewall and selinux

Modify / etc/sysconfig/selinux to ensure SELINUX=disabled, and then execute setenforce 0 or reboot server to take effect

2. Set firewall rules

Third, the hostnames of each node are resolved to modify the hostnames of node1 and node2 respectively, directly modify / etc/hostname to add the local hostname and hosttable in centos 7, and then restart the network service.

Configure the host table for 2 hosts and add it to / etc/hosts

Fourth, time synchronization between nodes is carried out in node1 and node2 respectively, which can be realized by ntp.

Fifth, configure the key-free access of ssh between each node. The following actions need to be done on each node.

Both hosts need to be able to communicate with each other, so both hosts have to generate keys and copy public keys for each other. The hosts files on each other's nodes have to resolve each other's hostname, 192.168.122.168 node1 192.168.122.169 node2

6. Manage high availability clusters through pacemaker

1. Create cluster users

In order to facilitate communication between nodes and configure clusters, create a hacluster user on each node, and the password on each node must be the same.

2. Set pcsd to boot automatically.

3. Authentication among the nodes in the cluster

4. Create and start the cluster

5. Set cluster self-startup

6. View cluster status information

7. Set up fence devices

This can be referred to.

Corosync enables stonith by default, and the current cluster does not have a corresponding stonith device, so this default configuration is currently unavailable, which can be verified by the following command:

You can disable stonith by using the following command:

8. Configure storage

Highly available clusters can not only use local disks to build pure software mirror cluster systems, but also can use special shared disk devices to build large-scale shared disk cluster systems to fully meet the different needs of customers.

The main shared disks are iscsi or DBRD. Shared disks are not used in this article.

9. Configure floating-point IP

No matter where the cluster service runs, we need a fixed address to provide the service. Here I choose 192.168.122.101 as the floating IP, give it a memorable name ClusterIP and tell the cluster to check it every 30 seconds.

10. Configure apache service

Install httpd on node1 and node2 and confirm that httpd boot is disabled

Configure the httpd monitoring page (it seems that it can also be monitored through systemd if not configured), which can be executed on node1 and node2, respectively.

First, let's create a home page for Apache. The default Apache docroot on centos is / var/www/html, so let's set up a home page under this directory.

The node1 node is modified as follows:

The node2 node is modified as follows:

The following statement adds httpd to the cluster as a resource:

11. Create a group

Bundle VIP and WEB resource into this group to switch in the cluster as a whole. (this configuration is optional)

12. Configure the service startup sequence

To avoid resource conflicts, syntax: (pcs resource group add can also be started according to the order in which it is added, this configuration is optional)

13. Specify the preferred Location (this configuration is optional)

Pacemaker does not require the hardware configuration of your machine to be the same. Some machines may be better configured than others. In this case, we want to set rules such as resources running on a node when it is available. To achieve this effect, we create location constraints. Similarly, we give him a descriptive name (prefer-node1) to indicate how much we want to run the WEB service and how much we want to run on it (we now specify a score of 50, but in a two-node cluster, any value greater than 0 can achieve the desired effect), as well as the name of the target node:

The higher the score specified here, the more you want to run on the corresponding node.

Resource stickiness (this configuration is optional)

In some environments, it is required to avoid resource migration between nodes as much as possible. Migrating resources usually means that services are not available for a period of time, which can be a long time for some complex services, such as Oracle databases.

To achieve this, Pacemaker has a concept called "resource stickiness", which controls how much a service (resource) wants to stay on the node on which it is running.

In order to optimize the distribution of resources, Pacemaker sets this value to 0 by default. We can define different stickiness values for each resource, but in general, changing the default stickiness value is sufficient. Resource stickiness indicates whether the resource tends to stay in the current node. If it is a positive integer, a negative number will leave,-inf means negative infinity, and inf means positive infinity.

Summary of common commands: view cluster status: # pcs status

View the current configuration of the cluster: # pcs config

Cluster self-booting after boot: # pcs cluster enable-all

Start the cluster: # pcs cluster start-all

Check the status of cluster resources: # pcs resource show

Verify the cluster configuration: # crm_verify-L-V

Test resource configuration: # pcs resource debug-start resource

Set the node to standby: # pcs cluster standby node1

At this point, the study on "how to build a cluster in CentOS 7 under the Linux system" is over. I hope to be able to solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!

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.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report