redis系列01:源码安装redis-3.2.10

前段时间安装好的redis,今天用脚本安装的时候突然出现版本异常的问题,所以更新一篇为大家提供参考

本次安装在CentOS6.5,采用的redis-3.2.10,最新的redis-4.0.1安装同样适用,不过由于4.0.1版本的redis改动较大,大家自己选择即可。,

1.基础环境配置,上传安装包

useradd redis -s /sbin/nologin -M
mkdir -p /server/tools/
cd /server/tools/

2.安装redis,配置开机自启动

# 解压,编译安装

tar -zxf redis-3.2.10.tar.gz
cd redis-3.2.10
make PREFIX=/usr/local/redis
make PREFIX=/usr/local/redis install

# 配置环境变量,便于命令工具的调用访问

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

# 手动创建标准目录结构,操作规范化

mkdir -p /usr/local/redis/{conf,data,logs}
/bin/cp /server/tools/redis-3.2.10/redis.conf /usr/local/redis/conf/redis.conf.oritree /usr/local/redis

# 创建修改配置文件

cd /usr/local/redis/conf
egrep -v "^#|^$" redis.conf.ori>redis.confcat redis.conf

# 默认生效的配置如下:

bind 127.0.0.1
protected-mode yes
port 6379
tcp-backlog 511
timeout 0
tcp-keepalive 300
daemonize no
supervised no
pidfile /var/run/redis_6379.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 ./
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
appendonly no
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 512
hash-max-ziplist-value 64
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

# 修改配置文件

vim redis.conf

# 确认以下必要的配置,修改完毕后的配置文件可以作为模板,用于创建新的redis实例

bind 0.0.0.0port 6379
daemonize yes
pidfile /usr/local/redis/logs/redis.pid
logfile /usr/local/redis/logs/redis.log
dir /usr/local/redis/data
dbfilename redis.rdb

# 内核参数调优(临时)

echo never > /sys/kernel/mm/transparent_hugepage/enabled
echo 511 > /proc/sys/net/core/somaxconn
cat /sys/kernel/mm/transparent_hugepage/enabled
cat /proc/sys/net/core/somaxconn
echo "vm.overcommit_memory = 1" >>/etc/sysctl.conf
sysctl -p

# 启动redis,并查看redis启动状态

