linux 安装redis

1.安装gcc  redis是c语言编写的

   yum install gcc-c++

2.下载redis安装包,在root目录下执行

wget http://download.redis.io/releases/redis-6.0-rc3.tar.gz

Redis官网下载

上传(yum install lrzsz)

rz

 

3.解压redis:

tar -zxvf redis-6.0-rc3.tar.gz

4.移动redis:

mv redis-6.0-rc3 /usr/local/redis

5.编译

cd /usr/local/redis
make

6.安装:

make PREFIX=/usr/local/redis install

7.拷贝redis.conf到安装目录(这时本身已经在安装目录了)

cp redis.conf /usr/local/redis

8.编辑redis.conf   

vim redis.conf

    1.后台启动,daemonize yes

    2.绑定端口,port 6379 默认是6379 需要安全组开放端口

    3.绑定IP,bind 192.168.2.128 // bind 127.0.0.1 这行注释掉否则Resis Desktop Manage链接不上

    4.指定数据存放路径,dir /usr/local/redis/log rdb存放的路径[需要创建log文件夹]

    5.指定持久化方式,appendonly yes

    6.requirepass 1234 设置密码

9.后端启动redis:

/usr/local/redis/bin/redis-server ./redis.conf

10.查看是否启动成功:

 ps aux | grep redis

11.设置redis服务启动和关闭

# Date 2020-04-16
# chkconfig: 2345 10 90  
# description: Start and Stop redis   

PATH=/usr/local/redis/src:/sbin:/usr/bin:/bin   
REDISPORT=6379  
EXEC=/usr/local/redis/src/redis-server   
REDIS_CLI=/usr/local/redis/src/redis-cli   

PIDFILE=/var/run/redis.pid   
CONF="/usr/local/redis/redis.conf"  
AUTH="xin123456"  
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 脚本

 

给文件添加权限,使用脚本文件可以执行,命令为:

chmod 755 /etc/init.d/redis

以上工作顺利完成并且没有出现报错,则配置完成,每次我们开机之后都可以输入以下两个命令启动和关闭redis服务:

service redis start
service redis stop

 

在云服务器中添加redis端口的安全组规则

 

 

进入客户端

./bin/redis-cli --raw 处理中文乱码问题

 

 

 

 

 

 

12.关闭redis进程

    1.  ./bin/redis-cli shutdown

    2. kill -9 pid 进程

  • 查看虚拟机的ip
  • ifconfig

 

posted @ 2020-04-16 15:47  wfpanskxin  阅读(320)  评论(0编辑  收藏  举报