Hadoop配置脚本

#!/bin/bash
read -p "请输入master节点IP地址:" masterip
read -p "请输入slave1节点IP地址:" slave1ip
read -p "请输入centosYUM源地址:" yumc
read -p "请输入ambariYUM源地址:" yuma
read -p "这是master节点?[y/n]" hostname
read -p "本机是否已存在 jdk-8u77-linux-x64.tar.gz文件[y/n]" file
if [ $file == y ];then
	echo -e "请输入jdk压缩文件路径"
	read -p "当前目录下请直接输入文件名" filepath
else
	echo -e "请输入jdk压缩文件远程URL"
	echo -e "参考格式:ftp://controller/bigdata/jdk-8u77-linux-x64.tar.gz"
	echo -e "\n"
	read fileurl
	mkdir -p /opt/jdk
fi
if [ $hostname == y ];then
	echo -e "正在配置master节点"
	hostnamectl set-hostname master
else
	echo -e "正在配置slave1节点"
	hostnamectl set-hostname slave1
fi
if [ -n `ls /etc/|grep hosts.bak` ];then
	rm -f /etc/hosts
	cp /etc/hosts.bak /etc/hosts
else
	cp /etc/hosts /etc/hosts.bak
fi
echo -e "$masterip master.hadoop master\n$slave1ip slave1.hadoop slave1" >> /etc/hosts
echo -e "hosts文件配置如下,按回车继续执行下面的内容]"
cat /etc/hosts
read h
rm -f /etc/yum.repos.d/*
echo -e "[centos]\nname=centos\nbaseurl=$yumc\ngpgcheck=0\nenabled=1" > /etc/yum.repos.d/centos.repo
echo -e "[ambari]\nname=ambari\nbaseurl=$yuma\ngpgcheck=0\nenabled=1" > /etc/yum.repos.d/ambari.repo
echo -e "YUM配置完成"
echo -e "正在验证"
yum clean all
yum repolist
echo -e "是否配置正确,如若错误请终止[回车继续执行]"
read cuo
if [ $hostname == y ];then
	echo -e "正在安装相关服务"
	yum install -y ntp httpd
	sed -i 's/server/#server/g' /etc/ntp.conf
	echo -e "server 127.127.1.0\nfudge 127.127.1.0 stratum 10" >> /etc/ntp.conf
	rm -f /etc/httpd/conf.d/welcome.conf
	systemctl enable httpd.service
	systemctl enable ntpd
	if [ -z "$(systemctl start httpd.service)" ];then
		echo -e httpd服务启动成功
	else
		echo -e 启动失败
		echo 脚本已终止,请检查相关服务配置
		exit 0
	fi
	if [ -z "$(systemctl start ntpd)" ];then
		echo -e ntpd服务启动成功
	else
		echo -e 启动失败
		echo 脚本已终止,请检查相关服务配置
		exit 0
	fi
else
	echo -e "emmmmmmmmm"
fi
echo -e "开始配置jdk"
mkdir /usr/jdk64
if [ $file == y ];then
	tar -zxvf $filepath -C /usr/jdk64
	echo -e "JDK文件解压缩完成"
else
	echo -e "开始下载JDK文件"
        cd /opt/jdk
	wget $fileurl /opt/jdk/
	tar -zxvf /opt/jdk/*tar.gz -C /usr/jdk64
	echo -e "JDK文件解压缩完成"
fi
echo -e "开始配置Java环境"
cd /usr/jdk64/jdk1.8*
jh=$(pwd)
echo "export JAVA_HOME=$jh" >> /etc/profile
echo 'export PATH=$JAVA_HOME/bin:$PATH' >> /etc/profile
echo -e "正在验证jdk"
source /etc/profile
java -version
yz=`java -version`
yzz=`echo $yz|grep 1.8.0`
if [ -n "$yzz" ];then
	echo -e "Java配置出错,请终止"
	read yooo
else
	echo -e "Java配置成功"
fi
if [ $hostname == y ];then
	echo -e "正在继续配置master节点"
	yum install -y ambari-server mariadb mariadb-server mysql-connector-java expect
	systemctl daemon-reload
	systemctl enable mariadb.service
	if [ -z "$(systemctl restart mariadb.service)" ];then
		echo -e mariadb服务启动成功
	else
		echo -e 启动失败
		echo 脚本已终止,请检查相关服务配置
		exit 0
	fi
	expect -c "
	spawn /usr/bin/mysql_secure_installation
	expect \"Enter current password for root (enter for none):\"
	send \"\r\"
	expect \"Set root password?\"
	send \"y\r\"
	expect \"New password:\"
	send \"bigdata\r\"
	expect \"Re-enter new password:\"
	send \"bigdata\r\"
	expect \"Remove anonymous users?\"
	send \"y\r\"
	expect \"Disallow root login remotely?\"
	send \"n\r\"
	expect \"Remove test database and access to it?\"
	send \"y\r\"
	expect \"Reload privilege tables now?\"
	send \"y\r\"
	expect eof
	"
	echo -e "正在创建数据库"
	mysql -uroot -pbigdata -e "create database ambari;"
	mysql -uroot -pbigdata -e "grant all privileges on ambari.* to 'ambari'@'localhost' identified by 'bigdata';"
	mysql -uroot -pbigdata -e "grant all privileges on ambari.* to 'ambari'@'%' identified by 'bigdata';"
	echo -e "正在刷新权限"
	mysql -uroot -pbigdata -e "flush privileges;"
	echo -e "正在验证"
	if [ -z `mysql -uambari -pbigdata -e "use ambari"` ];then
		echo -e "数据库及用户配置成功,开始导入数据库文件"
		if [ -z `ls /var/lib/ambari-server/resources/ | grep Ambari-DDL-MySQL-CREATE.sql` ];then
			echo -e "数据库文件不存在,请检查ambari服务是否成功安装"
		else
			mysql -uroot -pbigdata ambari < /var/lib/ambari-server/resources/Ambari-DDL-MySQL-CREATE.sql
		fi
		echo -e "正在查询导入结果"
		mysql -uambari -pbigdata -e "use ambari;show tables;"
	else
		echo -e "数据库用户配置失败"
		exit;
	fi
	echo  'export buildNumber=2.6.0.0' >> /etc/profile
	source /etc/profile
	echo -e "开始执行ambari-server setup命令"
	expect -c "
	spawn ambari-server setup
	expect \"Customize user account for ambari-server daemon [y/n] (n)?\"
	send \"n\r\"
	expect \"Enter choice (1):\"
	send \"3\r\"
	expect \"Path to JAVA_HOME:\"
	send \"$jh\r\"
	expect \"Enter advanced database configuration [y/n] (n)?\"
	send \"y\r\"
	expect \"Enter choice (1): \"
	send \"3\r\"
	expect \"Hostname (localhost):\"
	send \"localhost\r\"
	expect \"Port (3306):\"
	send \"3306\r\"
	expect \"Database name (ambari):\"
	send \"ambari\r\"
	expect \"Username (ambari):\"
	send \"ambari\r\"
	expect \"Enter Database Password (bigdata):\"
	send \"bigdata\r\"
	expect \"Proceed with configuring remote database connection properties [y/n] (y)?\"
	send \"y\r\"
	expect eof
	"
	ambari-server setup --jdbc-db=mysql --jdbc-driver=/usr/share/java/mysql-connector-java.jar
	ambari-server start
	echo -e "请在浏览器打开下面这个地址"
	echo -e "$masterip:8080"
else
	yum install -y ntpdate
	systemctl enable ntpdate
	echo -e "同步master节点"
	ntpdate master.hadoop
	echo -e "slave1节点已配置完成"
fi
echo -e "配置结束"

 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

坐公交也用券

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值