Hadoop记录-部署hadoop环境shell实现
#!/bin/bash menu() { echo "---欢迎使用hadoop部署管理程序---" echo "# 1.初始化Linux环境" echo "# 2.配置jdk" echo "# 3.配置ntpd时钟服务" echo "# 4.配置zookeeper环境" echo "# 5.配置hadoop环境" echo "# 6.退出程序" echo "-----------------------------" } choice() { read -p "Please choice a menu[1‐9]:" select } install_linux(){ mkdir /usr/app dir=/usr/app/software if [ ! -d ${dir} ] then mkdir /usr/app/software -p fi #设置主机名 hostnamectl set-hostname cent sed -i 's/HOSTNAME=localhost.localdomain/HOSTNAME=cent/g' /etc/sysconfig/network echo "192.168.66.128 cent" >> /etc/hosts #关闭selinux sed -i '/^SELINUX/s/=.*/=disabled/' /etc/selinux/config setenforce 0 #关闭防火墙 service iptables stop chkconfig iptables off #修改Linux系统的最大打开文件数量 cat >> /etc/security/limits.conf <<EOF * soft nofile 65536 * hard nofile 65536 EOF } install_jdk(){ find /usr/app/software -type -f -name 'jdk*.tar.gz' if [ $? -eq 0 ] then tar xvf /usr/app/software/jdk*.tar.gz -C /usr/app mv jdk* jdk cat >> /etc/profile <<EOF export JAVA_HOME=/usr/app/jdk export PATH=$JAVA_HOME/bin:$PATH export CLASSPATH=$JAVA_HOME/lib/tools.jar:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib EOF source /etc/profile else echo "请先上传jdk tar包" fi } install_ntpd(){ yum -y install ntp service ntpd restart #ntpdate -u ntp1.aliyun.com ---配置阿里云时钟 #如果是离线网络,则需要配置一台ntpd时钟,其他节点的同步这台时钟 } install_zookeeper(){ ls -ll /usr/app/software/zookeeper*.tar.gz if [ $? -eq 0 ] then tar xvf /usr/app/software/zookeeper*.tar.gz -C /usr/app mv zookeeper* zookeeper mv /usr/app/zookeeper/conf/zoo.cfg* /usr/app/zookeeper/conf/zoo.cfg echo>/usr/app/zookeeper/conf/zoo.cfg mkdir /usr/app/zookeeper/data cat >> /usr/app/zookeeper/conf/zoo.cfg << EOF tickTime=2000 initLimit=10 syncLimit=5 dataDir=/usr/app/zookeeper/data clientPort=2181 maxClientCnxns=60 server.1= cent:2888:3888 EOF else echo "请先上传zookeeper tar包" fi } install_hadoop(){ echo "配置太多(hadoop-env.sh/core-site.xml/hdfs-site.xml/mapred-site.xml/yarn-site.xml/yarn-env.sh),此功能忽略" } while : do menu choice case $select in 1) install_linux;; 2) install_jdk;; 3) install_ntpd;; 4) install_zookeeper;; 5) install_hadoop;; 6) exit;; *) echo "您输入的数字没有对应的菜单" esac done