## 第一種最簡啟動
啟動服務端
~~~
redis-server //默認使用6379端口
~~~
打開另一個ssh終端,用客戶端進行連接
~~~
redis-cli -h 127.0.0.1 -p 6379
~~~
連接成功
~~~
[root@localhost ~]# redis-cli -h 127.0.0.1 -p 6379
127.0.0.1:6379>
~~~
## 第二種(動態參數)
服務端使用6380端口
~~~
redis-server --port 6380 //指定使用6380端口啟動redis
~~~
客戶端
~~~
redis-cli -p 6380
~~~
## 第三種使用配置文件的方式啟動(生產環境)
單機多實例配置文件可以用端口區分開.
進入Redis安裝目錄, 創建confing文件夾 . 拷貝redis.conf文件至config文件 . 因為Redis是單線程的,但是我們服務器基本都是多核的,所以我們經常在一臺服務器上部署很多的Redis . 這樣我們就需要配置很多的端口 . 這樣我們的配置文件就以端口來進行區分 . 比如將redis.conf文件名修改成redis-6381 .
~~~
cat redis-6381 | grep -v "#" |grep -v "^$" > redis-6382 //對原6381文件進行"#"注釋行進行過濾并重定向 為redis-6382
~~~
得到配置文件
~~~
daemonize no
pidfile /var/run/redis.pid //這里為進程存放的位置
port 6379
tcp-backlog 511
timeout 0
tcp-keepalive 0
loglevel notice
logfile ""
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 ./
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
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-entries 512
list-max-ziplist-value 64
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
~~~
修改為以下
~~~
daemonize yes //修改為yes, 以守護進程的方式進行啟動
port 6382 //端口號修改為6382
dir "/opt/soft/redis/data" //工作目錄,就是我們的日志文件和持久化的文件存在哪個目錄
logfile "6382.log" //日志文件
logfile //redis系統日志,只是一個文件名
~~~
啟動
~~~
redis-server config/redis-6382
~~~
查看進程是否存在
~~~
ps -ef | grep 6382
~~~
結果,說明啟動成功
~~~
root 18534 1 0 00:41 ? 00:00:00 redis-server *:6382
root 18538 18300 0 00:41 pts/0 00:00:00 grep --color=auto 6382
~~~
客戶端連接成功
~~~
redis-cli -p 6382
127.0.0.1:6382>
~~~
查看日志文件
~~~
18552:M 29 Mar 00:44:52.035 * Increased maximum number of open files to 10032 (it was originally set to 1024).
_._
_.-``__ ''-._
_.-`` `. `_. ''-._ Redis 3.0.7 (00000000/0) 64 bit
.-`` .-```. ```\/ _.,_ ''-._
( ' , .-` | `, ) Running in standalone mode
|`-._`-...-` __...-.``-._|'` _.-'| Port: 6382
| `-._ `._ / _.-' | PID: 18552
`-._ `-._ `-./ _.-' _.-'
|`-._`-._ `-.__.-' _.-'_.-'|
| `-._`-._ _.-'_.-' | http://redis.io
`-._ `-._`-.__.-'_.-' _.-'
|`-._`-._ `-.__.-' _.-'_.-'|
| `-._`-._ _.-'_.-' |
`-._ `-._`-.__.-'_.-' _.-'
`-._ `-.__.-' _.-'
`-._ _.-'
`-.__.-'
18552:M 29 Mar 00:44:52.036 # WARNING: The TCP backlog setting of 511 cannot be enforced because /proc/sys/net/core/somaxconn is set to the lower value of 128.
18552:M 29 Mar 00:44:52.036 # Server started, Redis version 3.0.7
18552:M 29 Mar 00:44:52.036 # 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.
18552:M 29 Mar 00:44:52.037 # 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.
18552:M 29 Mar 00:44:52.037 * The server is now ready to accept connections on port 6382
~~~
- Redis簡介
- 簡介
- 典型應用場景
- Redis安裝
- 安裝
- redis可執行文件說明
- 三種啟動方法
- Redis常用配置
- API的使用和理解
- 通用命令
- 數據結構和內部編碼
- 單線程
- 數據類型
- 字符串
- 哈希
- 列表
- 集合
- 有序集合
- Redis常用功能
- 慢查詢
- Pipline
- 發布訂閱
- Bitmap
- Hyperloglog
- GEO
- 持久化機制
- 概述
- snapshotting快照方式持久化
- append only file追加方式持久化AOF
- RDB和AOF的抉擇
- 開發運維常見問題
- fork操作
- 子進程外開銷
- AOF追加阻塞
- 單機多實例部署
- Redis復制原理和優化
- 什么是主從復制
- 主從復制配置
- 全量復制和部分復制
- 故障處理
- 開發運維常見問題
- Sentinel
- 主從復制高可用
- 架構說明
- 安裝配置
- 客戶端連接
- 實現原理
- 常見開發運維問題
- 高可用讀寫分離
- 故障轉移client怎么知道新的master地址
- 總結
- Sluster
- 呼喚集群
- 數據分布
- 搭建集群
- 集群通信
- 集群擴容
- 集群縮容
- 客戶端路由
- 故障轉移
- 故障發現
- 故障恢復
- 開發運維常見問題
- 緩存設計與優化
- 緩存收益和成本
- 緩存更新策略
- 緩存粒度控制
- 緩存穿透優化
- 緩存雪崩優化
- 無底洞問題優化
- 熱點key重建優化
- 總結
- 布隆過濾器
- 引出布隆過濾器
- 布隆過濾器基本原理
- 布隆過濾器誤差率
- 本地布隆過濾器
- Redis布隆過濾器
- 分布式布隆過濾器
- 開發規范
- 內存管理
- 開發運維常見坑
- 實戰
- 對文章進行投票
- 數據庫的概念
- 啟動多實例