Heim  >  Artikel  >  Datenbank  >  3.启停redis服务

3.启停redis服务

WBOY
WBOYOriginal
2016-06-07 15:22:361126Durchsuche

1.编译redis.conf参数文件安装完成后,我们就得尝试启动redis服务了。在$REDIS_HOME,编译如下文件 /home/ldh/redis/redis-2.8.3/redis.conf 修改端口将PORT 6379改成你想要的被客户访问的端口,不改也可以,只要不冲突。 设置密码: redis.conf中requirepas

1.编译redis.conf参数文件安装完成后,我们就得尝试启动redis服务了。在$REDIS_HOME,编译如下文件 /home/ldh/redis/redis-2.8.3/redis.conf

修改端口将PORT 6379改成你想要的被客户访问的端口,不改也可以,只要不冲突。 设置密码: redis.conf中requirepass前的注释去掉,后面加上密码,如 requirepass pass1234 如果服务已经启动,修改密码后需要重启服务才能使新密码生效。

2.启动服务启动服务,假如不用Nohup的话,当前会话就不能再进行其他操作咯。 nohup redis-server /home/ldh/redis/redis-2.8.3/redis.conf & 我们来看看nohup.out中,这个服务启动会反馈什么信息 [ldh@hauser redis-2.8.3]$ vi nohup.out [22624] 25 Dec 11:00:06.456 # Fatal error, can't open config file '/home/otredis/redis/2.6.16/conf/redis.conf' [22726] 25 Dec 11:06:01.442 # Fatal error, can't open config file '/home/otredis/redis/2.6.16/conf/redis.conf' [22737] 25 Dec 11:06:25.925 # Unable to set the max number of files limit to 10032 (Operation not permitted), setting the max clients configuration to 992. _._ _.-``__ ''-._ _.-`` `. `_. ''-._ Redis 2.8.3 (00000000/0) 64 bit .-`` .-```. ```\/ _.,_ ''-._ ( ' , .-` | `, ) Running in stand alone mode |`-._`-...-` __...-.``-._|'` _.-'| Port: 6389 | `-._ `._ / _.-' | PID: 22737 `-._ `-._ `-./ _.-' _.-' |`-._`-._ `-.__.-' _.-'_.-'| | `-._`-._ _.-'_.-' | http://redis.io `-._ `-._`-.__.-'_.-' _.-' |`-._`-._ `-.__.-' _.-'_.-'| | `-._`-._ _.-'_.-' | `-._ `-._`-.__.-'_.-' _.-' `-._ `-.__.-' _.-' `-._ _.-' `-.__.-' [22737] 25 Dec 11:06:25.931 # Server started, Redis version 2.8.3 [22737] 25 Dec 11:06:25.931 # 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. [22737] 25 Dec 11:06:25.931 * The server is now ready to accept connections on port 6389

此时,redis服务已经启动了。

3.登陆redis 此时我们登陆到redis数据库当中 [ldh@hauser redis-2.8.3]$ redis-cli -h 127.0.0.1 -p 6389 -a pass1234 127.0.0.1:6389> set fwy abc OK 127.0.0.1:6389> get fwy "abc"

本机登陆的话,也可以省略-h,如果是用默认端口6379,那么-p也可以省略。如redis-cli -a pass1234登陆即可如果远程登陆,可以用telnet登陆,退出时敲进quit [fengweiyuan513@cnsz081003 ~]$ telnet 10.25.30.143 6389 Trying 10.25.30.143... Connected to 10.25.30.143 (10.25.30.143). Escape character is '^]'. auth pass1234 +OK get fwy $1 2 quit +OK Connection closed by foreign host. [fengweiyuan513@cnsz081003 ~]$

4.停止redis服务 [ldh@hauser ~]$ redis-cli -h 127.0.0.1 -p 6389 -a pass1234 127.0.0.1:6389> shutdown 127.0.0.1:6389> exit 再连接一次已经发现不存在了,也可以通过ps -ef | grep redis来观察 [ldh@hauser ~]$ redis-cli -p 6389 -a pass1234 Could not connect to Redis at 127.0.0.1:6389: Connection refused 远程通过telnet来shutdown也是可以的,感觉挺不安全的。

Stellungnahme:
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn
Vorheriger Artikel:xTuple中数据库的备份语句Nächster Artikel:主键和外键的作用