注:在执行脚本前,需配好yum源,本地或者在线源,并将安装包传入/opt/目录下
#!/bin/bash #安装redis read -p "请输入本机IP地址:" ip systemctl stop firewalld setenforce 0 #安装gcc gcc-c++ 编译器 yum install -y gcc gcc-c++ make &> /dev/null if [ $? -eq 0 ];then echo -e "\033[34;1m 编译器安装完成! \033[0m" fi #将redis-5.0.7.tar.gz压缩包上传到/opt目录中,解压,并编译安装 cd /opt tar zxvf redis-5.0.7.tar.gz -C /opt/ &> /dev/null cd /opt/redis-5.0.7/ make &> /dev/null make PREFIX=/usr/local/redis install &> /dev/null if [ $? -eq 0 ];then echo -e "\033[34;1m redis编译安装完成! \033[0m" fi #执行软件包提供的installserver.sh脚本文件设置Redis服务所需要的相关配置文件 yum -y install expect &> /dev/null /usr/bin/expect <<EOF cd /opt/redis-5.0.7/utils spawn /opt/redis-5.0.7/utils/install_server.sh expect "instance:" {send "\r"} expect "/etc/redis/6379.conf" {send "\r"} expect "/var/log/redis_6379.log" {send "\r"} expect "/var/lib/redis/6379" {send "\r"} expect "path" {send "/usr/local/redis/bin/redis-server\r"} expect "ENTER" {send "\r"} expect eof EOF if [ $? -eq 0 ];then echo -e "\033[34;1m redis相关配置完成! \033[0m" fi #把redis的可执行程序文件放入路径环境变量的目录中便于系统识别 ln -s /usr/local/redis/bin/* /usr/local/bin/ netstat -natp | grep redis # Redis服务控制 /etc/init.d/redis_6379 start /etc/init.d/redis_6379 status #修改配置/etc/redis/6379.conf参数 sed -i '70s/bind 127.0.0.1/bind 127.0.0.1 '$ip'/' /etc/redis/6379.conf /etc/init.d/redis_6379 restart if [ $? -eq 0 ];then echo -e "\033[34;1m redis安装完成! \033[0m" fi netstat -natp | grep redis