CDH集群部署脚本

hosts

[root@ipsynm0001 ~]# cat 154_scp_hosts_all.sh 
#!/bin/bash
for ip in `cat /root/ip_all_154.txt`
do
/root/scp_hosts.exp /etc/hosts $ip /etc/hosts root Yhrt@2016 
done

[root@ipsynm0001 ~]# cat scp_hosts.exp 
#!/bin/expect
if {$argc<5} {
puts stderr "Usage: $argv0 localfile host remotefile user passwd "
exit 1
}
set localfile [ lindex $argv 0 ]
set host [ lindex $argv 1 ]
set remotefile [ lindex $argv 2 ]
set user [ lindex $argv 3 ]
set pwd  [ lindex $argv 4 ]
set timeout 30
#spawn ssh -p22 ${user}@${host} "rm -rf ${remotefile}"
#expect {
# "*yes/no" { send "yes\r"; exp_continue }
# "*Password:" { send "$pwd\r"; exp_continue }
#}
spawn scp   ${localfile} ${user}@${host}:${remotefile}
expect "*Password:"
send "$pwd\r"
#expect "*#"
send "exit\r"
interact


firewall

[root@ipsynm0001 ~]# cat 154_stop_firewalld.sh
#!/bin/bash
for ip in `cat /root/ip_all_154.txt`
do
/root/098_stop_firewalld.exp  $ip root Yhrt@2016
done

[root@ipsynm0001 ~]# cat 098_stop_firewalld.exp 
#!/bin/expect
if {$argc<3} {
puts stderr "Usage: $argv0 start_agent host user passwd "
exit 1
}
set host [ lindex $argv 0 ]
set user [ lindex $argv 1 ]
set pwd  [ lindex $argv 2 ]
set timeout 30
spawn ssh -p22 ${user}@${host} "systemctl status firewalld "
expect {
 "*Password:" { send "$pwd\r"; exp_continue }
}
spawn ssh -p22 ${user}@${host} "systemctl stop firewalld"
expect {
 "*Password:" { send "$pwd\r"; exp_continue }
}
spawn ssh -p22 ${user}@${host} "systemctl disable  firewalld " 
expect {
 "*Password:" { send "$pwd\r"; exp_continue }
}
spawn ssh -p22 ${user}@${host} "systemctl status firewalld "
expect {
 "*Password:" { send "$pwd\r"; exp_continue }
}

#expect eof
# exit
#interact


profile

[root@ipsynm0001 ~]# cat 154_scp_profile_all.sh 
#!/bin/bash
for ip in `cat /root/ip_all_154.txt`
do
/root/scp_profile.exp /etc/profile $ip /etc/profile root Yhrt@2016 
done

[root@ipsynm0001 ~]# cat scp_profile.exp 
#!/bin/expect
if {$argc<5} {
puts stderr "Usage: $argv0 localfile host remotefile user passwd "
exit 1
}
set localfile [ lindex $argv 0 ]
set host [ lindex $argv 1 ]
set remotefile [ lindex $argv 2 ]
set user [ lindex $argv 3 ]
set pwd  [ lindex $argv 4 ]
set timeout 30
spawn ssh -p22 ${user}@${host} "rm -rf ${remotefile}"
expect {
 "*yes/no" { send "yes\r"; exp_continue }
 "*Password:" { send "$pwd\r"; exp_continue }
}
spawn scp   ${localfile} ${user}@${host}:${remotefile}
expect "*Password:"
send "$pwd\r"
send "exit\r"
interact


jdk

