### 一、Redis服务端口
Redis默认的端口是6379,如果想启动多个Redis服务,就需要在不同端口启动不同的Redis服务。一下示例为通过6380端口启动Redis服务。
- 指定redis服务端口
```shell
[root@miantiao:/redis-5.0.9/src]$ ./redis-server --port 6380 #指定redis服务端口为6380
```
- 链接指定端口的redis服务
```shell
[root@miantiao:/redis-5.0.9/src]$ redis-cli -p 6380 #链接端口为为6380的redis服务
```
### 二、Redis的配置文件
#### 1、Redis配置文件内容
Redis 的配置文件位于 Redis 安装目录下,文件名为 **redis.conf**。其内容非常多,使用如下命令可以将其中的注释行、空白去除并将去除后的内容写入一个新的文件中(redis-6379.conf)
```shell
[root@miantiao:/redis-5.0.9] $cat redis.conf | grep -v "#" | grep -v "^$" > redis-6379.conf
```
以下就是最终可用的Redis配置信息,其中主要的配置项已注解。其他配置项的说明可参见:[Redis配置文件参数说明](https://www.runoob.com/redis/redis-conf.html)
```shell
bind 127.0.0.1 #绑定的host
protected-mode yes
port 6379 #端口
tcp-backlog 511
timeout 0
tcp-keepalive 300
daemonize no #是否以守护线程的方式启动。no:会在控制台打印日志,yes:不会在控制台打印日志
supervised no
pidfile /var/run/redis_6379.pid
loglevel notice
logfile "" #日志文件名称
databases 16
always-show-logo yes
save 900 1
save 300 10
save 60 10000
stop-writes-on-bgsave-error yes
rdbcompression yes
rdbchecksum yes
dbfilename dump.rdb
dir ./ #生成文件存放的路径
replica-serve-stale-data yes
replica-read-only yes
repl-diskless-sync no
repl-diskless-sync-delay 5
repl-disable-tcp-nodelay no
replica-priority 100
lazyfree-lazy-eviction no
lazyfree-lazy-expire no
lazyfree-lazy-server-del no
replica-lazy-flush no
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 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-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
stream-node-max-bytes 4096
stream-node-max-entries 100
activerehashing yes
client-output-buffer-limit normal 0 0 0
client-output-buffer-limit replica 256mb 64mb 60
client-output-buffer-limit pubsub 32mb 8mb 60
hz 10
dynamic-hz yes
aof-rewrite-incremental-fsync yes
rdb-save-incremental-fsync yes
```
#### 2、通过配置文件启动Redis
对于企业级应用来说,可定不能通过手动地方式启动Redis,最好的方式就是通过配置文件启动Redis。首先需要编写Redis的配置文件例如(redis-6379.conf),然后执行如下命令即可。
```shell
[root@miantiao:/redis-5.0.9]$ redis-server redis-6379.conf
```
### 三、 Redis客户端连接
- 默认连接
```shell
redis-cli
```
- 连接指定服务器或端口
```shell
redis-cli -h 127.0.0.1
redis-cli -p 6379
redis-cli -h 127.0.0.1 -p 6379
```
Redis学习笔记(三)