環境準備:CentOS 7.5redis
1、調整系統配置:
bash
一、調整 vm.overcommit_memoryapp
echo "vm.overcommit_memory = 1" >> /etc/sysctl.conf運維
它是內存分配策略ide
可選值:0、一、2。ui
0, 表示內核將檢查是否有足夠的可用內存供應用進程使用;若是有足夠的可用內存,內存申請容許;不然,內存申請失敗,並把錯誤返回給應用進程。spa
1, 表示內核容許分配全部的物理內存,而無論當前的內存狀態如何。code
2, 表示內核容許分配超過全部物理內存和交換空間總和的內存。orm
二、調整 Transparent Huge Pages (THP)server
解決:redis 作 rdb 時會有部分請求超時的 case
echo never > /sys/kernel/mm/transparent_hugepage/enabled
並在/etc/rc.local 追加
echo "never > /sys/kernel/mm/transparent_hugepage/enabled" >> /etc/rc.local
三、TCP backlog 設置
echo 2048 > /proc/sys/net/core/somaxconn
在/etc/sysctl.conf 添加 net.core.somaxconn = 2048
echo "net.core.somaxconn = 2048" >> /etc/sysctl.conf
sysctl -p
四、配置資源限制文件
1
2
3
4
|
echo
"redis hard nofile 10240"
>>
/etc/security/limits
.conf
echo
"redis soft nofile 10240"
>>
/etc/security/limits
.conf
echo
"redis hard nproc 8192"
>>
/etc/security/limits
.conf
echo
"redis soft nproc 8192"
>>
/etc/security/limits
.conf
|
2、部署redis
一、建立用戶
groupadd -g 601 redis
useradd -u 6001 -g 601 redis
id redis
passwd redis
二、建立目錄
mkdir -p /redis/log
mkdir -p /redis/conf
mkdir -p /redis/data
三、編譯安裝
su - redis
tar zxvf redis-5.0.5.tar.gz
cd redis-5.0.5
make
make PREFIX=/redis install
四、配置redis用戶環境變量
vi ~/.bash_profile
PATH=$PATH:$HOME/.local/bin:$HOME/bin:/redis/bin
source ~/.bash_profile
五、調整 redis.conf
daemonize yes
logfile "/redis/log/redis.log"
requirepass beijing
bind 172.16.254.106
六、設置開機啓動
vi /etc/rc.local
su - redis -c "/redis/bin/redis-server /redis/conf/redis.conf"
3、平常運維
一、啓動redis
redis-server /redis/conf/redis.conf
二、關閉redis
redis-cli -p 6379 -h 172.16.254.106 -a beijing
Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.
172.16.254.106:6379> shutdown
not connected>
或者
pkill redis-server
三、redis密碼管理
1)初始化密碼
修改/redis/conf/redis.conf
重啓redis
2)不重啓redis修改密碼
vi redis.conf
redis-cli -p 6379 -h 172.16.254.106 -a beijing
Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.
172.16.254.106:6379> config get requirepass
1) "requirepass"
2) "beijing"
172.16.254.106:6379> config set requirepass beijing123
OK
172.16.254.106:6379> config get requirepass
1) "requirepass"
2) "beijing123"