CentOs7集群通用配置

  • 集群服务器直接免密登录
# /root/.ssh/ 目录下 生成公钥 私钥
ssh-keygen -t rsa  # 视具体情况yes或者回车

ls
authorized_keys  id_rsa  id_rsa.pub  known_hosts
# 分别为:授权码    私钥      公钥     记录其他通过ssh访问过此用户所在服务器(或者机器,虚拟机)的计算机的公钥

# 多台虚拟机一起做 互相拷贝公钥到对方的授权码中
ssh-copy-id hostname/ip  # 目标机器的ip地址或主机名(最好给本机也copy一个,ssh-copy-id 本机ip或者主机名)

# 完成后 就可以ssh免密登录集群其他机器了
ssh IP
exit
  • 集群文件远程同步工具rsync及同步脚本xsync
# 所有机器install rsync 并设置开机启动
yum install rsync -y
systemctl start rsyncd.service
systemctl enable rsyncd.service
# xsync脚本基于rsync服务
cd /usr/local/bin
touch xsync
vi xsync
# 添加以下内容

#!/bin/sh
# 获取输入参数个数,如果没有参数,直接退出
pcount=$#
if((pcount==0)); then
        echo no args...;
        exit;
fi

# 获取文件名称
p1=$1
fname=`basename $p1`
echo fname=$fname
# 获取上级目录到绝对路径
pdir=`cd -P $(dirname $p1); pwd`
echo pdir=$pdir
# 获取当前用户名称
user=`whoami`
# 循环
for((host=1; host<=3; host++)); do
        echo $pdir/$fname $user@cdh0$host:$pdir
        echo ==================cdh0$host==================
        rsync -rvl $pdir/$fname $user@cdh0$host:$pdir
done
#Note:这里的host对应自己主机名,需要做相应修改。另外,for循环中的host的边界值由自己的主机编号决定。

# 脚本写好后,赋予执行权限
chmod a+x xsync
ll 看一下
-rwxr-xr-x 1 root root 693 12月  1 23:18 xsync

测试一下

# cdh01机器
cd /opt
touch test.txt
xsync test.txt

# cdh01-03对应/opt目录下出现test.txt文件 完成了同步
fname=test.txt
pdir=/opt
/opt/test.txt root@cdh01:/opt
==================cdh01==================
sending incremental file list

sent 44 bytes  received 12 bytes  112.00 bytes/sec
total size is 0  speedup is 0.00
/opt/test.txt root@cdh02:/opt
==================cdh02==================
sending incremental file list
test.txt

sent 87 bytes  received 35 bytes  244.00 bytes/sec
total size is 0  speedup is 0.00
/opt/test.txt root@cdh03:/opt
==================cdh03==================
sending incremental file list
test.txt

sent 87 bytes  received 35 bytes  244.00 bytes/sec
total size is 0  speedup is 0.00
  • 集群xcall脚本
#!/bin/bash
pcount=$#
if((pcount==0));then
        echo no args;
        exit;
fi

for((i=1; i<=3; i++)); do
        echo ----------cdh0$i---------
        ssh cdh0$i $@
done
# 测试遇到问题 jps:没找到命令
# 解决一:需要在 /usr/local/bin目录下创建jps软连接
which jps
/usr/java/jdk/bin/jps
# 每台机器
ln -s /usr/java/jdk/bin/jps jps

# 解决二: 在xcall.sh中 要执行的命令前添加 source /etc/profile 加载一下配置文件
ssh cdh0$i "source /etc/profile;$@"

# 测试就ok了
  • 集群服务器时钟同步
集群时钟同步方式有两种:
1. 主主:每台服务器和互联网同步
2. 主从:主服务器和互联网同步,从服务器与主服务器同步
对于HBase这种对timestamp比较敏感的组件,由于内网较外网的优势,主从方式是首选
# 所有服务器安装 ntp服务
yum install ntp -y

# 选择第一台机器 cdh01 作为主节点 进行配置
vi /etc/ntp.conf

# 添加下面内容
# 当无法访问外网时,与机器本地硬件时间同步
server 127.127.1.0 iburst local clock
# ntp服务允许哪些网段的服务器连接上来同步,配置集群网段 
restrict 192.168.xxx.0 mask 255.255.255.0 nomodify notrap
# local time
server  127.127.1.0
fudge   127.127.1.0 stratum 10

# 主服务器cdh01 启动并开机自启ntp服务
systemctl start ntpd
systemctl enable ntpd
# 查看一下ntp状态
systemctl status ntpd

● ntpd.service - Network Time Service
   Loaded: loaded (/usr/lib/systemd/system/ntpd.service; disabled; vendor preset: disabled)
   Active: active (running) since 三 2020-12-02 20:59:22 CST; 1min 6s ago
  Process: 1554 ExecStart=/usr/sbin/ntpd -u ntp:ntp $OPTIONS (code=exited, status=0/SUCCESS)
 Main PID: 1555 (ntpd)
    Tasks: 1
   Memory: 620.0K
   CGroup: /system.slice/ntpd.service
           └─1555 /usr/sbin/ntpd -u ntp:ntp -g
# 查看同步情况
ntpq -p

     remote           refid      st t when poll reach   delay   offset  jitter
==============================================================================
 time.cloudflare 10.12.2.186      3 u  223   64   10  257.034  -19.212   1.196
*202.118.1.130   .PTP.            1 u   24   64   27   43.842    1.729   2.686
+undefined.hostn 127.67.113.92    2 u   29   64   17  287.058  -49.107  11.309
+ntp.xtom.nl     134.71.66.21     2 u   86   64   26  192.959   10.240   5.577
 LOCAL(0)        .LOCL.          10 l  290   64   20    0.000    0.000   0.000

# 从服务器配置
# 从服务器 关闭并禁用开机自启ntp服务 因为从要向主同步
systemctl stop ntpd
systemctl disable ntpd

# 与主服务器同步
ntpdate cdh01

 2 Dec 21:07:38 ntpdate[1556]: adjust time server 192.168.xxx.xxx offset 0.021882 sec
# 设置每天定时同步
crontab -e
# 添加内容 表示每天零点零分同步
0 0 * * * /usr/sbin/ntpdate cdh01
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值