環境:node
系統硬件:vmware vsphere (CPU:2*4核,內存2G,雙網卡)c++
系統版本:CentOS-7.0-1406-x86_64-DVD.isoredis
安裝步驟:數據庫
1.準備vim
1.1 顯示系統版本
[root@centos ~]# cat /etc/redhat-releasecentos
CentOS Linux release 7.3.1611 (Core)緩存
[root@centos ~]# uname -rapp
3.10.0-514.6.1.el7.x86_64less
1.2 安裝基本軟件包tcp
[root@centos ~]# yum install vim wget lsof gcc gcc-c++ -y
1.3 顯示IP地址
[root@centos ~]# ip addr|grep inet
inet 127.0.0.1/8 scope host lo
inet 192.168.1.10/24 brd 192.168.1.255 scope global ens160
2.安裝redis
2.1 安裝依賴
[root@centos ~]# yum install tcl -y
[root@centos ~]# cd /usr/local/src
[root@centos ~]# wget http://download.redis.io/releases/redis-5.0.5.tar.gz
[root@centos ~]# tar -zxvf redis-5.0.5.tar.gz && cd redis-5.0.5
[root@centos ~]# make && make PREFIX=/opt/redis install
[root@centos ~]# groupadd redis
[root@centos ~]# useradd -g redis redis -s /sbin/nologin -M
[root@centos ~]# mkdir -p /opt/redis/logs
[root@centos ~]# cp redis.conf /opt/redis
[root@centos ~]# ll /opt/redis
[root@centos ~]# chown -R redis:redis /opt/redis
[root@centos ~]# vim /opt/redis/redis.conf
找到相關的行,修改
#bind 127.0.0.1
protected-mode no
requirepass redispwd
daemonize no
supervised no
pidfile /opt/redis/redis_6379.pid
logfile /opt/redis/redis_6379.log
dbfilename dump.rdb
dir /opt/redis
保存,退出
[root@centos ~]# vim /usr/lib/systemd/system/redis.service
[Unit]
Description=Redis Server
After=network.target
[Service]
Type=simple
PIDFile=/opt/redis/redis_6379.pid
ExecStart=/opt/redis/bin/redis-server /opt/redis/redis.conf
ExecStop=/bin/kill -s QUIT $MAINPID
Restart=on-failure
User=redis
[Install]
WantedBy=multi-user.target
保存,退出
[root@centos ~]# systemctl enable redis && systemctl daemon-reload && systemctl start redis
[root@centos ~]# systemctl status firewalld
配置打開端口
[root@centos ~]# iptables -L --line-numbers|grep ACCEPT
[root@centos ~]# firewall-cmd --zone=public --add-port=6379/tcp --permanent
**************************************************************************************************
指定IP能夠訪問
[root@centos ~]# firewall-cmd --permanent --add-rich-rule="rule family="ipv4" source address="192.168.1.25" port protocol="tcp" port="6379" accept"
移除指定IP能夠訪問
[root@centos ~]# firewall-cmd --permanent --remove-rich-rule="rule family="ipv4" source address="192.168.1.25" port protocol="tcp" port="6379" accept"
**************************************************************************************************
[root@centos ~]# firewall-cmd --reload && iptables -L --line-numbers|grep ACCEPT
安裝完成後,打開客戶端
[root@centos ~]# /opt/redis/bin/redis-cli -h 127.0.0.1 -p 6379
輸入如下命令,測試寫入及讀取
127.0.0.1:6379 > auth redispwd
127.0.0.1:6379 > set name abc123
127.0.0.1:6379 > get name
退出
quit
手動持久化(保存到硬盤)
[root@centos ~]# /opt/redis/bin/redis-cli save
redis.conf 的配置信息
一、daemonize 若是須要在後臺運行,把該項改成yes
二、pidfile 配置多個pid的地址 默認在/var/run/redis.pid
三、bind 綁定ip,設置後只接受來自該ip的請求
四、port 監聽端口,默認是6379
五、loglevel 分爲4個等級:debug verbose notice warning
六、logfile 用於配置log文件地址
七、databases 設置數據庫個數,默認使用的數據庫爲0
八、save 設置redis進行數據庫鏡像的頻率。
九、rdbcompression 在進行鏡像備份時,是否進行壓縮
十、dbfilename 鏡像備份文件的文件名
十一、Dir 數據庫鏡像備份的文件放置路徑
十二、Slaveof 設置數據庫爲其餘數據庫的從數據庫
1三、Masterauth 主數據庫鏈接須要的密碼驗證
1四、Requriepass 設置 登錄時須要使用密碼
1五、Maxclients 限制同時使用的客戶數量
1六、Maxmemory 設置redis可以使用的最大內存
1七、Appendonly 開啓append only模式
1八、Appendfsync 設置對appendonly.aof文件同步的頻率(對數據進行備份的第二種方式)
1九、vm-enabled 是否開啓虛擬內存支持 (vm開頭的參數都是配置虛擬內存的)
20、vm-swap-file 設置虛擬內存的交換文件路徑
2一、vm-max-memory 設置redis使用的最大物理內存大小
2二、vm-page-size 設置虛擬內存的頁大小
2三、vm-pages 設置交換文件的總的page數量
2四、vm-max-threads 設置VM IO同時使用的線程數量
2五、Glueoutputbuf 把小的輸出緩存存放在一塊兒
2六、hash-max-zipmap-entries 設置hash的臨界值
2七、Activerehashing 從新hash
redis【持久化】配置:
http://blog.csdn.net/vtopqx/article/details/46833513
一、rdb
save 900 1
save 300 10
save 60 10000
二、aof
appendfsync always
appendfsync everysec
appendfsync no
redis【主從】配置:
http://blog.csdn.net/yilukuangpao/article/details/52004257
vi etc/redis.conf
#綁定IP地址
bind 192.168.88.128
#若當前服務爲slave,在此處設置主服務的ip及端口
slaveof 10.10.10.200 6379
#若當前服務爲slave,設置主服務的認證密碼
masterauth 01130229
127.0.0.1:6379> slaveof 10.10.10.200 6379
顯示ok,也就OK了
redis【集羣】配置:
http://blog.csdn.net/jhq0113/article/details/44134833
http://blog.csdn.net/zj0116/article/details/44673017
bind 127.0.0.1
protected-mode yes
port 6379
tcp-backlog 511
timeout 0
tcp-keepalive 300
daemonize no
supervised no
pidfile /var/run/redis_6379.pid
loglevel notice
logfile /var/log/redis_6379.log
databases 16
save 900 1
save 300 10
save 60 10000
stop-writes-on-bgsave-error yes
rdbcompression yes
rdbchecksum yes
dbfilename dump.rdb
dir /usr/local/redis
slave-serve-stale-data yes
slave-read-only yes
repl-diskless-sync no
repl-diskless-sync-delay 5
repl-disable-tcp-nodelay no
slave-priority 100
appendonly no
appendfilename "appendonly.aof"
appendfsync everysec
no-appendfsync-on-rewrite no
auto-aof-rewrite-percentage 100
auto-aof-rewrite-min-size 64mb
aof-load-truncated yes
aof-use-rdb-preamble no
lazyfree-lazy-eviction no
lazyfree-lazy-expire no
lazyfree-lazy-server-del no
slave-lazy-flush no
lua-time-limit 5000
slowlog-log-slower-than 10000
slowlog-max-len 128
latency-monitor-threshold 0
notify-keyspace-events ""
hash-max-ziplist-entries 512
hash-max-ziplist-value 64
list-max-ziplist-size -2
list-compress-depth 0
set-max-intset-entries 512
zset-max-ziplist-entries 128
zset-max-ziplist-value 64
hll-sparse-max-bytes 3000
activerehashing yes
client-output-buffer-limit normal 0 0 0
client-output-buffer-limit slave 256mb 64mb 60
client-output-buffer-limit pubsub 32mb 8mb 60
hz 10
aof-rewrite-incremental-fsync yes