ThinkChat2.0新版上线,更智能更精彩,支持会话、画图、阅读、搜索等,送10W Token,即刻开启你的AI之旅 广告
## 第一种最简启动 启动服务端 ~~~ 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 ~~~