1- # [ CentOS 7 安装redis] ( < https://blog.csdn.net/qq_40134903/article/details/88123865 > )
1+ [ CentOS 7 安装redis] ( < https://blog.csdn.net/qq_40134903/article/details/88123865 > )
2+
3+ [ CENTOS7下安装REDIS] ( https://www.cnblogs.com/zuidongfeng/p/8032505.html )
24
35``` bash
46# 安装vim
@@ -9,3 +11,177 @@ vim /etc/vimrc
911set nu
1012```
1113
14+ ``` bash
15+ yum -y install wget
16+ yum install gcc-c++
17+ cd /usr/local
18+ mkdir redis
19+ cd redis
20+ wget http://download.redis.io/releases/redis-stable.tar.gz
21+ tar -zxvf redis-stable.tar.gz
22+ rm redis-stable.tar.gz
23+ cd redis-stable
24+ # 执行make编译Redis:注意:make命令执行完成编译后,会在src目录下生成6个可执行文件,分别是redis-server、redis-cli、redis-benchmark、redis-check-aof、redis-check-rdb、redis-sentinel。
25+ make MALLOC=libc
26+ # 安装Redis:
27+ make install
28+ # 配置Redis能随系统启动:
29+ ./utils/install_server.sh
30+ # 关闭redis
31+ redis-cli shutdown
32+ # 启动Redis数据库服务器(redis解压目录下):
33+ $ cd src
34+ $ ./redis-server & (& 表示可在后台运行,ctrl+c)
35+ # 开机启动redis
36+ # 1 mkdir /usr/local/redis/redis-stable
37+ mkdir /usr/local/redis/redis-stable/bin # 执行目录
38+ mkdir /usr/local/redis/redis-stable/etc # 配置目录
39+ mkdir /usr/local/redis/redis-stable/log # 日志目录
40+ mkdir /usr/local/redis/redis-stable/data # 持久化数据目录
41+ # 2 复制文件到redis文件夹(解压的目录下):
42+ cp src/redis-server src/redis-cli src/redis-benchmark src/redis-sentinel src/redis-check-aof src/redis-check-rdb /usr/local/redis/redis-stable/bin/
43+ cp redis.conf /usr/local/redis/redis-stable/etc/
44+ # 3 编辑配置文件:将daemonize no 修改为 daemonize yes
45+ vim /usr/local/redis/redis-stable/etc/redis.conf
46+ # 4 测试启动redis
47+ /usr/local/redis/redis-stable/bin/redis-server &
48+ # 5 开启守护进程
49+ /usr/local/redis/redis-stable/bin/redis-server /usr/local/redis/redis-stable/etc/redis.conf &
50+ # 6 查看进程
51+ ps -ef | grep redis
52+ netstat -ano | grep 6379
53+ netstat -lntp | grep 6379
54+ # 7 增加系统启动配置rc.local文件:
55+ vim /etc/rc.local
56+ chmod +x /etc/rc.d/rc.local
57+ systemctl daemon-reload
58+ systemctl list-dependencies multi-user.target | grep rc-local
59+ # 8 将/usr/local/redis/redis-stable/bin加入系统环境变量:
60+ vim /etc/profile # export PATH="$PATH:/usr/local/redis/redis-stable/bin"
61+ source /etc/profile
62+ # 9 重启后查看是否自动启动成功
63+ shutdown -r now # 重启系统
64+ ps -A| grep redis
65+ ps -ef| grep redis
66+ netstat -lntp | grep 6379
67+
68+ # 启动和关闭服务
69+ /etc/init.d/redis_6379 start
70+ /etc/init.d/redis_6379 stop
71+ # 或
72+ service redis_6379 start
73+ service redis_6379 stop
74+
75+
76+ # 设置密码
77+ vim /usr/local/redis/redis-stable/etc/redis.conf
78+ # # requirepass foobared
79+ requirepass xxxxxxx(连接密码)
80+ service redis_6379 restart
81+
82+
83+
84+
85+
86+
87+
88+
89+
90+
91+
92+
93+
94+ ```
95+
96+ ``` bash
97+ [root@centos701 redis-stable]# ./utils/install_server.sh
98+ Welcome to the redis service installer
99+ This script will help you easily set up a running redis server
100+
101+ Please select the redis port for this instance: [6379]
102+ Selecting default: 6379
103+ Please select the redis config file name [/etc/redis/6379.conf]
104+ Selected default - /etc/redis/6379.conf
105+ Please select the redis log file name [/var/log/redis_6379.log]
106+ Selected default - /var/log/redis_6379.log
107+ Please select the data directory for this instance [/var/lib/redis/6379]
108+ Selected default - /var/lib/redis/6379
109+ Please select the redis executable path [/usr/local/bin/redis-server]
110+ Selected config:
111+ Port : 6379
112+ Config file : /etc/redis/6379.conf
113+ Log file : /var/log/redis_6379.log
114+ Data dir : /var/lib/redis/6379
115+ Executable : /usr/local/bin/redis-server
116+ Cli Executable : /usr/local/bin/redis-cli
117+ Is this ok? Then press ENTER to go on or Ctrl-C to abort.
118+ Copied /tmp/6379.conf => /etc/init.d/redis_6379
119+ Installing service...
120+ Successfully added to chkconfig!
121+ Successfully added to runlevels 345!
122+ Starting Redis server...
123+ Installation successful!
124+ [root@centos701 redis-stable]#
125+
126+ ` ` `
127+
128+
129+
130+ # # /etc/rc.local
131+
132+ ` ` `
133+ # run redis-server
134+ /usr/local/redis/bin/redis-server /usr/local/redis/etc/redis.conf
135+ ` ` `
136+
137+ Redis服务查看、开启、关闭:
138+ a.通过ps -ef| grep redis命令查看Redis进程
139+ b.开启Redis服务操作通过/etc/init.d/redis_6379 start命令,也可通过(service redis_6379 start)
140+ c.关闭Redis服务操作通过/etc/init.d/redis_6379 stop命令,也可通过(service redis_6379 stop)
141+
142+
143+
144+ redis.conf 的配置信息
145+ 1、daemonize 如果需要在后台运行,把该项改为yes
146+ 2、pidfile 配置多个pid的地址 默认在/var/run/redis.pid
147+ 3、bind 绑定ip,设置后只接受来自该ip的请求
148+ 4、port 监听端口,默认是6379
149+ 5、loglevel 分为4个等级:debug verbose notice warning
150+ 6、logfile 用于配置log文件地址
151+ 7、databases 设置数据库个数,默认使用的数据库为0
152+ 8、save 设置redis进行数据库镜像的频率。
153+ 9、rdbcompression 在进行镜像备份时,是否进行压缩
154+ 10、dbfilename 镜像备份文件的文件名
155+ 11、Dir 数据库镜像备份的文件放置路径
156+ 12、Slaveof 设置数据库为其他数据库的从数据库
157+ 13、Masterauth 主数据库连接需要的密码验证
158+ 14、Requriepass 设置 登陆时需要使用密码
159+ 15、Maxclients 限制同时使用的客户数量
160+ 16、Maxmemory 设置redis能够使用的最大内存
161+ 17、Appendonly 开启append only模式
162+ 18、Appendfsync 设置对appendonly.aof文件同步的频率(对数据进行备份的第二种方式)
163+ 19、vm-enabled 是否开启虚拟内存支持 (vm开头的参数都是配置虚拟内存的)
164+ 20、vm-swap-file 设置虚拟内存的交换文件路径
165+ 21、vm-max-memory 设置redis使用的最大物理内存大小
166+ 22、vm-page-size 设置虚拟内存的页大小
167+ 23、vm-pages 设置交换文件的总的page数量
168+ 24、vm-max-threads 设置VM IO同时使用的线程数量
169+ 25、Glueoutputbuf 把小的输出缓存存放在一起
170+ 26、hash-max-zipmap-entries 设置hash的临界值
171+ 27、Activerehashing 重新hash
172+
173+
174+
175+ ------------------------------------------------------------------------------------------------------------------------
176+
177+ Redis设置密码访问:
178+
179+ vim /usr/local/redis/etc/redis.conf
180+ # requirepass foobared
181+
182+ 修改为:
183+
184+ requirepass xxxxxxx(连接密码)
185+
186+ 重启Redis
187+ ---------------------
0 commit comments