使用跳板机的目的:我们的服务器都是云主机,使用的都是aws比较多,而且aws是以私钥去连接公钥,连接的方式都是以root权限连接,这样子的话,开发人员要连接上服务器的话,不可能给root权限直接连吧,否则会对服务器造成很大的威胁.
跳板机实现的思路:使用shell去编写,账户这块使用LDAP做集中式管理+认证,权限这块使用sudo集中式控制管理.
LDAP:部署可以使用yum,安装简单,不过安装的目录和结构都不同于一个位置.
也可以使用编译安装,编译安装的话,需要一定的时间,期间也会遇到很多错误,好处就是可以把编译的环境统一管理在相同目录中.
两者安装LDAP,迁移的时候,也非常容易.
(1)跳板机实现的过程:LDAP安装+部署.我管理的LDAP是通过WEB管理工具来管理.
(2)编写shell菜单
(3)创建普通用户的私钥+公钥,并把公钥上传到对端的服务器的目录底下.
实现的截图:
脚本如下:
- [root@localhost jc]# cat tiaoban_deploy.sh
- #!/bin/bash
- ip=`/sbin/ifconfig eth0|grep "inet addr"|awk -F ":" '{print $2}'|awk '{print $1}'`
- current_date=`date +%Y-%m-%d-%H:%M:%S`
- dis_manumenu="<ip:${ip}-server>"
- user=`echo $USER`
- # Source function library.
- . /etc/rc.d/init.d/functions
- new_echo () {
- if [ -z "$2" ]
- then
- COLOR=33
- elif [ $2 == red ]
- then
- COLOR=31
- elif [ $2 == green ]
- then
- COLOR=32
- elif [ $2 == blue ]
- then
- COLOR=36
- elif [ $2 == purple ]
- then
- COLOR=35
- elif [ $2 == white ]
- then
- COLOR=39
- else
- echo new_echo function use error
- exit
- fi
- if [ -z "$4" ]
- then
- COLOR1=33
- elif [ $4 == red ]
- then
- COLOR1=31
- elif [ $4 == green ]
- then
- COLOR1=32
- elif [ $4 == blue ]
- then
- COLOR1=36
- elif [ $4 == purple ]
- then
- COLOR1=35
- elif [ $4 == white ]
- then
- COLOR1=39
- else
- echo new_echo function use error
- exit
- fi
- if [ -z "$3" ]
- then
- echo -en "\\033[1;${COLOR}m""\033[3m$1 \033[0m\n"
- else
- echo -en "\\033[1;${COLOR}m""\033[3m$1 \033[0m\033[70G\\033[1;${COLOR1}m\033[3m $3 \033[0m\n"
- fi
- }
- for signal in `seq 1 1000`
- do
- trap ':' INT EXIT TSTP TERM HUP $signal &> /dev/null
- done
- clear
- for signal in `name`
- do
- trap trap ':' INT EXIT TSTP TERM HUP $signal &> /dev/null
- done
- clear
- function getchar()
- {
- stty cbreak -echo
- dd if=/dev/tty bs=1 count=1 2>/dev/null
- stty -cbreak echo
- }
- ###############################################################################
- #while :
- #do
- name=`cat /opt/username`
- clear
- read -p "请输入登陆跳板机验证标识:" name
- repa=`cat /opt/username`
- if [ "$name" == "$repa" ];then
- action "认证标识正确,欢迎登陆跳板机。。。。。。。。。。。。。。。。。。。" /bin/true
- else
- action "对不起,您输入的认证标识有错误,无法登陆跳板机,已退出............" /bin/false
- exit
- exit
- fi
- # realuser=$(awk '{print $1}' $name)
- # realpass=$(awk '{print $1}' $pass)
- # if [ "$pass" == "$realpass" ]; then
- # echo "欢迎登陆跳板机。。。。。。。。。。。"
- #else
- # echo "对不起,您的输入有错误..............."
- #fi
- #done
- cat <<EOF
- 当前系统时间:$current_date
- =============================================================================
- $dis_manumenu 当前使用跳板机用户:$USER 版本:Versin1.0
- =============================================================================
- ---------------------------跳板机帮助手册--------------------------------
- (1)菜单0选项,是退出整个跳板机.
- (2)菜单1-11选项是服务器列表,这里只有11台服务器提供选择.
- (3)跳板机上面服务器包含:邮件系统,redmine,开发应用服务.
- -----------------------------------------------------------------------------
- **0)(exit)
- -->[--------------------公司跳板机菜单---------------------]:<--
- **1)redmine-server(8)
- **2)数据分析打点测试服(18)
- **3)测试服(11)
- **4)日志测试服I(13)
- **5)日志测试服II(22)
- **6)测试服I(12)
- **7)测试服II(16)
- **8)内网SSO服务器(192)
- **9)用户中心开发服(15)
- **10)用户中心QA测试服(23)
- **11)用户中心本地测试服(24)
- **12)用户中心本地测试服(24)
- ##############################################################################
- ==============================================================================
- EOF
- read -p "请选择: " num
- case $num in
- 0)
- action "-------------------------exit----------------------------" /bin/true
- exit
- ;;
- 1)
- ip="192.168.3.8"
- public=/home/$USER
- if [ -z $CHECK ]
- then
- clear
- new_echo "----------------------------------------------------------------------------------" green
- new_echo "Connection '$ip'($USER) " purple "[ SUCCESS ]" green
- new_echo "`date +'%x %X'` " white
- new_echo "--------------------------------- use ${SECONDS}s -----------------------------------------" green
- action 用户:$user-"现在开始登陆,请稍等..............................." /bin/true
- ssh -i "/home/$USER/.ssh/id_rsa" $user@$ip
- sleep 2
- fi
- ;;
- 2)
- ip="192.168.3.18"
- public=/home/$USER
- if [ -z $CHECK ]
- then
- clear
- new_echo "----------------------------------------------------------------------------------" green
- new_echo "Connection '$ip'($USER) " purple "[ SUCCESS ]" green
- new_echo "`date +'%x %X'` " white
- new_echo "--------------------------------- use ${SECONDS}s -----------------------------------------" green
- action 用户:$user-"现在开始登陆,请稍等..............................." /bin/true
- ssh -i "/home/$USER/.ssh/id_rsa" $user@$ip
- fi
- ;;
- 3)
- ip="192.168.3.11"
- public=/home/$USER
- if [ -z $CHECK ]
- then
- clear
- new_echo "----------------------------------------------------------------------------------" green
- new_echo "Connection '$ip'($USER) " purple "[ SUCCESS ]" green
- new_echo "`date +'%x %X'` " white
- new_echo "--------------------------------- use ${SECONDS}s -----------------------------------------" green
- action 用户:$user-"现在开始登陆,请稍等..............................." /bin/true
- ssh -i "/home/$USER/.ssh/id_rsa" $user@$ip
- fi
- ;;
- 4)
- ip="192.168.3.13"
- public=/home/$USER
- if [ -z $CHECK ]
- then
- clear
- new_echo "----------------------------------------------------------------------------------" green
- new_echo "Connection '$ip'($USER) " purple "[ SUCCESS ]" green
- new_echo "`date +'%x %X'` " white
- new_echo "--------------------------------- use ${SECONDS}s -----------------------------------------" green
- action 用户:$user-"现在开始登陆,请稍等..............................." /bin/true
- ssh -i "/home/$USER/.ssh/id_rsa" $user@$ip
- fi
- ;;
- 5)
- ip="192.168.3.22"
- public=/home/$USER
- if [ -z $CHECK ]
- then
- clear
- new_echo "----------------------------------------------------------------------------------" green
- new_echo "Connection '$ip'($USER) " purple "[ SUCCESS ]" green
- new_echo "`date +'%x %X'` " white
- new_echo "--------------------------------- use ${SECONDS}s -----------------------------------------" green
- action 用户:$user-"现在开始登陆,请稍等..............................." /bin/true
- ssh -i "/home/$USER/.ssh/id_rsa" $user@$ip
- fi
- ;;
- 6)
- ip="192.168.3.12"
- public=/home/$USER
- if [ -z $CHECK ]
- then
- clear
- new_echo "----------------------------------------------------------------------------------" green
- new_echo "Connection '$ip'($USER) " purple "[ SUCCESS ]" green
- new_echo "`date +'%x %X'` " white
- new_echo "--------------------------------- use ${SECONDS}s -----------------------------------------" green
- action 用户:$user-"现在开始登陆,请稍等..............................." /bin/true
- ssh -i "/home/$USER/.ssh/id_rsa" $user@$ip
- fi
- ;;
- 7)
- ip=192.168.3.16
- public=/home/$USER
- if [ -z $CHECK ]
- then
- clear
- new_echo "----------------------------------------------------------------------------------" green
- new_echo "Connection '$ip'($USER) " purple "[ SUCCESS ]" green
- new_echo "`date +'%x %X'` " white
- new_echo "--------------------------------- use ${SECONDS}s -----------------------------------------" green
- action 用户:$user-"现在开始登陆,请稍等..............................." /bin/true
- ssh -i "/home/$USER/.ssh/id_rsa" $user@$ip
- fi
- ;;
- 8)
- ip=192.168.3.92
- public=/home/$USER
- if [ -z $CHECK ]
- then
- clear
- new_echo "----------------------------------------------------------------------------------" green
- new_echo "Connection '$ip'($USER) " purple "[ SUCCESS ]" green
- new_echo "`date +'%x %X'` " white
- new_echo "--------------------------------- use ${SECONDS}s -----------------------------------------" green
- action 用户:$user-"现在开始登陆,请稍等.............................." /bin/true
- ssh -i "/home/$USER/.ssh/id_rsa" $user@$ip
- fi
- ;;
- 9)
- ip=192.168.3.15
- public=/home/$USER
- if [ -z $CHECK ]
- then
- clear
- new_echo "----------------------------------------------------------------------------------" green
- new_echo "Connection '$ip'($USER) " purple "[ SUCCESS ]" green
- new_echo "`date +'%x %X'` " white
- new_echo "--------------------------------- use ${SECONDS}s -----------------------------------------" green
- action 用户:$user-"现在开始登陆,请稍等..............................." /bin/true
- ssh -i "/home/$USER/.ssh/id_rsa" $user@$ip
- fi
- ;;
- 10)
- ip=192.168.3.23
- public=/home/$USER
- if [ -z $CHECK ]
- then
- clear
- new_echo "----------------------------------------------------------------------------------" green
- new_echo "Connection '$ip'($USER) " purple "[ SUCCESS ]" green
- new_echo "`date +'%x %X'` " white
- new_echo "--------------------------------- use ${SECONDS}s -----------------------------------------" green
- action 用户:$user-"现在开始登陆,请稍等..............................." /bin/true
- ssh -i "/home/$USER/.ssh/id_rsa" $user@$ip
- fi
- ;;
- 11)
- ip=192.168.3.24
- public=/home/$USER
- if [ -z $CHECK ]
- then
- clear
- new_echo "----------------------------------------------------------------------------------" green
- new_echo "Connection '$ip'($USER) " purple "[ SUCCESS ]" green
- new_echo "`date +'%x %X'` " white
- new_echo "--------------------------------- use ${SECONDS}s -----------------------------------------" green
- action 用户:$user-"现在开始登陆,请稍等..............................." /bin/true
- ssh -i "/home/$USER/.ssh/id_rsa" $user@$ip
- fi
- ;;
- 12)
- ip=192.168.3.25
- public=/home/$USER
- if [ -z $CHECK ]
- then
- clear
- new_echo "----------------------------------------------------------------------------------" green
- new_echo "Connection '$ip'($USER) " purple "[ SUCCESS ]" green
- new_echo "`date +'%x %X'` " white
- new_echo "--------------------------------- use ${SECONDS}s -----------------------------------------" green
- action 用户:$user-"现在开始登陆,请稍等..............................." /bin/true
- ssh -i "/home/$USER/.ssh/id_rsa" $user@$ip
- fi
- ;;
- *)
- clear
- action 账户:$USER-"您的输入有误,已退出,请重新登录,谢谢................" /bin/true
- exit
- ;;
- esac
转载于:https://blog.51cto.com/jiechao2012/1149081