[root@ipsynm0001 ~]# cat scp_jdk_all.sh
#!/bin/bash
for ip in `cat /root/ip_all_1.txt
do
/root/scp_jdk.exp /usr/java/jdk1.8.0_171 $ip /usr/java/ root Yhrt@2016  
done

[root@ipsynm0001 ~]# cat scp_jdk.exp 
#!/bin/expect
if {$argc<5} {
puts stderr "Usage: $argv0 localfile host remotefile user passwd  "
exit 1
}
set localfile [ lindex $argv 0 ]
set host [ lindex $argv 1 ]
set remotefile [ lindex $argv 2 ]
set user [ lindex $argv 3 ]
set pwd  [ lindex $argv 4 ]
set timeout 30
spawn ssh -p22 ${user}@${host} "rm -rf ${remotefile}"
expect {
 "*yes/no" { send "yes\r"; exp_continue }
 "*Password:" { send "$pwd\r"; exp_continue }
}
spawn ssh -p22 ${user}@${host} "mkdir -p ${remotefile}"
expect {
 "*yes/no" { send "yes\r"; exp_continue }
 "*Password:" { send "$pwd\r"; exp_continue }
}
spawn ssh -p22 ${user}@${host} "chmod -R 755 ${remotefile}"
expect {
 "*yes/no" { send "yes\r"; exp_continue }
 "*Password:" { send "$pwd\r"; exp_continue }
}
spawn scp -r  ${localfile} ${user}@${host}:${remotefile}
expect {
 "*yes/no" { send "yes\r"; exp_continue }
 "*Password:" { send "$pwd\r"; exp_continue }
}
#expect "*#"
send "exit\r"
interact

[root@ipsynm0001 ~]# cat 154_install_jdk_all.sh
#!/bin/bash
for ip in `cat /root/ip_all_154.txt`
do
/root/100_install_jdk_all.exp /root/oracle-j2sdk1.8-1.8.0+update141-1.x86_64.rpm $ip /root root Yhrt@2016  
done

[root@ipsynm0001 ~]# cat 100_install_jdk_all.exp
#!/bin/expect
if {$argc<5} {
puts stderr "Usage: $argv0 localfile host remotefile user passwd  "
exit 1
}
set localfile [ lindex $argv 0 ]
set host [ lindex $argv 1 ]
set remotefile [ lindex $argv 2 ]
set user [ lindex $argv 3 ]
set pwd  [ lindex $argv 4 ]
set timeout 30
spawn scp -r  ${localfile} ${user}@${host}:${remotefile}
expect {
 "*yes/no" { send "yes\r"; exp_continue }
 "*Password:" { send "$pwd\r"; exp_continue }
}
spawn ssh -p22 ${user}@${host} "rpm -qa | grep jdk"
expect {
 "*yes/no" { send "yes\r"; exp_continue }
 "*Password:" { send "$pwd\r"; exp_continue }
}

#copy-jdk-configs-2.2-3.el7.noarch
#java-1.7.0-openjdk-devel-1.7.0.141-2.6.10.5.el7.x86_64
#java-1.7.0-openjdk-headless-1.7.0.141-2.6.10.5.el7.x86_64
#java-1.7.0-openjdk-1.7.0.141-2.6.10.5.el7.x86_64

spawn ssh -p22 ${user}@${host} "rpm -e java-1.7.0-openjdk-devel-1.7.0.141-2.6.10.5.el7.x86_64"
expect {
 "*yes/no" { send "yes\r"; exp_continue }
 "*Password:" { send "$pwd\r"; exp_continue }
}

spawn ssh -p22 ${user}@${host} "rpm -e java-1.7.0-openjdk-1.7.0.141-2.6.10.5.el7.x86_64"
expect {
 "*yes/no" { send "yes\r"; exp_continue }
 "*Password:" { send "$pwd\r"; exp_continue }
}

#java-1.7.0-openjdk-headless-1.7.0.141-2.6.10.5.el7.x86_64
spawn ssh -p22 ${user}@${host} "rpm -e java-1.7.0-openjdk-headless-1.7.0.141-2.6.10.5.el7.x86_64"
expect {
 "*yes/no" { send "yes\r"; exp_continue }
 "*Password:" { send "$pwd\r"; exp_continue }
}
spawn ssh -p22 ${user}@${host} "rpm -e copy-jdk-configs-2.2-3.el7.noarch"
expect {
 "*yes/no" { send "yes\r"; exp_continue }
 "*Password:" { send "$pwd\r"; exp_continue }
}

spawn ssh -p22 ${user}@${host} "rpm -ivh /root/oracle-j2sdk1.8-1.8.0+update141-1.x86_64.rpm"
expect {
 "*yes/no" { send "yes\r"; exp_continue }
 "*Password:" { send "$pwd\r"; exp_continue }
}
spawn ssh -p22 ${user}@${host} "source /etc/profile;java -version"
expect {
 "*yes/no" { send "yes\r"; exp_continue }
 "*Password:" { send "$pwd\r"; exp_continue }
}

#expect "*#"
#send "exit\r"
#interact


免密

[root@ipsynm0001 ~]# cat 154_gen_get_key_root.sh
#!/bin/bash
for ip in `cat /root/ip_all_154.txt`
do
/root/154_gen_root_ssh_key.exp $ip  root Yhrt@2016 
done

[root@ipsynm0001 ~]# cat 154_gen_root_ssh_key.exp
#!/bin/expect
if {$argc<3} {
puts stderr "Usage: $argv0 host user passwd "
exit 1
}
set host [ lindex $argv 0 ]
set user [ lindex $argv 1 ]
set pwd  [ lindex $argv 2 ]
set timeout 30
spawn ssh -p22 ${user}@${host} "rm -rf /root/.ssh/id_rsa"
expect {
 "*yes/no" { send "yes\r"; exp_continue }
 "*Password:" { send "$pwd\r"; exp_continue }
}
spawn ssh -p22 ${user}@${host} "rm -rf /root/.ssh/id_rsa.pub.*"
expect {
 "*yes/no" { send "yes\r"; exp_continue }
 "*Password:" { send "$pwd\r"; exp_continue }
}
#expect "*#"
spawn ssh -p22 ${user}@${host} "ssh-keygen -t rsa"            
#如果ssh端口是非22,比如22222,那么这一行的ssh后面添加"-p22222"
expect {
"*yes/no" { send "yes\r"; exp_continue }
"*Password:" { send "$pwd\r"; exp_continue }
"Enter file in which to save the key*" { send "\n\r"; exp_continue }
"Overwrite*" { send "y\n"; exp_continue } 
"Enter passphrase (empty for no passphrase):" { send "\n\r"; exp_continue }
"Enter same passphrase again:" { send "\n\r" }
}
spawn ssh -p22 ${user}@${host} "cp /root/.ssh/id_rsa.pub /root/.ssh/id_rsa.pub.`hostname | cut -d'x' -f3 |sed 's/ //g' |sed -n '1p'`"
expect {
 "*yes/no" { send "yes\r"; exp_continue }
 "*Password:" { send "$pwd\r"; exp_continue }
}
spawn scp ${user}@${host}:/root/.ssh/id_rsa.pub.ipsynm* /root/.ssh/154_20190128
expect {
 "*yes/no" { send "yes\r"; exp_continue }
 "*Password:" { send "$pwd\r"; exp_continue }
}
#expect "*#"

[root@ipsynm0001 ~]# cat 154_scp_key_root.sh
#!/bin/bash
for ip in `cat /root/ip_all_154.txt`
do
/root/scp_key.exp /root/.ssh/authorized_keys $ip /root/.ssh/authorized_keys root Yhrt@2016 

done

[root@ipsynm0001 ~]# cat scp_key.exp 
#!/bin/expect
if {$argc<5} {
puts stderr "Usage: $argv0 localfile host remotefile user passwd "
exit 1
}
set localfile [ lindex $argv 0 ]
set host [ lindex $argv 1 ]
set remotefile [ lindex $argv 2 ]
set user [ lindex $argv 3 ]
set pwd  [ lindex $argv 4 ]
set timeout 30
spawn ssh -p22 ${user}@${host} "rm -rf ${remotefile}"
expect {
 "*yes/no" { send "yes\r"; exp_continue }
 "*Password:" { send "$pwd\r"; exp_continue }
}
spawn scp   ${localfile} ${user}@${host}:${remotefile}
expect {
 "*yes/no" { send "yes\r"; exp_continue }
 "*Password:" { send "$pwd\r"; exp_continue }
}


透明大页面

[root@ipsynm0001 ~]# cat 154_cdh_transparent_linux.sh
#!/bin/bash
for ip in `cat /root/ip_all_154.txt`
#ip_all_transparent.txt`
do
/root/scp_cdh_setup_linux.exp /root/cdh_transparent_linux.sh $ip /root/cdh_transparent_linux.sh root  Yhrt@2016
done

