CentOS 7 安装Redis 及部署

1、检查环境

[root@localhost etc]# cat /etc/system-release    
CentOS Linux release 7.3.1611 (Core) 

2、下载redis

http://www.redis.cn/download.html

redis-4.0.10.tar.gz

3、解压redis

[root@localhost redis]# pwd
/usr/local/src/redis
[root@localhost redis]# ll
-rw-r--r--. 1 root root 1738465 Aug 19 06:48 redis-4.0.10.tar.gz
[root@localhost redis]# tar -zxvf redis-4.0.10.tar.gz 

4、文件结构及对解压后的文件进行编译

[root@localhost redis-4.0.10]# pwd
/usr/local/src/redis/redis-4.0.10
[root@localhost redis-4.0.10]# ll
total 300
-rw-rw-r--.  1 root root 162174 Jun 13 04:02 00-RELEASENOTES
-rw-rw-r--.  1 root root     53 Jun 13 04:02 BUGS
-rw-rw-r--.  1 root root   1815 Jun 13 04:02 CONTRIBUTING
-rw-rw-r--.  1 root root   1487 Jun 13 04:02 COPYING
drwxrwxr-x.  6 root root    124 Jun 13 04:02 deps
-rw-rw-r--.  1 root root     11 Jun 13 04:02 INSTALL
-rw-rw-r--.  1 root root    151 Jun 13 04:02 Makefile
-rw-rw-r--.  1 root root   4223 Jun 13 04:02 MANIFESTO
-rw-rw-r--.  1 root root  20543 Jun 13 04:02 README.md
-rw-rw-r--.  1 root root  58766 Jun 13 04:02 redis.conf
-rwxrwxr-x.  1 root root    271 Jun 13 04:02 runtest
-rwxrwxr-x.  1 root root    280 Jun 13 04:02 runtest-cluster
-rwxrwxr-x.  1 root root    281 Jun 13 04:02 runtest-sentinel
-rw-rw-r--.  1 root root   7606 Jun 13 04:02 sentinel.conf
drwxrwxr-x.  3 root root   4096 Jun 13 04:02 src
drwxrwxr-x. 10 root root    167 Jun 13 04:02 tests
drwxrwxr-x.  8 root root   4096 Jun 13 04:02 utils
[root@localhost redis-4.0.10]# make
…………
…………
…………
Hint: It's a good idea to run 'make test' ;)

