解决当前告警提示
告警一
backlog参数控制的是三次握手的时候server端收到client ack确认号之后的队列值,即全连接队列
vim /etc/sysctl.conf
net.core.somaxconn = 1024
sysctl -p
告警二
内核参数
0、表示内核将检查是否有足够的可用内存供应用进程使用;如果有足够的可用内存,内存申请允许;否则,内存申请失败,并把错误返回给应用进程。
1、表示内核允许分配所有的物理内存,而不管当前的内存状态如何
2、表示内核允许分配超过所有物理内存和交换空间总和的内存
vim /etc/sysctl.conf
vm.overcommit_memory = 1
sysctl -p
告警三
大页内存动态分配,需要关闭让redis 负责内存管理
[root@centos7 ~]#echo 'echo never > /sys/kernel/mm/transparent_hugepage/enabled'
>> /etc/rc.d/rc.local
[root@centos7 ~]#cat /etc/rc.d/rc.local
#!/bin/bash
# THIS FILE IS ADDED FOR COMPATIBILITY PURPOSES
#
# It is highly advisable to create own systemd services or udev rules
# to run scripts during boot instead of using this file.
#
# In contrast to previous versions due to parallel execution during boot
# this script will NOT be run after all other services.
#
# Please note that you must run 'chmod +x /etc/rc.d/rc.local' to ensure
# that this script will be executed during boot.
touch /var/lock/subsys/local
echo never > /sys/kernel/mm/transparent_hugepage/enabled
[root@centos7 ~]#chmod +x /etc/rc.d/rc.local
编译安装后的命令
[root@ ~]# ll /apps/redis/bin/
total 21888
-rwxr-xr-x 1 redis redis 2452176 Sep 4 16:22 redis-benchmark #redis性能测试工具
-rwxr-xr-x 1 redis redis 5777752 Sep 4 16:22 redis-check-aof #AOF文件检查工具
-rwxr-xr-x 1 redis redis 5777752 Sep 4 16:22 redis-check-rdb #RDB文件检查工具
-rwxr-xr-x 1 redis redis 2618208 Sep 4 16:22 redis-cli #客户端工具
lrwxrwxrwx 1 redis redis 12 Sep 4 16:22 redis-sentinel -> redis-server #哨兵,软连
接到server
-rwxr-xr-x 1 redis redis 5777752 Sep 4 16:22 redis-server #redis 服务启动命令
redis设置密码
方式一
修改配置文件
redis.conf文件
方式二
[root@localhost ~]# redis-cli
127.0.0.1:6379> config set requirepass 000000
连接到redis
本机无密码连接
redis-cli
跨主机无密码连接
redis-cli -h HOSTNAME/IP -p PORT
跨主机密码连接
redis-cli -h HOSTNAME/IP -p PORT -a PASSWORD
shell连接脚本
[root@localhost ~]# cat redis.sh
#!/bin/bash
NUM=100
PASS=123456
for i in `seq $NUM`;do
redis-cli -h 127.0.0.1 -a "$PASS" --no-auth-warning set key${i} value${i}
echo "key${i} value${i} 写入完成"
done
echo "$NUM个key写入到Redis完成"
[root@localhost ~]# cat redis.sh
#!/bin/bash
NUM=`seq 1 10`
for i in ${NUM};do
redis-cli -h 127.0.0.1 set key-${i} value-${i}
echo "key-${i} value-${i} 写入完成"
done
echo "$NUM key写入到Redis完成"
python连接方式
#!/bin/env python
import redis
import time
pool = redis.ConnectionPool(host="192.168.148.157", port=6379,password="")
r = redis.Redis(connection_pool=pool)
for i in range(100):
r.set("k%d" % i,"v%d" % i)
time.sleep(1)
data=r.get("k%d" % i)
print(data)