部署Redis服务
在redis1(192.168.1.11)上部署redis
[root@redis1 ~]# yum install -y gcc
[root@redis1 ~]# tar xf redis-4.0.8.tar.gz
[root@redis1 ~]# cd redis-4.0.8
# 修改安装目录为/usr/local/redis
[root@redis1 redis-4.0.8]# vim +27 src/Makefile
PREFIX?=/usr/local/redis
# 编译安装
[root@redis1 redis-4.0.8]# make && make install
# 将redis命令目录添加至PATH环境变量
[root@redis1 redis-4.0.8]# vim /etc/bashrc # 尾部追加
export PATH=$PATH:/usr/local/redis/bin
[root@redis1 redis-4.0.8]# source /etc/bashrc
# 初始化redis服务
[root@redis1 redis-4.0.8]# ./utils/install_server.sh # 全部问题直接回车采用默认值
Welcome to the redis service installer
This script will help you easily set up a running redis server
Please select the redis port for this instance: [6379]
Selecting default: 6379
Please select the redis config file name [/etc/redis/6379.conf]
Selected default - /etc/redis/6379.conf
Please select the redis log file name [/var/log/redis_6379.log]
Selected default - /var/log/redis_6379.log
Please select the data directory for this instance [/var/lib/redis/6379]
Selected default - /var/lib/redis/6379
Please select the redis executable path [/usr/local/redis/bin/redis-server]
Selected config:
Port : 6379
Config file : /etc/redis/6379.conf
Log file : /var/log/redis_6379.log
Data dir : /var/lib/redis/6379
Executable : /usr/local/redis/bin/redis-server
Cli Executable : /usr/local/redis/bin/redis-cli
Is this ok? Then press ENTER to go on or Ctrl-C to abort.
Copied /tmp/6379.conf => /etc/init.d/redis_6379
Installing service...
Successfully added to chkconfig!
Successfully added to runlevels 345!
Starting Redis server...
Installation successful!
# 查看服务状态
[root@redis1 ~]# /etc/init.d/redis_6379 status
Redis is running (10023)
# 也可以使用以下方式查看服务状态
[root@redis1 ~]# service redis_6379 status
Redis is running (10023)
[root@redis1 ~]# ss -tlnp | grep :6379
LISTEN 0 128 127.0.0.1:6379 *:* users:(("redis-server",pid=10023,fd=6))
# 关闭服务
[root@redis1 ~]# service redis_6379 stop
Stopping ...
Redis stopped
# 也可以使用以下方式关闭服务
[root@redis1 ~]# /etc/init.d/redis_6379 stop
# 启动服务
[root@redis1 ~]# service redis_6379 start
Starting Redis server...
# 也可以使用以下方式启动服务
[root@redis1 ~]# /etc/init.d/redis_6379 start
# 重启服务
[root@redis1 ~]# service redis_6379 restart
Stopping ...
Redis stopped
Starting Redis server...
# 也可以使用以下方式重启服务
[root@redis1 ~]# /etc/init.d/redis_6379 restart
# 连接redis
[root@redis1 ~]# redis-cli
127.0.0.1:6379> ping # 测试服务,正常返回PONG
PONG
127.0.0.1:6379> exit
网友评论