有关本地集群的linux操作tips

发布时间 2023-05-07 14:19:01作者: aminor

免密登录认证

-1. 使用rsa加密技术,生成公钥和私钥。一路回车即可
[root@username01 ~]# cd ~
[root@username01 ~]# ssh-keygen -t rsa	

-2. 进入~/.ssh目录下,使用ssh-copy-id命令
[root@username01 ~]# cd ~/.ssh			
[root@username01 .ssh]# ssh-copy-id  root@username01

-3. 进行验证	
[hadoop@username01 .ssh]# ssh username01
#下面的第一次执行时输入yes后,不提示输入密码就对了
[hadoop@username01 .ssh]# ssh localhost
[hadoop@username01 .ssh]# ssh 0.0.0.0

注意:三台机器提前安装好的情况下,需要同步公钥文件。如果使用克隆技术。那么使用同一套密钥对就方便多了。

linux ubuntu 自动登录root账户

https://blog.csdn.net/m0_46128839/article/details/116133371

跟着走一遍

linux 服务管理

查看所有开机启动项

systemctl list-unit-files | grep enabled

开启或关闭开机自启动服务

systemctl disable/enable [service_name]

服务管理

https://blog.csdn.net/liuchonghua/article/details/81743606

linux 集群执行脚本

集群同步

#!/bin/bash

for file in $@
do
	for host in CentOS002 CentOS003
	do
		if [ -e $file ]
		then
			pdir=$(cd -P $(dirname $file); pwd)
		
			fname=$(basename $file)
			ssh $host "mkdir -p $pdir"
			rsync -av $pdir/$fname $host:$pdir
			echo send $pdir/$file to $host:$pdir ...

		else
			echo $file does not exists!
		fi
	done
done  
echo done.

集群执行

#!/bin/bash

for file in $@
do
	for host in CentOS002 CentOS003
	do
		if [ -e $file ]
		then
			pdir=$(cd -P $(dirname $file); pwd)
		
			fname=$(basename $file)
			
			rsync -av $pdir/$fname $host:/tmp
			ssh $host "sh /tmp/$fname"
			echo send $file to $host:/tmp

		else
			echo $file does not exists!
		fi
	done
done  
echo done.

linux关闭防火墙

关闭防火墙

systemctl stop firewalld
systemctl disable firewalld

linux 集群时间同步

时间同步

# 1 选择集群中的某一台机器作为时间服务器,例如username01
# 2 保证这台服务器安装了ntp.x86_64。
# 3 保证ntpd 服务运行......
[root@username01 ~]# sudo service ntpd start
# 	开机自启动:
[root@username01 ~]# chkconfig ntpd on
	
# 4 配置相应文件:
[root@username01 ~]# vi /etc/ntp.conf
	
	# Hosts on local network are less restricted.
	# restrict 192.168.1.0 mask 255.255.255.0 nomodify notrap
  # 添加集群中的网络段位
	restrict 192.168.10.0 mask 255.255.255.0 nomodify notrap

	# Use public servers from the pool.ntp.org project.
	# Please consider joining the pool (http://www.pool.ntp.org/join.html).
	# 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 127.127.1.0     -master作为服务器
# 5 其他机器要保证安装ntpdate.x86_64

# 6 其他机器要使用root定义定时器
*/1 * * * * /usr/sbin/ntpdate -u username01