一、redis安装步骤
[root@localhost ~]# mkdir -p /opt/redis_cluster/reddis_6379
[root@localhost ~]# mkdir -p /opt/redis_cluster/reddis_6379/{conf,pid,logs}
[root@localhost ~]# mkdir -p /data/redis_cluster/redis_6379 ###本地数据库目录
[root@localhost ~]# mkdir -p /data/soft ###用来放安装包
[root@localhost ~]# cd /data/soft/
[root@localhost soft]# wget http://download.redis.io/releases/redis-5.0.5.tar.gz
[root@localhost soft]# tar -zxf tar zxf redis-5.0.5.tar.gz -C /opt/redis_cluster/
[root@localhost soft]# ln -s /opt/redis_cluster/redis-5.0.5/ /opt/redis_cluster/redis
cd /opt/redis_cluster/redis
make MALLOC=libc ###如果直接执行make会报错,所以需要指定库
make install
cd /opt/redis_cluster/redis/utils
执行 ./install_server.sh 接下来一直按回车,完成配置的初始化,之后展示详细信息:
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/bin/redis-server
Cli Executable : /usr/local/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!
二、redis配置文件
单节点的redis配置很简单,手动编写即可.(如果你的配置需求比较多,可以参照/etc/redis/6379.conf,这是官方详细的配置文件.)
cd /opt/redis_cluster/redis_6379/conf/
vim redis_6379.conf
### 以守护进程模式启动
daemonize yes
### 绑定的主机地址
bind 192.168.1.1
### 监听端口
port 6379
### pid文件和log文件的保存地址
pidfile /opt/redis_cluster/redis_6379/pid/redis_6379.pid
logfile /opt/redis_cluster/redis_6379/logs/redis_6379.log
### 设置数据库的数量,默认数据库为0
databases 16
### 制定本地持久化文件的文件名,默认是dump.rdb
dbfilename redis_6379.rdb
### 本地数据库的目录
dir /data/redis_cluster/redis_6379
三、启动和关闭redis
[root@localhost ~]# redis-server /opt/redis_cluster/redis_6379/conf/redis_6379.conf ###启动redis服务端
[root@localhost ~]# ps aux | grep redis
root 35003 0.1 0.4 46992 4400 ? Ssl 03:57 0:00 redis-server 192.168.1.1:6379
root 35039 0.0 0.1 12320 1076 pts/1 R+ 04:00 0:00 grep --color=auto redis
[root@localhost ~]# redis-cli -h 192.168.1.1 ###登录redis数据库
192.168.1.1:6379> shutdown ###关闭数据库
not connected> exit
或者: [root@localhost ~]# redis-cli -h 192.168.146.129 shutdown ###关闭数据库