1 #!/bin/bash 2 3 # 创建必备文件夹 4 if [ ! -e /home/soft/ ];then mkdir -p /home/soft/;fi 5 6 # 修改主机映射 7 sethosts(){ 8 names=() 9 ips=() 10 x=0 11 while [ 1 -eq 1 ] 12 do 13 read -p "输入0结束,请输入第$[$x+1]个ip --> " ip 14 if [ "$ip" == "0" ];then break;fi 15 ips[$x]=$ip 16 let x++ 17 done 18 19 20 for (( i=0;i<${#ips[*]};i++ )) 21 do 22 read -p "请输入${ips[$i]}对应的主机名 --> " name 23 echo -e "${ips[$i]} ${name}" >> /etc/hosts 24 done 25 26 echo ------------------------------------ 27 cat /etc/hosts 28 echo ----------------------------------- 29 30 } 31 32 # 卸载软件 33 uninstall(){ 34 rpm -qa | grep "$1" > /home/soft/"$1".tmp.txt 35 while [ 1 -eq 1 ] 36 do 37 a=`head -n 1 /home/soft/"$1".tmp.txt` 38 if [ "$a" == "" ];then break;rm -rf /home/soft/"$1".tmp.txt;fi 39 rpm -e --nodeps "$a" 40 sed -i '/'"$a"'/d' /home/soft/"$1".tmp.txt 41 done 42 rm -rf /home/soft/"$1".tmp.txt 43 echo "-------uninstall--${1}--OK.--------" 44 45 } 46 47 # 设置环境变量 48 setprofile(){ 49 read -p "Enter your java-home --> " JAVA_HOME 50 read -p "Enter your hadoop-home --> " HADOOP_HOME 51 read -p "Enter your zookeeper-home --> " ZOOKEEPER_HOME 52 echo ' 53 export JAVA_HOME='"${JAVA_HOME}"' 54 export JRE_HOME='"${JAVA_HOME}/jre"' 55 export HADOOP_HOME='"${HADOOP_HOME}"' 56 export ZOOKEEPER_HOME='"${ZOOKEEPER_HOME}"' 57 export PATH=$JAVA_HOME/bin:$JRE_HOME/bin:$HADOOP_HOME/bin:$HADOOP_HOME/sbin:$ZOOKEEPER_HOME/bin:$PATH 58 export CLASSPATH=$JAVA_HOME/lib:$JRE_HOME/lib:$CLASSPATH' >> /etc/profile 59 60 } 61 62 # 设置ip 63 setip(){ 64 65 grep 'eth1' /etc/udev/rules.d/70-persistent-net.rules 66 if [ $? -eq 0 ];then 67 sed -i '/eth0/d;/^$/d;/#/d' /etc/udev/rules.d/70-persistent-net.rules 68 sed -i 's/eth1/eth0/' /etc/udev/rules.d/70-persistent-net.rules 69 fi 70 71 mac=`awk -F"," '{print $4}' /etc/udev/rules.d/70-persistent-net.rules | awk -F""" '{print $2}'` 72 sed -i 's/HWADDR=.*/'"HWADDR=${mac}"'/' /etc/sysconfig/network-scripts/ifcfg-eth0 73 74 read -p "请输入ip --> " ip 75 sed -i 's/IPADDR=.*/IPADDR='"$ip"'/' /etc/sysconfig/network-scripts/ifcfg-eth0 76 echo ------------------------------------------- 77 cat /etc/sysconfig/network-scripts/ifcfg-eth0 78 echo ------------------------------------------ 79 } 80 81 # 设置 mac 82 setmac(){ 83 84 grep 'eth1' /etc/udev/rules.d/70-persistent-net.rules 85 if [ $? -eq 0 ];then 86 sed -i '/eth0/d;/^$/d;/#/d' /etc/udev/rules.d/70-persistent-net.rules 87 sed -i 's/eth1/eth0/' /etc/udev/rules.d/70-persistent-net.rules 88 fi 89 cat /etc/udev/rules.d/70-persistent-net.rules 90 } 91 92 # 主菜单 93 main(){ 94 while [ 1 -eq 1 ] 95 do 96 read -p " 97 98 +-------------------------------------------------------+-----------------------+ 99 | Linux--Tools by:curry | 100 +-----------------------------+-------------------------+-----------------------+ 101 | 1. 修改主机名 | a1. 卸载--jdk | b1. 格式化 hdfs | 102 | 2. 修改ip | a2. see--jdk | b2. 开启 hdfs | 103 | 3. 修改mac | a3. 卸载--mysql | b3. 开启 yarn | 104 | 4. 修改主机映射 | a4. see--mysql | b4. 开启 zookeeper | 105 | 5. 关闭防火墙及开机自启 | a5. set--环境变量 | b5. 开启 journalnode | 106 | 6. 网络服务及开机自启 | a6. set--ssh免密 | b6. 格式化 zookeeper | 107 | 7. reboot | a7. test--安装mysql | | 108 +-----------------------------+-------------------------+-----------------------+ 109 | e1. edit--ip | f1. 发送--ssh授权文件 | g1. 查--yum | 110 | e2. edit--mac | f2. 发送--hosts | g2. 查--rpm | 111 | e3. edit--hosts | f3. 发送--profile | g3. 安装--yum | 112 | e4. edit--hostname | f4. 追加ssh-->授权文件 | g4. 卸载--rpm | 113 | e5. edit--profile | | | 114 +-----------------------------+-------------------------+-----------------------+ 115 | 0. 退出 e. 编辑本文件 | | 116 +-----------------------------+-------------------------+-----------------------+ 117 118 " flag 119 case $flag in 120 f4) 121 cat ~/.ssh/id_rsa.pub >> ~/.ssh/authorized_keys 122 ;; 123 g4) 124 read -p "请输入程序名 --> " word 125 rpm -e --nodeps "${word}" 126 ;; 127 g3) 128 read -p "请输入安装包名称 --> " priword 129 yum install -y "${priword}" 130 ;; 131 g2) 132 133 read -p "请输入关键字 --> " priword 134 rpm -qa | grep "${priword}" 135 ;; 136 g1) 137 read -p "请输入关键字 --> " priword 138 yum search ${priword} | grep "${priword}" --color 139 ;; 140 f3) 141 read -p "请输入接受主机名或主机ip --> " flag 142 scp -r /etc/profile ${flag}:/etc/ 143 ;; 144 f2) 145 read -p "请输入接受主机名或主机ip --> " flag 146 scp -r /etc/hosts ${flag}:/etc/ 147 ;; 148 f1) 149 read -p "请输入接受主机名或主机ip --> " flag 150 scp -r ~/.ssh/authorized_keys ${flag}:~/.ssh/ 151 ;; 152 e5) 153 vim /etc/profile 154 ;; 155 e4) 156 vim /etc/sysconfig/network 157 ;; 158 e3) 159 vim /etc/hosts 160 ;; 161 e2) 162 vim /etc/udev/rules.d/70-persistent-net.rules 163 ;; 164 e1) 165 vim /etc/sysconfig/network-scripts/ifcfg-eth0 166 ;; 167 e) 168 vim /home/tools/curry.sh 169 ;; 170 b6) 171 hdfs zkfc -formatZK 172 ;; 173 b5) 174 hadoop-daemon.sh start journalnode 175 ;; 176 b4) 177 zkServer.sh start 178 ;; 179 b3) 180 start-yarn.sh 181 ;; 182 b2) 183 start-dfs.sh 184 ;; 185 b1) 186 hdfs namenode -format 187 ;; 188 a7) 189 yum install -y mysql.x86_64 190 ;; 191 a6) 192 rm -rf ~/.ssh/* 193 ssh-keygen -t rsa; 194 cat /root/.ssh/id_rsa.pub >> /root/.ssh/authorized_keys 195 echo ----------------------------- 196 cat /root/.ssh/authorized_keys 197 echo ---------------------------- 198 ;; 199 a5) 200 setprofile 201 ;; 202 a4) 203 rpm -qa | grep "mysql" 204 ;; 205 a3) 206 uninstall "mysql" 207 ;; 208 a2) 209 rpm -qa | grep jdk 210 ;; 211 a1) 212 uninstall "java" 213 ;; 214 0) 215 echo -e " 再见 "; break 216 ;; 217 1) 218 read -p "请设置主机名 --> " hostname 219 sed -i 's/HOSTNAME=.*/HOSTNAME='"$hostname"'/' /etc/sysconfig/network 220 cat /etc/sysconfig/network | grep "HOSTNAME" 221 ;; 222 2) 223 setip 224 ;; 225 3) 226 setmac 227 ;; 228 4) 229 sethosts 230 ;; 231 5) 232 service iptables stop 233 chkconfig iptables off 234 ;; 235 6) 236 service network stop 237 service network start 238 chkconfig network on 239 ;; 240 7) 241 reboot 242 ;; 243 *) 244 echo "没长眼吗? 看好再输入,OK?" 245 ;; 246 esac 247 done 248 } 249 250 251 252 253 main