shell脚本一键安装redis

post by rocdk890 / 2017-4-1 16:02 Saturday linux技术
  最近打算把需要经常安装的东西都写成一键脚本安装,这样方便自己,也方便大家.
  系统:centos 7.x(64位)
  软件:redis 3.0.7

cat /root/soft_shell/auto_install_redis.sh
#!/bin/bash
PATH=/bin:/sbin:/usr/bin:/usr/sbin:/opt/bin:/opt/sbin:~/bin
export PATH

# Check if user is root
if [ $(id -u) != "0" ]; then
    echo "Error: You must be root to run this script, please use root to install"
    exit 1
fi

# Check the network status
NET_NUM=`ping -c 4 www.baidu.com |awk '/packet loss/{print $6}' |sed -e 's/%//'`
if [ -z "$NET_NUM" ] || [ $NET_NUM -ne 0 ];then
        echo "Please check your internet"
        exit 1
fi

if [ -s redis-3.0.7.tar.gz ];then
	echo -e "\033[40;31m redis-3.0.7.tar.gz [found]\033[40;37m"
else
	wget http://download.redis.io/releases/redis-3.0.7.tar.gz
	#wget http://download.slogra.com/redis/redis-3.0.7.tar.gz
fi

yum -y install gcc gcc-c++ make
user_redis=`cat /etc/passwd|grep redis|awk -F : '{print $1}'`
if [ -z "$user_redis" ];then
	useradd -s /bin/false -M redis
else
	echo "user redis already exists!"
fi

read -p "Enter redis port:" redis_port
mkdir -p /data/redis/member-$redis_port/{conf,data,log,pid}
tar zxf redis-3.0.7.tar.gz -C /usr/local/
cd /usr/local/
mv redis-3.0.7 redis
cd /usr/local/redis/
make && make install

cp /usr/local/redis/redis.conf /data/redis/member-$redis_port/conf/
chown -R redis.redis /data/redis/member-$redis_port
cat >/data/redis/member-$redis_port/conf/redis.conf <<EOF
daemonize yes
pidfile /data/redis/member-$redis_port/pid/redis.pid
port $redis_port
tcp-backlog 65535
bind 127.0.0.1
timeout 0
tcp-keepalive 0
loglevel notice
logfile /data/redis/member-$redis_port/log/redis.log
databases 16
lua-time-limit 5000
maxclients 10000
#protected-mode yes
dir /data/redis/member-$redis_port/data

###慢日志参数###
slowlog-log-slower-than 10000
slowlog-max-len 128

###内存参数###
maxmemory 8G
maxmemory-policy volatile-lru

###RDB持久化参数###
save 3600 1
stop-writes-on-bgsave-error yes
rdbcompression yes
rdbchecksum yes
dbfilename dump.rdb

###AOF持久化参数###
no-appendfsync-on-rewrite yes
appendonly yes
appendfilename "appendonly.aof"
appendfsync no
auto-aof-rewrite-min-size 512mb
auto-aof-rewrite-percentage 100
aof-load-truncated yes
aof-rewrite-incremental-fsync yes

###客户端Buffer参数###
client-output-buffer-limit normal 0 0 0
client-output-buffer-limit slave 256mb 64mb 60
client-output-buffer-limit pubsub 32mb 8mb 60

###其他参数###
hash-max-ziplist-entries 512
hash-max-ziplist-value 64
list-max-ziplist-entries 512
list-max-ziplist-value 64
set-max-intset-entries 512
zset-max-ziplist-entries 128
zset-max-ziplist-value 64
hll-sparse-max-bytes 3000
activerehashing yes
latency-monitor-threshold 0
hz 10
EOF

echo 'export PATH=$PATH:/usr/local/bin' >>/etc/profile

source /etc/profile

sudo -u redis `which redis-server` /data/redis/member-$redis_port/conf/redis.conf
夜空- 本站版权
1、本站所有主题由该文章作者发表,该文章作者与夜空享有文章相关版权
2、其他单位或个人使用、转载或引用本文时必须同时征得该文章作者和夜空的同意
3、本帖部分内容转载自其它媒体,但并不代表本站赞同其观点和对其真实性负责
4、如本帖侵犯到任何版权问题,请立即告知本站,本站将及时予与删除并致以最深的歉意
5、原文链接:blog.slogra.com/post-695.html

标签: centos 安装 shell redis install 一键 自动 auto

评论: