• CentOS 6.5 安装 Redis-3.2.6


    到官网下载最新版的 Redis-3.2.6

    我把它放到文件夹:/usr/local/src/centos-sdk/source2/redis

    安装脚本 redis-3.2.6.sh

    #!/bin/bash
    PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin
    export PATH
    
    
    if [[ $EUID -ne 0 ]]; then
    	echo "This script must be run as root"
    	exit 1
    fi
    
    setenforce 0  # 临时禁用,不需要重启(推荐)。
    
    
    ##################################################
    ### 安装 工具
    ##################################################
    yum install gcc-c++
    yum install -y tcl
    yum install wget
    
    ##################################################
    ### 安装 redis
    ##################################################
    cd /usr/local/src/centos-sdk/source2/redis
    tar -xzvf ./redis-3.2.6.tar.gz
    
    mkdir -pv /usr/local/redis/redis-3.2.6
    cp -rf ./redis-3.2.6/* /usr/local/redis/redis-3.2.6
    cd /usr/local/redis/redis-3.2.6
    
    # 测试 redis
    make
    cd src
    make test
    
    # 配置 redis
    mkdir /usr/local/redis/redis-3.2.6/etc
    cp -rf /usr/local/src/centos-sdk/config/redis-3.2.6/redis.conf /usr/local/redis/reids-3.2.6/etc/redis.conf
    
    # 开机启动(已弃用)
    # echo "/usr/local/redis/redis-3.2.6/src/redis-server /usr/local/redis/redis-3.2.6/etc/redis.conf &" >> /etc/rc.local
    
    # 启动 redis(已弃用)
    # /usr/local/redis/redis-3.2.6/src/redis-server /usr/local/redis/redis-3.2.6/etc/redis.conf &
    
    # 设置 redis 开机启动
    cp -rf /usr/local/src/centos-sdk/config/redis-3.2.6/redis.init  /etc/rc.d/init.d/redis # 拷贝redis.init到启动目录
    chmod +x /etc/rc.d/init.d/redis # 添加执行权限
    chkconfig redis on # 设置开机启动
    
    service redis start  # 启动 redis
    
    

    /usr/local/redis/reids-3.2.6/etc/redis.conf 内容如下:

    bind 127.0.0.1
    protected-mode yes
    port 6379
    tcp-backlog 511
    timeout 0
    tcp-keepalive 300
    daemonize yes
    supervised no
    pidfile /var/run/redis.pid
    loglevel notice
    logfile ""
    databases 16
    save 900 1
    save 300 10
    save 60 10000
    stop-writes-on-bgsave-error yes
    rdbcompression yes
    rdbchecksum yes
    dbfilename dump.rdb
    dir /usr/local/redis/data
    slave-serve-stale-data yes
    slave-read-only yes
    repl-diskless-sync no
    repl-diskless-sync-delay 5
    repl-disable-tcp-nodelay no
    slave-priority 100
    requirepass 52php-wenjianbao
    maxclients 1024
    maxmemory 1GB
    maxmemory-policy allkeys-lru
    appendonly yes
    appendfilename "appendonly.aof"
    appendfsync everysec
    no-appendfsync-on-rewrite no
    auto-aof-rewrite-percentage 100
    auto-aof-rewrite-min-size 64mb
    aof-load-truncated yes
    lua-time-limit 5000
    slowlog-log-slower-than 10000
    slowlog-max-len 128
    latency-monitor-threshold 0
    notify-keyspace-events ""
    hash-max-ziplist-entries 128
    hash-max-ziplist-value 1024
    list-max-ziplist-size -2
    list-compress-depth 0
    set-max-intset-entries 512
    zset-max-ziplist-entries 128
    zset-max-ziplist-value 64
    hll-sparse-max-bytes 3000
    activerehashing yes
    client-output-buffer-limit normal 0 0 0
    client-output-buffer-limit slave 256mb 64mb 60
    client-output-buffer-limit pubsub 32mb 8mb 60
    hz 10
    aof-rewrite-incremental-fsync yes

    更详细的介绍:Redis-3.2.6 配置文件中文翻译

    /etc/init.d/redis 文件内容如下

    # chkconfig: 2345 10 90
    # description: Start and Stop redis
    
    PATH=/usr/local/bin:/sbin:/usr/bin:/bin
    
    REDISPORT=6379 # 端口
    EXEC=/usr/local/redis/redis-3.2.6/src/redis-server # 服务程序
    REDIS_CLI=/usr/local/redis/redis-3.2.6/src/redis-cli # 命令行程序
    
    PIDFILE=/var/run/redis.pid
    CONF="/usr/local/redis/redis-3.2.6/etc/redis.conf" # 配置文件
    
    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
    			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: $0 {start|stop|restart|force-reload}" >&2
    		exit 1
    esac
    
    
    

    延伸阅读:

    Mac Pro 编译安装 Redis-3.2.3

  • 相关阅读:
    【linux命令 】chmod设置权限 + chown设置属主和属组 + 文件特殊权限(SUID、SGID、SBIT)
    【linux命令】chgrp改变文件或目录的属组
    【Linux命令】setfacl、getfacl命令基本用法(文件权限全文控制列表acl)
    【linux命令】权限管理命令(chattr、lsattr、sudo)
    【linux运维】linux系统上忘记密码如何操作
    【zibbix自定义监控】zabbix服务自定义监控mysql的状态信息
    【zabbix告警配置】zabbix服务配置邮件告警
    【mail邮件系统】linux上安装部署sendmail邮件系统
    【nginx+keepalived】nginx+keepalived搭建高可用
    【Linux命令】centos防火墙使用和配置
  • 原文地址:https://www.cnblogs.com/52php/p/6214975.html
Copyright © 2020-2023  润新知