2525 - 把旧值:` daemonize no `
2626 - 改为新值:` daemonize yes `
2727 - 启动:` /usr/local/bin/redis-server /etc/redis.conf `
28+ - 关闭:` redis-cli -h 127.0.0.1 -p 6379 shutdown `
2829 - 查看是否启动:` ps -ef | grep redis `
2930 - 进入客户端:` redis-cli `
3031 - 关闭客户端:` redis-cli shutdown `
@@ -100,6 +101,12 @@ aof-rewrite-incremental-fsync yes
100101- 去掉注释,把 ` foobared ` 改为你想要设置的密码,比如我打算设置为:123456,所以我改为:` requirepass 123456 `
101102- 修改之后重启下服务
102103- 有了密码之后,进入客户端,就得这样访问:` redis-cli -h 127.0.0.1 -p 6379 -a 123456 `
104+ - 如果用 IP 进入客户端,但是报:` Could not connect to Redis at 192.168.1.121:6379: Connection refused `
105+ - 原因:Redis 默认只允许本机访问,可是有时候我们也需要 Redis 被远程访问。
106+ - 解决办法:
107+ - 修改 Redis 配置文件:`vim /etc/redis.conf`
108+ - 找到 bind 那行配置,默认是:`# bind 127.0.0.1`
109+ - 去掉 # 注释并改为:`bind 0.0.0.0`
103110
104111## Redis 常用命令
105112
@@ -125,6 +132,106 @@ aof-rewrite-incremental-fsync yes
125132- ` FLUSHALL ` ,清空所有数据库的所有键值
126133
127134
135+ ## 把 redis 添加到系统服务中
136+
137+ - 新建文件:` vim /etc/init.d/redis `
138+ - 添加如下内容:
139+
140+ ``` nginx
141+ #!/bin/sh
142+ #
143+ # redis - this script starts and stops the redis-server daemon
144+ #
145+ # chkconfig: - 85 15
146+ # description: Redis is a persistent key-value database
147+ # processname: redis-server
148+ # config: /usr/local/redis-2.4.X/bin/redis-server
149+ # config: /usr/local/ /redis-2.4.X/etc/redis.conf
150+ # Source function library.
151+ . /etc/rc.d/init.d/functions
152+ # Source networking configuration.
153+ . /etc/sysconfig/network
154+ # Check that networking is up.
155+ [ "$NETWORKING" = "no" ] && exit 0
156+ redis="/usr/local/bin/redis-server"
157+ prog=$(basename $redis)
158+ REDIS_CONF_FILE="/etc/redis.conf"
159+ [ -f /etc/sysconfig/redis ] && . /etc/sysconfig/redis
160+ lockfile=/var/lock/subsys/redis
161+ start() {
162+ [ -x $redis ] || exit 5
163+ [ -f $REDIS_CONF_FILE ] || exit 6
164+ echo -n $"Starting $prog: "
165+ daemon $redis $REDIS_CONF_FILE
166+ retval=$?
167+ echo
168+ [ $retval -eq 0 ] && touch $lockfile
169+ return $retval
170+ }
171+ stop() {
172+ echo -n $"Stopping $prog: "
173+ killproc $prog -QUIT
174+ retval=$?
175+ echo
176+ [ $retval -eq 0 ] && rm -f $lockfile
177+ return $retval
178+ }
179+ restart() {
180+ stop
181+ start
182+ }
183+ reload() {
184+ echo -n $"Reloading $prog: "
185+ killproc $redis -HUP
186+ RETVAL=$?
187+ echo
188+ }
189+ force_reload() {
190+ restart
191+ }
192+ rh_status() {
193+ status $prog
194+ }
195+ rh_status_q() {
196+ rh_status >/dev/null 2>&1
197+ }
198+ case "$1" in
199+ start)
200+ rh_status_q && exit 0
201+ $1
202+ ;;
203+ stop)
204+ rh_status_q || exit 0
205+ $1
206+ ;;
207+ restart|configtest)
208+ $1
209+ ;;
210+ reload)
211+ rh_status_q || exit 7
212+ $1
213+ ;;
214+ force-reload)
215+ force_reload
216+ ;;
217+ status)
218+ rh_status
219+ ;;
220+ condrestart|try-restart)
221+ rh_status_q || exit 0
222+ ;;
223+ *)
224+ echo $"Usage: $0 {start|stop|status|restart|condrestart|try-restart| reload|orce-reload}"
225+ exit 2
226+ esac
227+ ```
228+
229+ - 修改权限:` chmod 755 /etc/init.d/redis `
230+ - 启动服务:` service redis start `
231+ - 停止服务:` service redis stop `
232+ - 重启服务:` service ngredisnx restart `
233+
234+
128235## Redis 客户端
129236
130237- Java:< http://redis.io/clients#java >
0 commit comments