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