新手安装redis过程

安装redis过程

  1. 先用root账户登录centos7

  2. 运行 yum install gcc 命令 安装redis所需要的jar包以及依赖

  3. 
    

    下载redis安装包

    wget http://download.redis.io/releases/redis-4.0.6.tar.gz
    
    
    1. 解压安装包

      tar -zxvf redis-4.0.6.tar.gz
      
    2. 因为实在~目录下下载redis安装包,所以redis复制到/usr/local/文件夹下面

      [root@localhost ~]# cp -a redis-4.0.6 /usr/local/
      
      
    3. 进入~文件夹下面删除压缩包以及解压包

rm -rf redis-4.0.6.tar.gz      rm  -rf 强制递归删除不提示   rm -r 递归删除  rm -f 强制删除文件不提示

7.跳转到redis文件夹下 编译安装

make MALLOC=libc

8.将/usr/local/redis-4.0.6/src目录下的文件加到/usr/local/bin目录

cd src && make install

redis 的启动方法

先切换到redis src目录下 直接启动 ./redis-server

[root@localhost src]# ./redis-server
9297:C 26 Jul 13:49:36.369 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
9297:C 26 Jul 13:49:36.370 # Redis version=4.0.6, bits=64, commit=00000000, modified=0, pid=9297, just started
9297:C 26 Jul 13:49:36.370 # Warning: no config file specified, using the default config. In order to specify a config file use ./redis-server /path/to/redis.conf
9297:M 26 Jul 13:49:36.370 * Increased maximum number of open files to 10032 (it was originally set to 1024).
                _._                                                  
           _.-``__ ''-._                                             
      _.-``    `.  `_.  ''-._           Redis 4.0.6 (00000000/0) 64 bit
  .-`` .-```.  ```\/    _.,_ ''-._                                   
 (    '      ,       .-`  | `,    )     Running in standalone mode
 |`-._`-...-` __...-.``-._|'` _.-'|     Port: 6379
 |    `-._   `._    /     _.-'    |     PID: 9297
  `-._    `-._  `-./  _.-'    _.-'                                   
 |`-._`-._    `-.__.-'    _.-'_.-'|                                  
 |    `-._`-._        _.-'_.-'    |           http://redis.io        
  `-._    `-._`-.__.-'_.-'    _.-'                                   
 |`-._`-._    `-.__.-'    _.-'_.-'|                                  
 |    `-._`-._        _.-'_.-'    |                                  
  `-._    `-._`-.__.-'_.-'    _.-'                                   
      `-._    `-.__.-'    _.-'                                       
          `-._        _.-'                                           
              `-.__.-'                                               

9297:M 26 Jul 13:49:36.372 # WARNING: The TCP backlog setting of 511 cannot be enforced because /proc/sys/net/core/somaxconn is set to the lower value of 128.
9297:M 26 Jul 13:49:36.372 # Server initialized
9297:M 26 Jul 13:49:36.372 # WARNING overcommit_memory is set to 0! Background save may fail under low memory condition. To fix this issue add 'vm.overcommit_memory = 1' to /etc/sysctl.conf and then reboot or run the command 'sysctl vm.overcommit_memory=1' for this to take effect.
9297:M 26 Jul 13:49:36.372 # WARNING you have Transparent Huge Pages (THP) support enabled in your kernel. This will create latency and memory usage issues with Redis. To fix this issue run the command 'echo never > /sys/kernel/mm/transparent_hugepage/enabled' as root, and add it to your /etc/rc.local in order to retain the setting after a reboot. Redis must be restarted after THP is disabled.
9297:M 26 Jul 13:49:36.372 * Ready to accept connections

按Ctrl +c 关闭

2 .以后台进程方式启动redis 较为方便

  1. 第一步:修改redis.conf文件

    #修改daemonize为yes,即默认以后台程序方式运行(还记得前面手动使用&号强制后台运行吗)。
    daemonize no
    

​ 2.启动Redis 在src文件夹下

[root@localhost src]# ./redis-server /usr/local/redis-4.0.6/redis.conf
9432:C 26 Jul 13:58:20.860 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
9432:C 26 Jul 13:58:20.860 # Redis version=4.0.6, bits=64, commit=00000000, modified=0, pid=9432, just started
9432:C 26 Jul 13:58:20.860 # Configuration loaded
[root@localhost src]# 

3.关闭redis进程

首先使用ps -aux | grep redis查看redis进程

[root@localhost src]# ps -aux | grep redis
root      9433  0.0  0.1 141812  2024 ?        Ssl  13:58   0:00 ./redis-server 127.0.0.1:6379
root      9512  0.0  0.0 112724   996 pts/2    R+   14:01   0:00 grep --color=auto redis

  1. 设置开机自启

    1、在/etc目录下新建redis目录

    mkdir redis

    2、将/usr/local/redis-4.0.6/redis.conf 文件复制一份到/etc/redis目录下

    cp /usr/local/redis-4.0.6/redis.conf /etc/redis/6379.conf
    

    3、将redis的启动脚本复制一份放到/etc/init.d目录下

    cp /usr/local/redis-4.0.6/utils/redis_init_script /etc/init.d/redisd
    

    4、设置redis开机自启动

    先切换到/etc/init.d目录下

    然后执行自启命令

    chkconfig redisd on
    service redisd does not support chkconfig 
    
  2. 出现-rwxr-xr-x. 1 root root 1098 7月 26 14:07 redisd
    [root@localhost init.d]# chkconfig redisd on
    服务 redisd 不支持 chkconfig
    [root@localhost init.d]# chkconfig redisd on service redisd does not support chkconfig
    服务 redisd 不支持 chkconfig

  3. 看结果是redisd不支持chkconfig

    解决方法:

    使用vim编辑redisd文件,在第一行加入如下两行注释,保存退出

    # chkconfig:   2345 90 10
    # description:  Redis is a persistent key-value database
    

再次执行开机自启命令,成功 chkconfig redisd on

7.现在可以直接已服务的形式启动和关闭redis了

启动:

service redisd start

如果出现

service redisd start
/var/run/redis_6379.pid exists, process is already running or crashed

两种方法:

1:可用安装文件启动 redis-server /etc/redis/6379.conf

2:shutdown -r now 软重启让系统自动恢复下就行了

redis默认客户端 6379

连接windows上的Desktopredismanager

因为redis的防火墙没有打开,而且我的虚拟机是用centos07,centoso7已经用firewall防火墙替代了IPtables

firewall-cmd --zone=public --add-port=6379/tcp --permanent   利用这个命令打开6379端口
firewall-cmd --reload  重启防火墙

[https://blog.csdn.net/yidou120/article/details/90482715]:

这个是firewall具体命令

。。。。好像出了点问题

删除 /etc/init.d/redisd 配置文件

并且删除 /etc/redis/6379.conf

然后进入 /usr/local/redis-4.0.6/ 修改redis.conf文件 将bind 127.0.0.1 注释 并将requirepass 解开注释 并加上 root(我的密码) 然后进入redis-4.0.6 下面的src文件夹 ./redis-server /usr/local/redis-4.0.6/redis.conf启动redis,然后用redis-cli命令进入redis自带操作界面用auth root验证密码是否正确 正确会显示ok 就可以连接上redisdesktopmanager了。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值