/usr/local/redis/bin/redis-server /usr/local/redis/conf/redis.conf
ps -ef |grep redis
netstat -anptl |grep redis
[[email protected] conf]# cat /usr/local/redis/logs/redis.log
6003:M 04 Sep 21:10:39.252 * Increased maximum number of open files to 10032 (it was originally set to 1024).
                _._
           _.-``__ ‘‘-._
      _.-``    `.  `_.  ‘‘-._           Redis 3.2.10 (00000000/0) 64 bit
  .-`` .-```.  ```\/    _.,_ ‘‘-._
 (    ‘      ,       .-`  | `,    )     Running in standalone mode
 |`-._`-...-` __...-.``-._|‘` _.-‘|     Port: 6379
 |    `-._   `._    /     _.-‘    |     PID: 6003
  `-._    `-._  `-./  _.-‘    _.-‘
 |`-._`-._    `-.__.-‘    _.-‘_.-‘|
 |    `-._`-._        _.-‘_.-‘    |           http://redis.io
  `-._    `-._`-.__.-‘_.-‘    _.-‘
 |`-._`-._    `-.__.-‘    _.-‘_.-‘|
 |    `-._`-._        _.-‘_.-‘    |
  `-._    `-._`-.__.-‘_.-‘    _.-‘
      `-._    `-.__.-‘    _.-‘
          `-._        _.-‘
              `-.__.-‘                                               

6003:M 04 Sep 21:10:39.255 # Server started, Redis version 3.2.10
6003:M 04 Sep 21:10:39.255 * The server is now ready to accept connections on port 6379

# 连接redis,进行测试

[[email protected] conf]# /usr/local/redis/bin/redis-cli -p 6379
127.0.0.1:6379> set a 1
OK
127.0.0.1:6379> set b 2
OK
127.0.0.1:6379> set c 3
OK
127.0.0.1:6379> get a
"1"
127.0.0.1:6379> get b
"2"
127.0.0.1:6379> get c
"3"
127.0.0.1:6379> exit
[[email protected]-server conf]# 

# 安全关闭redis-server

/usr/local/redis/bin/redis-cli shutdown

# 另外,需要设置一下内核参数保证下次重启不会出错

echo " ">> /etc/rc.local
echo "# redis by zhaoshuai in $(date +%F)" >> /etc/rc.local
echo "echo never > /sys/kernel/mm/transparent_hugepage/enabled" >> /etc/rc.local
echo "echo 511 > /proc/sys/net/core/somaxconn" >>/etc/rc.local
tail -4 /etc/rc.local

# 至此,redis-server就安装完成了。

3.创建新的redis实例(端口)

mkdir -p /usr/loca/redis/6380
cd /usr/local/redis/conf
cp redis.conf /usr/loca/redis/6380/6380.confcd /usr/local/redis/6380/

# 编辑配置文件,

vim 6380.conf

# 修改为以下内容:

bind 0.0.0.0
daemonize yes
pidfile /usr/local/redis/6380/pid-6380.pid
logfile /usr/local/redis/6380/log-6380.log
dir /usr/local/redis/6380
dbfilename 6380.rdb......

# 启动redis新实例,如果需要可以设置开机自启动

[[email protected] 6380]# /usr/local/redis/bin/redis-server /usr/local/redis/6380/6380.conf 
[[email protected] 6380]# echo "/usr/local/redis/bin/redis-server /usr/local/redis/6380/6380.conf" >>/etc/rc.local 

4.另附一个redis启动管理脚本,方便大家学习使用

#!/bin/sh
#
# chkconfig:   2345 85 15
# description: this script can manager the redis-server daemon
#              Redis is a persistent key-value database
# exec:        /usr/local/redis/bin/redis-server
# config:      /usr/local/redis/conf/redis.conf
# pidfile:     /usr/local/redis/logs/redis.pid
# datafile:    /usr/local/redis/data/redis.rdb  

redis="/usr/local/redis/bin/redis-server"
REDIS_CONF_FILE="/usr/local/redis/conf/redis.conf"
prog=$(basename $redis)
lockfile=/var/lock/subsys/redis

# Source function library.
. /etc/rc.d/init.d/functions

# Source networking configuration.
. /etc/sysconfig/network

# Check that networking is up.
[ "$NETWORKING" = "no" ] && exit 0

start() {
    [ -x $redis ] || exit 5
    [ -f $REDIS_CONF_FILE ] || exit 6
    echo -n $"Starting $prog: "
    daemon $redis $REDIS_CONF_FILE
    retval=$?
    echo
    [ $retval -eq 0 ] && touch $lockfile
    return $retval
}
stop() {
    echo -n $"Stopping $prog: "
    killproc $prog -QUIT
    retval=$?
    echo
    [ $retval -eq 0 ] && rm -f $lockfile
    return $retval
}
restart() {
    stop
    start
}
reload() {
    echo -n $"Reloading $prog: "
    killproc $redis -HUP
    RETVAL=$?
    echo
}
rh_status() {
    status $prog
}
rh_status_q() {
    rh_status >/dev/null 2>&1
}
case "$1" in
    start)
        rh_status_q && exit 0
        $1
        ;;
    stop)
        rh_status_q || exit 0
        $1
        ;;
    restart)
        $1
        ;;
    reload)
        rh_status_q || exit 7
        $1
        ;;
    status)
        rh_status
        ;;
    *)
        echo $"Usage: $0 {start|stop|restart|reload|status}"
        exit 2
esac

# 完毕,呵呵呵

时间: 2024-10-24 15:42:21

redis系列01:源码安装redis-3.2.10的相关文章

centos6.5 64 源码安装redis服务,建立可远程连接的redis数据库

安装环境:centos6.5 64位 使用的包:redis-2.8.19.tar.gz  tcl8.6.3-src.tar.gz 包的下载链接:http://downloads.sourceforge.net/tcl/tcl8.6.3-src.tar.gz http://download.redis.io/releases/redis-2.8.19.tar.gz 本次安装的目录/home/hadoop/redis为任意目录 代码实现: 1,安装需要的支持环境 su root cd /home/h

MySQL系列 - MySQL源码安装配置

二.MySQL系列 - MySQL源码安装配置(附5.7等最新版本)1.依赖环境准备2.开始安装2.1.下载MySQL2.2.解压2.3.赋权限2.4.修改配置文件2.5.启动MySQL3.MySQL 5.7源码安装不同之处 二.MySQL系列 - MySQL源码安装配置(附5.7等最新版本) 1.依赖环境准备 make安装 make编译器下载地址:http://www.gnu.org/software/make/ # tar zxvf make-3.82.tar.gz # cd make-3.

搭建LNAMP环境(五)- PHP7源码安装Redis和Redis拓展

上一篇:搭建LNAMP环境(四)- 源码安装PHP7 一.安装Redis 1.创建redis用户组和用户 groupadd redis useradd -r -g redis -s /sbin/nologin -M redis 2.下载redis源码包,将源码包放到/usr/local/src/目录下 下载页面:http://redis.io/download这里用的是redis-3.2.5.tar.gz下载地址:http://download.redis.io/releases/redis-3

源码安装redis环境

linux下安装redis 1.下载源码,解压包后编译源码: wget http://download.redis.io/releases/redis-2.8.3.tar.gz tar xzf redis-2.8.3.tar.gz cd redis-2.8.3 make 2.编译完成后,在src目录下有四个可执行的文件 redis-server.redis-benchmark.redis-cli和redis.conf(不在src目录下).然后拷贝到一个目录下. 3.创建bin和redis.con

redis 3.0源码安装详细步骤详细说明

到官网下载,然后在服务器上执行 tar zxvf redis-3.0.4.tar.gz cd redis-3.0.4make cd  src ./redis-server启动redis make一下即可完成安装.通过redis-cli 进入执行ping显示pong就说明安装成功了. 不过redis推荐下面这些深层次的安装配置. mak test注意,执行make完成之后redis会提示Hint: It's a good idea to run 'make test' ;) 执行一下即可.cd s

Centos6.7源码安装 redis

演示环境 系统:Linux CentOS 6.7 64位 账号:root 环境:无安装 redis 官网下载redis3.0.7 这是目前的最新版本 http://www.redis.cn/ 首先进入到下载好的redis目录里 [[email protected]]# tar xf redis-3.0.7.tar.gz //解压压缩包 进入解压出来的目录里,执行make编译,注意编译前系统一定要安装gcc软件包,不然编译的时候会报错的. [[email protected]]# make 注意:

centos7源码安装redis

下载: https://redis.io/ 解压: tar -xzf redis-5.0.3.tar.gz 进入目录: cd redis-5.0.3 编译: make 创建配置文件:vim /etc/redis.conf port 7000 bind 0.0.0.0 requirepass 123456 daemonize yes pidfile /var/run/redis.pid appendonly no 启动服务: src/redis-server /etc/redis.conf 停止服

Centos 6.3下使用源码安装Mysql 5.7.10

最近想尝试下新版本的Mysql 5.7.10,于是开始尝试玩下. 在该次安装中,使用源码编译安装Mysql,编译器使用cmake.这里选择的版本是mysql-5.7.10,cmake的版本是cmake-2.8.10.2注:在下载源码包的时候,请注意选择Platform为“Source Code”.环境:[[email protected] mysql]$ sudo cat /etc/redhat-releaseCentOS release 6.3 (Final)[[email protected

搭建LNAMP环境(四)- 源码安装PHP7

上一篇:搭建LNAMP环境(三)- 源码安装Apache2.4 一.安装PHP7 1.yum安装编译php需要的包 yum -y install libxml2 libxml2-devel curl-devel libpng-devel freetype-devel libmcrypt-devel libjpeg-devel 2.创建php用户组和用户 groupadd php useradd -r -g php -s /sbin/nologin -M php 3.下载php源码包,将源码包放到

搭建LNAMP环境(六)- PHP7源码安装MongoDB和MongoDB拓展

上一篇:搭建LNAMP环境(五)- PHP7源码安装Redis和Redis拓展 一.安装MongoDB 1.创建mongodb用户组和用户 groupadd mongodb useradd -r -g mongodb -s /sbin/nologin -M mongodb 2.下载mongodb源码包,并将源码包放到/usr/local/src/目录下下载页面:https://www.mongodb.com/download-center?jmp=nav这里用的是 mongodb-linux-x