[root@ipsynm0001 ~]# cat cdh_transparent_linux.sh 
echo never > /sys/kernel/mm/transparent_hugepage/defrag 
echo never > /sys/kernel/mm/transparent_hugepage/enabled 
echo 'echo never > /sys/kernel/mm/transparent_hugepage/enabled' >> /etc/rc.local
echo 'echo never > /sys/kernel/mm/transparent_hugepage/defrag' >> /etc/rc.local

[root@ipsynm0001 ~]# cat scp_cdh_setup_linux.exp 
#!/bin/expect
if {$argc<5} {
puts stderr "Usage: $argv0 localfile host remotefile user passwd "
exit 1
}
set localfile [ lindex $argv 0 ]
set host [ lindex $argv 1 ]
set remotefile [ lindex $argv 2 ]
set user [ lindex $argv 3 ]
set pwd  [ lindex $argv 4 ]
set timeout 30
spawn ssh -p22 ${user}@${host} "rm -rf ${remotefile}"
expect {
 "*yes/no" { send "yes\r"; exp_continue }
 "*Password:" { send "$pwd\r"; exp_continue }
}
spawn scp   ${localfile} ${user}@${host}:${remotefile}
expect {
 "*yes/no" { send "yes\r"; exp_continue }
 "*Password:" { send "$pwd\r"; exp_continue }
}
#expect "*#"

spawn ssh -p22 ${user}@${host} "sh ${remotefile}"
expect {
 "*yes/no" { send "yes\r"; exp_continue }
 "*Password:" { send "$pwd\r"; exp_continue }
}
 

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值