Quasi-synchronous shell script for intranet cluster

Source: Internet
Author: User
Tags ssh

In the company's intranet configuration cluster synchronization, may be a proxy problem, NTPD and chrony are not used, so had to write shell script to solve

Prerequisites for each machine in the cluster has been configured with a password-free login

First, the password-free login configuration

1. Log in with the root user. Each server generates a public key, which is then merged into Authorized_keys.
2. CentOS does not start by default SSH no secret login, each server to configure/etc/ssh/sshd_config.
Vi/etc/ssh/sshd_config modification
Usedns No
Pubkeyauthentication Yes
3. Enter commands under each server ssh-keygen-t RSA, generate key, all do not enter the password, directly enter,/root will generate. SSH folder.
4. Under the Master server, merge the public key into the Authorized_keys file, enter the/root/.ssh directory, and merge through the SSH command.
Cat id_rsa.pub>> Authorized_keys
SSH [email protected] cat ~/.ssh/id_rsa.pub>> Authorized_keys
SSH [email protected] cat ~/.ssh/id_rsa.pub>> Authorized_keys
5. Copy the Master server's Authorized_keys, known_hosts to the Slave server's/root/.ssh directory
SCP Authorized_keys [Email protected]:/root/.ssh/
SCP Authorized_keys [Email protected]:/root/.ssh/
SCP known_hosts [Email protected]:/root/.ssh/
SCP known_hosts [Email protected]:/root/.ssh/

Second, quasi-synchronous script timer.sh, in the master host's time added 5 seconds, because the execution script a little delay, the range of quasi-synchronization is reduced

#!/usr/bin/env bash#hosts arrayhosts= ("bigdata02" "bigdata03" "Bigdata04" "bigdata05") #localhost Current time date1= ' Date ' +%y/%m/%d%h:%m:%s "' date2= ' date-d" $date 1 5 second "+"%y/%m/%d%h:%m:%s "' Echo ' Now the time is $date 1" #loop Host to set timefor hostname in ${hosts[*]}do    theday= ' date-d "$date 2" + "%y-%m-%d" '    thetime= ' date-d "$date 2" + "%H :%m:%s "'        echo $hostname    ssh-t $hostname bash-c" ' Date-s ' $theDay ' &&hwclock  -- SYSTOHC ' "    ssh-t $hostname bash-c" ' Date-s ' $theTime ' &&hwclock  --systohc ' " done

Third, set the scheduled task on master

Configure Centos7 timed tasks to perform an hourly systemctl start Crondsystemctl enable Crond.service Edit Current crontab, enter crontab-e* */1 * * * Sh/hom e/timer.sh

Network cluster quasi-synchronous shell script

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.