集群基础环境初始化
1、准备虚拟机
192.168.1.7
192.168.1.6
192.168.1.183
2、切换为国内centos源
3、修改sshd服务优化
[root@elk01 ~]# sed -i 's/#UseDNS yes/UseDNS no/g' /etc/ssh/sshd_config [root@elk01 ~]# sed -i 's/GSSAPIAuthentication yes/GSSAPIAuthentication no/g' /etc/ssh/sshd_config [root@elk01 ~]# grep ^UseDNS /etc/ssh/sshd_config UseDNS no [root@elk01 ~]# grep ^GSSAPIAuthentication /etc/ssh/sshd_config GSSAPIAuthentication no
4、关闭防火墙
[root@elk02 ~]# systemctl disable --now firewalld [root@elk02 ~]# systemctl is-enabled firewalld [root@elk02 ~]# systemctl status firewalld
5、禁用Selinux
[root@elk01 ~]# sed -i 's/enforcing/disabled/g' /etc/selinux/config [root@elk01 ~]# grep ^SELINUX = /etc/selinux/config [root@elk01 ~]# setenforce 0 [root@elk01 ~]# getenforce Permissive
6、配置集群免密登录及同步脚本
1、修改主机列表
[root@elk01 ~]# cat >>/etc/hosts<<'EOF' > 192.168.1.7 elk01.cm.com > 192.168.1.183 elk02.cm.com > 192.168.1.6 elko3.cm.com > EOF
2、在elk01节点上生成密钥对
[root@elk01 ~]# ssh-keygen -t rsa -P '' -f ~/.ssh/id_rsa -q [root@elk01 ~]# ll ~/.ssh/ total 12 -rw-------. 1 root root 1679 Feb 14 15:04 id_rsa #私钥 -rw-r--r--. 1 root root 399 Feb 14 15:04 id_rsa.pub #公钥
3、elk01上配置所有集群节点的免密登录
[root@elk01 ~]# for host_id in 01 02 03;do ssh-copy-id elk${host_id}.cm.com;done
4、连接测试
[root@elk01 ~]# ssh 'elk03.cm.com' Last login: Tue Feb 14 10:53:32 2023 from 192.168.1.8 [root@elk03 ~]# logout Connection to elk03.cm.com closed. [root@elk01 ~]# ssh 'elk02.cm.com' Last login: Tue Feb 14 10:53:17 2023 from 192.168.1.8
5、所有节点安装rsync数据同步工具
[root@elk01 ~]# yum install rsync -y
6、编写同步脚本
[root@elk01 ~]# vim /usr/local/sbin/data_rsync.sh #!/bin/bash #Auther:cm if [ $# -ne 1 ];then echo "Usage: $0 /path/to/file(绝对路径)" exit fi #判断文件是否存在 if [ ! -e $1 ];then echo "[ $1 ] dir or file not find!" exit fi #获取父路径 fullpath=`dirname $1` #获取子路径 basename=`basename $1` #进入父路径 cd $fullpath for host_id in 01 02 03 do #是的输出变成绿色 tput setaf 2 echo =====rsyncing elk${host_id}.cm.com:$basename ===== #使得终端恢复原来颜色 tput setaf 7 #将数据同步到其他两个节点 rsync -az $basename `whoami`@elk${host_id}.cm.com:$fullpath if [ $? -eq 0 ];then echo "命令执行成功" fi done
7、给脚本授权
[root@elk01 ~]# chmod +x /usr/local/sbin/data_rsync.sh
8、测试
[root@elk01 ~]# mkdir /tmp/test/ [root@elk01 ~]# touch /tmp/test/test.txt [root@elk01 ~]# echo 111 > /tmp/test/test.txt [root@elk01 ~]# data_rsync.sh /tmp/test/ =====rsyncing elk01.cm.com:test ===== 命令执行成功! =====rsyncing elk02.cm.com:test ===== 命令执行成功! =====rsyncing elk03.cm.com:test ===== 命令执行成功!
[root@elk02 ~]# ll /tmp/test/test.txt -rw-r--r--. 1 root root 4 Feb 14 16:06 /tmp/test/test.txt [root@elk02 ~]# cat /tmp/test/test.txt 111
7、集群时间同步
1、安装常用的Linux工具
yum install vim net-tools
2、安装chrony服务
yum install ntpdate chrony -y
3、修改chrony服务文件
[root@elk01 ~]# vim /etc/chrony.conf #注释官方时间服务器,换成阿里云时间服务器 #server 0.centos.pool.ntp.org iburst #server 1.centos.pool.ntp.org iburst #server 2.centos.pool.ntp.org iburst #server 3.centos.pool.ntp.org iburst server ntp1.aliyun.com iburst server ntp2.aliyun.com iburst server ntp3.aliyun.com iburst server ntp4.aliyun.com iburst server ntp5.aliyun.com iburst server ntp6.aliyun.com iburst server ntp7.aliyun.com iburst
4、配置chronyd开机自启动 或重启服务
[root@elk01 ~]# systemctl restart chronyd
[root@elk01 ~]# systemctl enable --now chronyd
5、查看服务
systemctl status chronyd
草根-920