單點安裝redis+哨兵

下載地址c++

http://redis.io/download/ 
http://219.239.26.13/files/205900000B7E5F47/download.redis.io/releases/redis-4.0.9.tar.gz

建立程序目錄redis

mkdir /data/
#目錄結構本身調整 redis編譯完成後,有用的文件是 redis.conf sentinel.conf src/redis-* 可執行文件

解壓並編譯vim

yum -y install  gcc tcl gcc-c++ make
tar zxvf redis-4.0.9.tar.gz
mv redis-4.0.9 /data/
cd redis-4.0.9
make
make install 

規劃目錄結構併發

[root@qiqi3 data]# tree redis-4.0.9/
redis-4.0.9/
├── 6379
│   ├── conf
│   │   └── redis.conf
│   ├── data
│   │   └── dump.rdb
│   ├── login.sh
│   ├── logs
│   │   └── redis.log
│   ├── sentinel
│   │   ├── sentinel.conf
│   │   ├── sentinel.log
│   │   └── start_sentinel.sh
│   └── start.sh
└── bin
    ├── redis-benchmark
    ├── redis-check-aof
    ├── redis-check-rdb
    ├── redis-cli
    ├── redis-sentinel
    ├── redis-server
    ├── redis-trib.rb
    ├── runtest
    ├── runtest-cluster
    └── runtest-sentinel

6 directories, 18 files
筆者的目錄結構

修改配置文件 redis.confapp

#常規修改項
bind 1.1.1.1 pidfile "/app/redis-3.2.11/6379/run/redis_6379.pid" logfile "/app/redis-3.2.11/6379/logs/redis.log" dir "/app/redis-3.2.11/6379/data"
maxmemory 268435456 #設置最大使用內存

修改配置文件 sentinel.conftcp

bind 1.1.1.1
dir "/data/redis-4.0.9/6379/sentinel"
logfile "/data/redis-4.0.9/6379/sentinel/sentinel.log"

啓動rediside

/data/redis-4.0.9/bin/redis-server /data/redis-4.0.9/6379/conf/redis.conf &
/data/redis-4.0.9/bin/redis-sentinel /data/redis-4.0.9/6379/sentinel/sentinel.conf &

登陸redisui

#若是綁定了固定ip 就指定ip登陸 不然會被拒絕
/app/redis-3.2.11/bin/redis-cli -h 172.16.1.29 -p 6379

設置密碼this

打開文件/etc/redis.conf,找到其中的# requirepass foobared,去掉前面的#,並把foobared改爲你的密碼。

使用密碼登陸spa

/app/redis-3.2.11/bin/redis-cli -h 172.16.1.29 -p 6379 -a 123

 當第一啓動redis的時候,可能會產生一些警告

WARNING The TCP backlog setting of 511 cannot be enforced because /proc/sys/net/core/somaxconn is set to the lower value of 128.
 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.
 WARNING you have Transparent Huge Pages (THP) support enabled in your kernel. This will create latency and memory usage issues with Redis. To fix this issue run the command 'echo never > /sys/kernel/mm/transparent_hugepage/enabled' as root, and add it to your /etc/rc.local in order to retain the setting after a reboot. Redis must be restarted after THP is disabled.

能夠看到存在3條啓動警告信息:

第一個錯誤和第二個錯誤能夠同時解決,第一個錯誤大概是說somaxconn的值128設置太小,此值受限於系統的somaxconn與tcp_max_syn_backlog這兩個值,因此應該把這兩個內核參數值調大,第二個錯誤是過量使用內存設置爲0!在低內存環境下,後臺保存可能失敗。請在/etc/sysctl.conf 添加一項 ‘vm.overcommit_memory = 1′ ,而後重啓(或者運行命令’sysctl vm.overcommit_memory=1’ )使其生效。

針對警告所作的修改:

 # vim /etc/sysctl.conf
 net.core.somaxconn = 20480
 #最大隊列長度,應付突發的大併發鏈接請求,默認爲128
 net.ipv4.tcp_max_syn_backlog = 20480
 #半鏈接隊列長度,此值受限於內存大小,默認爲1024
 vm.overcommit_memory = 1
 #過量使用內存設置爲0!
 # sysctl -p
第三個警告錯誤是須要關閉Linux (THP) 透明內存

 # vim /etc/rc.local
 echo never > /sys/kernel/mm/transparent_hugepage/enabled #在開機腳本里追加此命令
相關文章
相關標籤/搜索