# 定义变量 down_link="https://download.redis.io/releases/redis-${RD_VERSION}.tar.gz" local redis_port=$((RANDOM + 1000)) local redis_pass=$(openssl rand -base64 30) local redis_dir='/data/redis' local redis_down_dir='/usr/local/src' local redis_id="$(basename "${down_link}")" local redis_id_version="$(basename "${redis_down_dir}/${redis_id}" .tar.gz)" local server_ip_addr=$(hostname -i | cut -d ' ' -f1)
# 下载和解压Redis wget -O "${redis_down_dir}/${redis_id}""${down_link}" tar -zxf "${redis_down_dir}/${redis_id}" -C "${redis_down_dir}/"
# 编译和安装Redis mv"${redis_down_dir}/${redis_id_version}""${redis_dir}/${redis_port}" && cd"${redis_dir}/${redis_port}" && make
# 复制文件到相应目录 cp -a "${redis_dir}/${redis_port}/src/redis-"{benchmark,check-aof,check-rdb,cli,sentinel,server} "${redis_dir}/${redis_port}/bin" cp -a "${redis_dir}/${redis_port}/redis.conf""${redis_dir}/${redis_port}/etc/"
# 修改配置文件 sed -i "s/^port 6379/port ${redis_port}/""${redis_dir}/${redis_port}/etc/redis.conf" sed -i 's/^daemonize no/daemonize yes/'"${redis_dir}/${redis_port}/etc/redis.conf" sed -i "s#^logfile \"\"#logfile \"${redis_dir}/${redis_port}/var/redis_${redis_port}.log\"#""${redis_dir}/${redis_port}/etc/redis.conf" sed -i "s#^pidfile /var/run/redis_6379.pid#pidfile ${redis_dir}/${redis_port}/var/redis_${redis_port}.pid#""${redis_dir}/${redis_port}/etc/redis.conf" sed -i "s@^# maxclients 10000@maxclients 100@""${redis_dir}/${redis_port}/etc/redis.conf" sed -i "s@^# requirepass foobared@requirepass ${redis_pass}@""${redis_dir}/${redis_port}/etc/redis.conf" sed -i "s/^# maxmemory <bytes>/maxmemory 2G/""${redis_dir}/${redis_port}/etc/redis.conf" echo"bind ${server_ip_addr}" >> "${redis_dir}/${redis_port}/etc/redis.conf"