自动交互安装服务应用,以redis为例

 

#!/bin/bash
#新建preinstall.sh文件,该文件完成安装前的准备
yum install gcc gcc-* wget expect -y #expect是因为后面我们用到,安装后可用来检测内容进行自动交互输入 mkdir -p /software/redis mkdir -p /opt/redis mkdir -p /opt/redis/data/6379 mkdir -p /opt/redis/log touch /opt/redis/log/redis_6379.log cd /software/redis/ wget http://download.redis.io/releases/redis-4.0.9.tar.gz tar -zxvf redis-4.0.9.tar.gz -C /opt/redis cd /opt/redis/redis-4.0.9 make MALLOC=libc cd /opt/redis/redis-4.0.9/src make install

开始安装

#!/usr/bin/expect
#新建startinstall.sh文件,该文件开始正式安装,其中\r是指回车
spawn /opt/redis/redis-4.0.9/utils/install_server.sh    #需要这样写,否则可能识别不出路径
#等待this instance出现,最好在前后也加上*,如下
expect "*this instance*"
#上面的内容出来后就可以自动输入6379了

send "6379\r"
expect "*config file name*"
send "/etc/redis/6379.conf\r"
expect "*log file name*"
send "/opt/redis/log/redis_6379.log\r"
expect "*this instance*"
send "/opt/redis/data/6379\r"
expect "*path*"
send "/usr/local/bin/redis-server\r"
#这里也要检测ENTER
expect "*ENTER*"  
#回车
send "\r"
#最好是检测到这个安装成功后再expect eof

expect "Installation successful!"
expect eof

 

至此,redis已经算是安装好了执行/etc/init.d/redis_6379 start即可开启服务

 

posted on 2018-06-08 16:18  标配的小号  阅读(210)  评论(0编辑  收藏  举报

导航