ssh
yum install openssh-server
service sshd start
chkconfig sshd on
iptables
service iptables start
chkconfig iptables on
vi /etc/sysconfig/iptables
-A INPUT -m state --state NEW -m tcp -p tcp --dport 6379 -j ACCEPT
service iptables restart
创建用户
adduser redis
passwd redis
创建存储目录
mkdir /usr/local/redis/
mkdir /usr/local/redis/data
chown redis:redis /usr/local/redis/
chown redis:redis /usr/local/redis/data
su redis
chmod 700 /usr/local/redis/
chmod 700 /usr/local/redis/data
/bin/sh: cc: command not found
sudo yum -y install gcc gcc-c++ libstdc++-devel
make MALLOC=libc
安装redis
su redis
tar xzf redis-4.0.9.tar.gz
ln -s redis-4.0.9 redis #建立一个链接
su root
make install
修改配置
vi /usr/local/redis/reidis/redis.conf
daemonize yes
requirepass foobared
bind 0.0.0.0
protected-mode no
tcp-keepalive 60
appendonly yes
no-appendfsync-on-rewrite yes
dir /usr/local/redis/data
警告解决
3367:M 27 Oct 14:04:42.093 # You requested maxclients of 10000 requiring at least 10032 max file descriptors.
3367:M 27 Oct 14:04:42.093 # Server can’t set maximum open files to 10032 because of OS error: Operation not permitted.
3367:M 27 Oct 14:04:42.093 # Current maximum open files is 4096. maxclients has been reduced to 4064 to compensate for low ulimit. If you need higher maxclients increase ‘ulimit -n’.
vi /etc/security/limits.conf
* soft nofile 65535
* hard nofile 65535
sysctl -p
3426:M 27 Oct 14:28:16.367 # WARNING: The TCP backlog setting of 511 cannot be enforced because /proc/sys/net/core/somaxconn is set to the lower value of 128.
vi /etc/sysctl.conf
net.core.somaxconn= 1024
sysctl -p
3426:M 27 Oct 14:28:16.367 # WARNING you have Transparent Huge Pages (THP) support enabled in your kernel. This will create latency and memory usage issues with Redis. To fix this issue run the command ‘echo never > /sys/kernel/mm/transparent_hugepage/enabled’ as root, and add it to your /etc/rc.local in order to retain the setting after a reboot. Redis must be restarted after THP is disabled.
echo never > /sys/kernel/mm/transparent_hugepage/enabled
vi /etc/rc.local
echo never > /sys/kernel/mm/transparent_hugepage/enabled
reboot
3426:M 27 Oct 14:28:16.367 # WARNING overcommit_memory is set to 0! Background save may fail under low memory condition. To fix this issue add ‘i’ to /etc/sysctl.conf and then reboot or run the command ‘sysctl vm.overcommit_memory=1’ for this to take effect.
vi /etc/sysctl.conf
vm.overcommit_memory = 1
sysctl -p
自启动
cp /usr/local/redis/redis/utils/redis_init_script /etc/rc.d/init.d/redis
vi /etc/rc.d/init.d/redis
### BEGIN INIT INFO
# Provides: redis_6379
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Redis data structure server
# Description: Redis data structure server. See https://redis.io
### END INIT INFO
REDISPORT=6379
EXEC=/usr/local/redis/redis/bin/redis-server
CLIEXEC=/usr/local/redis/redis/bin/redis-cli
PIDFILE=/var/run/redis_${REDISPORT}.pid
CONF="/usr/local/redis/redis/redis.conf"
case "$1" in
start)
if [ -f $PIDFILE ]
then
echo "$PIDFILE exists, process is already running or crashed"
else
echo "Starting Redis server..."
cd /home/redis
su redis -c "$EXEC $CONF"
fi
;;
stop)
if [ ! -f $PIDFILE ]
then
echo "$PIDFILE does not exist, process is not running"
else
PID=$(cat $PIDFILE)
echo "Stopping ..."
cd /home/redis
su redis -c "$CLIEXEC -p $REDISPORT -a foobared shutdown"
while [ -x /proc/${PID} ]
do
echo "Waiting for Redis to shutdown ..."
sleep 1
done
echo "Redis stopped"
fi
;;
*)
echo "Please use start or stop as first argument"
;;
esac
chkconfig --add redis