linux 下redis 安装

 

1. 复制安装文件到linux(xshell直接拖拽或ssh工具),自行创建目录

  如:cd /usr/local/src

    mkdir redis

    cd redis

2. 解压安装文件:

  tar -xvf redis-3.2.8.tar.gz

3. 进入安装文件目录,进行编译和安装

  cd redis-3.2.8

  make

  cd src

  make install (or  :  make PREFIX=/usr/local/src/redis install      #指定安装目录)

  编译过程可能出现的问题:

  1. cc:未找到命令

     下载安装gcc:yum -y install gcc automake autoconf libtool make

  2. zmalloc.h:50:31: error: jemalloc/jemalloc.h: No such file or directory

   zmalloc.h:55:2: error: #error "Newer version of jemalloc required"
          make[1]: *** [adlist.o] Error 1
  原因:分配器allocator会根据MALLOC变量去建立Redis ,默认不是libc而是jemalloc
  执行:make MALLOC=libc
  
4.  启动redis
  配置文件:redis.conf
  vi redis.conf
    daemonize yes #默认为no
    端口配置:
    port:6379    #默认6379
    配置数据库数量:Redis默认开启16个数据库,不能像mysql自定义数据库名称,只能是数值,不能修改。
     databases 16
    配置内存大小:会生成一个和内存大小一样的文件。
     maxmemory 200mb   #在真实环境必须部署,否则物理内存会被耗尽。
               #一般配置200mb/500mb/1gb/2gb。
               #可以分散到多台服务器,和其它业务共享服务器,以充分利用资源。
               #同时因为分散,防止单点故障,造成大量缓存失效。
 
 
   启动:

  redis-server                #默认找redis.conf配置文件

  redis-server &             #上面ctrl+c中断reis会退出,这个不会

  redis-server redis6380.conf #指定配置文件,这样可以启动多个实例

  注意两种启动方式的差异

  ps -ef|grep redis

  root      3511     1  0 16:29 ?   00:00:01 redis-server *:6379

  root      3515     1  0 16:29 ?   00:00:01 redis-server 127.0.0.1:6380

  注释掉redis.conf配置文件中的48行;# bind 127.0.0.1 ::1即可

 

5. 版本

  redis-server –v

  Redis server v=3.2.5 sha=00000000:0 malloc=jemalloc-4.0.3 bits=64 build=e6c4c3113548f6b0

  redis-cli –v

6. 设置访问密码

  默认没有密码,可以随意访问。

  redis速度相当快,在一个较好的服务器下,外部用户每秒可以进行15w此的密码尝试,这意味着必须指定非常强大的密码来防止暴力破解。

  如果要加,打开redis.conf的requirepass 123456          #480行,设置请求密码,这样访问时都需要先登录

  127.0.0.1:6379>auth 123456      #客户端访问方式

  jedis.auth(“123456”);              #jedis访问方式

 

7. 详细信息

  redis-cli

  127.0.0.1:6379> info     #查看当前redis节点的详细配置信息

启动中遇到的问题:

Warning: no config file specified, using the default config. In order to specify a config file use ./redis-server /path/to/redis.conf

警告:没有指定的配置文件。

解决办法: ./redis-server /usr/local/src/redis-3.2.8/redis.conf


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.

警告:过量使用内存设置为0!在低内存环境下,后台保存可能失败。为了修正这个问题,请在/etc/sysctl.conf 添加一项 'vm.overcommit_memory = 1' ,然后重启(或者运行命令'sysctl vm.overcommit_memory=1' )使其生效。


修改后再次启动。

oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值