make[1]: Leaving directory `/usr/local/src/redis/redis-4.0.10/src'
[root@localhost redis-4.0.10]# 

5、安装Redis及完成界面

进入src文件夹

[root@localhost src]# make install
    CC Makefile.dep

Hint: It's a good idea to run 'make test' ;)

    INSTALL install
    INSTALL install
    INSTALL install
    INSTALL install
    INSTALL install
[root@localhost src]# pwd
/usr/local/src/redis/redis-4.0.10/src
[root@localhost src]# 

6、部署

1、为了方便管理,将Redis文件中的conf配置文件和常用命令移动到统一文件中

[root@localhost redis]# pwd
/usr/local/src/redis
[root@localhost redis]# mkdir -p /usr/local/src/redis/bin
[root@localhost redis]# mkdir -p /usr/local/src/redis/etc
[root@localhost redis]# ll
total 1704
drwxr-xr-x. 2 root root       6 Aug 19 07:13 bin
drwxr-xr-x. 2 root root       6 Aug 19 07:13 etc
drwxrwxr-x. 6 root root    4096 Jun 13 04:02 redis-4.0.10
-rw-r--r--. 1 root root 1738465 Aug 19 06:48 redis-4.0.10.tar.gz
[root@localhost redis]# cd redis-4.0.10
[root@localhost redis-4.0.10]# cp redis.conf /usr/local/src/redis/etc/
[root@localhost redis-4.0.10]# cd src/
[root@localhost src]# cp mkreleasehdr.sh redis-benchmark redis-check-aof redis-cli redis-server /usr/local/src/redis/bin/
[root@localhost src]# cd /usr/local/src/redis/etc/

2、修改Redis配置文件

[root@localhost etc]# vim redis.conf


#将daemonize属性改为yes (表明需要在后台运行)
#requirepass cashzhang (修改密码)
#bind 192.168.1.202    (修改ip)

3、启动Redis服务

[root@localhost redis]# ll
total 1704
drwxr-xr-x. 2 root root     112 Aug 19 07:19 bin
drwxr-xr-x. 2 root root      24 Aug 19 07:23 etc
drwxrwxr-x. 6 root root    4096 Aug 19 07:16 redis-4.0.10
-rw-r--r--. 1 root root 1738465 Aug 19 06:48 redis-4.0.10.tar.gz
[root@localhost redis]# cd bin/
[root@localhost bin]# ll
total 16236
-rwxr-xr-x. 1 root root     566 Aug 19 07:19 mkreleasehdr.sh
-rwxr-xr-x. 1 root root 2451048 Aug 19 07:19 redis-benchmark
-rwxr-xr-x. 1 root root 5773280 Aug 19 07:19 redis-check-aof
-rwxr-xr-x. 1 root root 2617144 Aug 19 07:19 redis-cli
-rwxr-xr-x. 1 root root 5773280 Aug 19 07:19 redis-server
[root@localhost bin]# ./redis-server /usr/local/src/redis/etc/redis.conf 
16770:C 19 Aug 07:25:59.055 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
16770:C 19 Aug 07:25:59.055 # Redis version=4.0.10, bits=64, commit=00000000, modified=0, pid=16770, just started
16770:C 19 Aug 07:25:59.055 # Configuration loaded
[root@localhost bin]# 

4、编辑启动脚本

vim /etc/init.d/redis

#!/bin/sh
#
# redis        Startup script for Redis Server
#
# chkconfig: - 80 12
# description: Redis is an open source, advanced key-value store.
#
# processname: redis-server
# config: /usr/local/src/redis/etc/redis.conf
# pidfile: /var/run/redis.pid
source /etc/init.d/functions
BIN="/usr/local/src/redis/bin"
CONFIG="/usr/local/src/redis/etc/redis.conf"
PIDFILE="/var/run/redis.pid"
### Read configuration
[ -r "$SYSCONFIG" ] && source "$SYSCONFIG"
RETVAL=0
prog="redis-server"
desc="Redis Server"
start() {
        if [ -e $PIDFILE ];then
             echo "$desc already running...."
             exit 1
        fi
        echo -n $"Starting $desc: "
        daemon $BIN/$prog $CONFIG
        RETVAL=$?
        echo
        [ $RETVAL -eq 0 ] && touch /var/lock/subsys/$prog
        return $RETVAL
}
stop() {
        echo -n $"Stop $desc: "
        killproc $prog
        RETVAL=$?
        echo
        [ $RETVAL -eq 0 ] && rm -f /var/lock/subsys/$prog $PIDFILE
        return $RETVAL
}
restart() {
        stop
        start
}
case "$1" in
  start)
        start
        ;;
  stop)
        stop
        ;;
  restart)
        restart
        ;;
  condrestart)
        [ -e /var/lock/subsys/$prog ] && restart
        RETVAL=$?
        ;;
  status)
        status $prog
        RETVAL=$?
        ;;
   *)
        echo $"Usage: $0 {start|stop|restart|condrestart|status}"
        RETVAL=1
esac
exit $RETVAL

 

chmod +x /etc/init.d/redis

service redis start
service redis stop

chkconfig --add redis

5、设置环境变量,并使之生效

[root@localhost redis]# vim /etc/profile.d/redis.sh

export REDIS_HOME=/usr/local/src/redis
export PATH=$PATH:$REDIS_HOME/bin

[root@localhost redis]# source /etc/profile.d/redis.sh

6、配置下面的内核参数,否则Redis脚本在重启或停止redis时,将会报错,并且不能自动在停止服务前同步数据到磁盘上/etc/sysctl.conf加上

[root@localhost redis]# vim /etc/sysctl.conf


vm.overcommit_memory = 1


[root@localhost redis]# sysctl -p 
vm.overcommit_memory = 1

7、停止redis

#使用客户端
redis-cli shutdown
#因为Redis可以妥善处理SIGTERM信号,所以直接kill -9也是可以的
kill -9 PID

7、Radis可视化工具

https://redisdesktop.com/download

https://github.com/uglide/RedisDesktopManager

 

部分引用

https://www.cnblogs.com/KunGe-13/p/8340309.html

并做一些修改

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值