redis部署

一:规划目录

/data/soft 下载目录

/opt/redis_6379/{conf,logs,pid} 安装目录:日志目录,pid目录,配置目录

/data/redis_6379/ 数据目录

二:编译安装

 mkdir /data/soft -p

cd /data/soft/

tar xf redis-5.0.7.tar.gz -C /opt/

cd /opt/

ln -sv /opt/redis-5.0.7/ /opt/redis

cd /opt/redis

yum install -y gcc

make    #如果报错执行----make MALLOC=libc

make install

PS:

1.编译安装解释
./config

指定编译参数
make

按照要求编译生成可执行程序,把生成的可执行文件复制到/usr/local/bin/
make install

 

三:编写配置文件

mkdir -p /opt/redis_6379/{conf,logs,pid}

mkdir -p /data/redis_6379

cat >/opt/redis_6379/conf/redis_6379.conf<<EOF

daemonize yes

bind 127.0.0.1 10.0.0.101

port 6379

pidfile /opt/redis_6379/pid/redis_6379.pid

logfile /opt/redis_6379/logs/redis_6379.log

EOF

四:启动

redis-server /opt/redis_6379/conf/redis_6379.conf

五:检查

netstat -lntup|grep 6379

ps -ef|grep redis

 

 

六:连接

[root@elk101 tmp]# redis-cli
127.0.0.1:6379> set k1 v1
OK
127.0.0.1:6379> get k1
"v1"

 

七:关闭

127.0.0.1:6379> shutdown

[root@elk101 tmp]# redis-cli shutdown

 

八:通过system启动配置

[root@elk101 tmp]# groupadd redis -g 2000
[root@elk101 tmp]# useradd redis -u 2000 -g 2000 -M -s /sbin/nologin
[root@elk101 tmp]# chown -R redis.redis /opt/redis*
[root@elk101 tmp]# chown -R redis.redis /data/redis*
[root@elk101 tmp]# cat >/usr/lib/systemd/system/redis.service<<EOF
> [Unit]
> Description=Redis persistent key-value database
> After=network.target
> After=network-online.target
> Wants=network-online.target
>
> [Service]
> ExecStart=/usr/local/bin/redis-server /opt/redis_6379/conf/redis_6379.conf --supervised systemd
> ExecStop=/usr/local/bin/redis-cli shutdown
> Type=notify
> User=redis
> Group=redis
> RuntimeDirectory=redis
> RuntimeDirectoryMode=0755
>
> [Install]
> WantedBy=multi-user.target
> EOF
[root@elk101 tmp]# systemctl daemon-reload
[root@elk101 tmp]# systemctl start redis
[root@elk101 tmp]# ps -ef|grep redis
redis 8092 1 0 19:51 ? 00:00:00 /usr/local/bin/redis-server 127.0.0.1:6379
root 8097 2001 0 19:51 pts/2 00:00:00 grep --color=auto redis
[root@elk101 tmp]# systemctl stop redis

 

配置文件参考地址:

https://www.cnblogs.com/alaska/p/12539617.html

posted on 2021-07-04 19:53  弓长三寿  阅读(91)  评论(0编辑  收藏  举报