shell脚本一键部署——redis安装部署(含可复制代码)

安装redis

在执行脚本前,需配好yum源,本地或者在线源,并将安装包传入/opt/目录下

 脚本内容如下:

 

 1 #!/bin/bash
 2 #安装redis
 3 read -p "请输入本机IP地址:" ip
 4 
 5 systemctl stop firewalld
 6 setenforce 0
 7 
 8 #安装gcc gcc-c++ 编译器
 9 yum install -y gcc gcc-c++ make &> /dev/null
10 if [ $? -eq 0 ];then
11 echo -e  "\033[34;1m 编译器安装完成! \033[0m"
12 fi
13 
14 #将redis-5.0.7.tar.gz压缩包上传到/opt目录中,解压,并编译安装
15 cd /opt
16 tar zxvf redis-5.0.7.tar.gz -C /opt/ &> /dev/null
17 cd /opt/redis-5.0.7/
18 make &> /dev/null
19 make PREFIX=/usr/local/redis install &> /dev/null 
20 if [ $? -eq 0 ];then
21 echo -e  "\033[34;1m redis编译安装完成! \033[0m"
22 fi
23 
24 #执行软件包提供的installserver.sh脚本文件设置Redis服务所需要的相关配置文件
25 yum -y install expect &> /dev/null
26 /usr/bin/expect <<EOF
27 cd /opt/redis-5.0.7/utils
28 spawn /opt/redis-5.0.7/utils/install_server.sh
29 expect "instance:" {send "\r"}
30 expect "/etc/redis/6379.conf" {send "\r"}
31 expect "/var/log/redis_6379.log" {send "\r"}
32 expect "/var/lib/redis/6379" {send "\r"}
33 expect "path" {send "/usr/local/redis/bin/redis-server\r"}
34 expect "ENTER" {send "\r"}
35 expect eof
36 EOF
37 if [ $? -eq 0 ];then
38 echo -e  "\033[34;1m redis相关配置完成! \033[0m"
39 fi
40 
41 #把redis的可执行程序文件放入路径环境变量的目录中便于系统识别
42 ln -s /usr/local/redis/bin/* /usr/local/bin/
43 netstat -natp | grep redis 
44 
45 # Redis服务控制
46 /etc/init.d/redis_6379 start
47 /etc/init.d/redis_6379 status
48 
49 #修改配置/etc/redis/6379.conf参数
50 sed -i '70s/bind 127.0.0.1/bind 127.0.0.1 '$ip'/' /etc/redis/6379.conf
51 /etc/init.d/redis_6379 restart
52 if [ $? -eq 0 ];then
53 echo -e  "\033[34;1m redis安装完成! \033[0m"
54 fi
55 netstat -natp | grep redis

 执行结果如下:

 

 

posted on 2021-09-17 14:29  笑洋仟  阅读(1027)  评论(0编辑  收藏  举报

levels of contents