知乎专栏 |
目录
[root@netkiller ~]# dnf install -y redis [root@netkiller ~]# systemctl enable redis
cp /etc/redis.conf{,.original} sed -i 's/bind 127.0.0.1/bind 0.0.0.0/g' /etc/redis.conf sed -i 's/timeout 0/timeout 30/' /etc/redis.conf sed -i 's/# maxclients 10000/maxclients 1000/' /etc/redis.conf sed -i 's/# maxmemory-policy noeviction/maxmemory-policy volatile-lru/g' /usr/local/etc/redis.conf random=$(cat /dev/urandom | tr -cd [:alnum:] | fold -w32 | head -n 1) sed -i "s/# requirepass foobared/requirepass ${random}/g" /etc/redis.conf echo "Redis random password is: ${random}" cat >> /etc/security/limits.d/20-nofile.conf <<EOF redis soft nofile 65500 redis hard nofile 65500 EOF cat >> /etc/sysctl.conf <<EOF # Set up for Redis vm.overcommit_memory = 1 net.core.somaxconn = 1024 EOF sysctl -w net.core.somaxconn=1024 sysctl -w vm.overcommit_memory=1 cat >> /etc/rc.local <<EOF # Set up for Redis echo never > /sys/kernel/mm/transparent_hugepage/enabled EOF echo never > /sys/kernel/mm/transparent_hugepage/enabled systemctl enable redis systemctl start redis systemctl status redis