一、 Windows下配置Redis服务器、设置密码并允许IP访问
1、下载安装Redis的Windows版本
2、修改redis安装目录下的redis.windows-service.conf文件
#设置IP访问:默认绑定localhost,修改 bind 127.0.0.1 这一行,将127.0.0.1改为自己的IP
bind 128.103.5.48
#设置访问密码:修改 requirepass 的值
requirepass=自己的密码
3、重启redis服务
4、windows 2008R2注意设置防火墙的入站端口(6379)设置以及redis安装目录下NETWORK SERVICE用户的完全访问权限
5、可视化操作软件RedisDesktopManager
二、Ubuntu下配置Redis服务器、设置密码并允许IP访问
#编辑redis配置文件
sudo vi /etc/redis/redis.conf
#注释下面这一行 我的是69行 可以搜索bind查找
#bind 127.0.0.1
##默认开启保护模式yes,设定为no禁用
protected-mode no
##重启redis
sudo service redis-server restart
#或者可以强制杀死再手动开启
sudo killall redis-server
sudo redis-server /etc/redis/redis.conf #这里最好把配置文件加进去不然可能会出现配置未生效
三、设置redis最大内存以及超过最大内存的过期策略
#编辑redis配置文件
sudo vi /etc/redis/redis.conf
#编辑maxmemory 2.5GB
# maxmemory <bytes>
maxmemory 2684354560
#编辑过期策略
# volatile-lru -> remove the key with an expire set using an LRU algorithm根据LRU算法生成的过期时间来删除。
# allkeys-lru -> remove any key accordingly to the LRU algorithm根据LRU算法删除任何key
# volatile-random -> remove a random key with an expire set根据过期设置来随机删除key
# allkeys-random -> remove a random key, any key无差别随机删
# volatile-ttl -> remove the key with the nearest expire time (minor TTL)根据最近过期时间来删除(辅以TTL)
# noeviction -> don't expire at all, just return an error on write operations谁也不删,直接在写操作时返回错误。
maxmemory-policy volatile-lru
四、错误汇集
Can't save in background: fork: Cannot allocate memory
/* 在/etc/sysctl.conf文件里面加入或者直接删除也可以,因为它缺省值就是 */
sudo echo 'vm.overcommit_memory = 1' >> /etc/sysctl.conf
sudo sysctl -p
#查看最大进程数
sysctl kernel.pid_max
#查看进程数
ps -eLf | wc -l
#修改最大进程数后系统恢复
echo "kernel.pid_max=1000000 " >> /etc/sysctl.conf
sysctl -p