CentOS 6编译安装Redis

[root@localhost ~]# vim /etc/sysconfig/iptables
# 添加如下:-A INPUT -m state –state NEW -m tcp -p tcp –dport 6379 -j ACCEPT(允许6379端口通过防火墙)
[root@localhost ~]# /etc/init.d/iptables restart

安装过程

[root@localhost ~]# tar -zxvf redis-3.0.5.tar.gz
[root@localhost ~]# cd redis-3.0.5
[root@localhost redis-3.0.5]# make  # 编译

make命令包含了redis安装过程,安装成功后会在src目录下生成5个可执行文件

  1. redis-server:Redis服务器的daemon启动程序
  2. redis-cli:Redis命令行操作工具。当然,你也可以用telnet根据其纯文本协议来操作
  3. redis-benchmark:Redis性能测试工具,测试Redis在你的系统及你的配置下的读写性能
  4. redis-check-aof:更新日志检查
  5. redis-check-dump:用于本地数据库检查
[root@localhost redis-3.0.5]# make PREFIX=/usr/local/redis install
# redis安装到 /usr/local/redis/下面
[root@localhost redis-3.0.5]# mkdir -p /data/redisdb  # 创建redis数据存放目录

# 修改配置文件
[root@localhost redis-3.0.5]# cp ./redis.conf /usr/local/redis/
[root@localhost redis-3.0.5]# vim /usr/local/redis/redis.conf

# 运行、开启Redis
[root@localhost redis-3.0.5]# /usr/local/redis/bin/redis-server

# 进入Redis客户端,进行操作
[root@localhost redis-3.0.5]# /usr/local/redis/bin/redis-cli

# 关闭Redis
[root@localhost redis-3.0.5]# /usr/local/redis/bin/redis-cli shutdown

  

将Redis加入服务开机自启动

[root@localhost redis-3.0.5]# vim /etc/init.d/redis

添加如下脚本内容:

# chkconfig: 2345 90 10
# description: service of redis for start and stop add by tomener
  
PATH=/usr/local/bin:/sbin:/usr/bin:/bin
REDISPORT=6379
EXEC=/usr/local/redis/bin/redis-server
REDIS_CLI=/usr/local/redis/bin/redis-cli
 
PIDFILE=/var/run/redis.pid   
CONF="/usr/local/redis/redis.conf"
AUTH="1234"

case "$1" in   
        start)   
                if [ -f $PIDFILE ]   
                then   
                        echo "$PIDFILE exists, process is already running or crashed."  
                else  
                        echo "Starting Redis server..."  
                        $EXEC $CONF   
                fi   
                if [ "$?"="0" ]   
                then   
                        echo "Redis is running..."  
                fi   
                ;;   
        stop)   
                if [ ! -f $PIDFILE ]   
                then   
                        echo "$PIDFILE exists, process is not running."  
                else  
                        PID=$(cat $PIDFILE)   
                        echo "Stopping..."  
                       $REDIS_CLI -p $REDISPORT  SHUTDOWN    
                        sleep 2  
                       while [ -x $PIDFILE ]   
                       do  
                                echo "Waiting for Redis to shutdown..."  
                               sleep 1  
                        done   
                        echo "Redis stopped"  
                fi   
                ;;   
        restart|force-reload)   
                ${0} stop   
                ${0} start   
                ;;   
        *)   
               echo "Usage: /etc/init.d/redis {start|stop|restart|force-reload}" >&2  
                exit 1  
esac

  

# 配置内核参数,等Redis脚本在重启或停止redis的时候,能够提前同步数据到磁盘中(防止报错)
[root@localhost ~]# vim /etc/sysctl.conf
添加如下: vm.overcommit_memory = 1
[root@localhost ~]# sysctl -p   # 使添加的数据生效
[root@localhost redis-3.0.5]# chmod 0755 /etc/init.d/redis
[root@localhost redis-3.0.5]# chkconfig --add redis   # 加入Linux服务
[root@localhost redis-3.0.5]# chkconfig --level 235 redis on  # 设置开机启动

# Redis的开启、关闭、重启
[root@localhost redis-3.0.5]# service redis start|stop|restart

  

posted @ 2019-11-18 15:42  让我们荡起双桨!  阅读(556)  评论(0编辑  收藏  举报