【Redis】Redis学习② - Redis安装

一、yum安装

     yum list redis
	 yum install redis -y
	 systemctl start redis 
	 systemctl enable redis
    [root@gbase8c_private yum.repos.d]# redis-cli
    127.0.0.1:6379> info
    # Server
    redis_version:3.2.12
    redis_git_sha1:00000000
    redis_git_dirty:0
    redis_build_id:7897e7d0e13773f
    redis_mode:standalone 

二、编译安装

	cd /usr/local/src
	tar xf redis-5.0.3.tar.gz
	make PREFIX=/usr/local/redis install
	mkdir /usr/local/redis/etc
	cp /usr/local/src/redis-5.0.3/redis.conf /usr/local/redis/etc/
	/usr/local/redis/bin/redis-server /usr/local/redis/etc/redis.conf 
	sysctl -a
	#以下配置同步所有redis服务器
	sysctl -w net.core.somaxconn=512  #tcp-backlog警告
    sysctl -w vm.overcommit_memory=1  #0表示内核将检查是否有足够可用内存供应用进程使用,如果有足够的可用内存,内存申请允许;否则申请失败,并把错误返回给应用进程
	echo never > /sys/kernel/mm/transparent_hugepage/enabled #开启大页内存动态分配,需要关闭让redis负责内存管理

   #启动日志:
	[root@gbase8c_private etc]# /usr/local/redis/bin/redis-server /usr/local/redis/etc/redis.conf
    15392:C 08 Oct 2023 20:59:22.095 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
    15392:C 08 Oct 2023 20:59:22.096 # Redis version=5.0.3, bits=64, commit=00000000, modified=0, pid=15392, just started
    15392:C 08 Oct 2023 20:59:22.096 # Configuration loaded
    15392:M 08 Oct 2023 20:59:22.096 * Increased maximum number of open files to 10032 (it was originally set to 1024).
                    _._                                                  
               _.-``__ ''-._                                             
          _.-``    `.  `_.  ''-._           Redis 5.0.3 (00000000/0) 64 bit
      .-`` .-```.  ```\/    _.,_ ''-._                                   
     (    '      ,       .-`  | `,    )     Running in standalone mode
     |`-._`-...-` __...-.``-._|'` _.-'|     Port: 6379
     |    `-._   `._    /     _.-'    |     PID: 15392
      `-._    `-._  `-./  _.-'    _.-'                                   
     |`-._`-._    `-.__.-'    _.-'_.-'|                                  
     |    `-._`-._        _.-'_.-'    |           http://redis.io        
      `-._    `-._`-.__.-'_.-'    _.-'                                   
     |`-._`-._    `-.__.-'    _.-'_.-'|                                  
     |    `-._`-._        _.-'_.-'    |                                  
      `-._    `-._`-.__.-'_.-'    _.-'                                   
          `-._    `-.__.-'    _.-'                                       
              `-._        _.-'                                           
                  `-.__.-'                                               
    
    15392:M 08 Oct 2023 20:59:22.097 # Server initialized
    15392:M 08 Oct 2023 20:59:22.097 * Ready to accept connections
    15392:signal-handler (1696769966) Received SIGINT scheduling shutdown...
    15392:M 08 Oct 2023 20:59:26.969 # User requested shutdown...
    15392:M 08 Oct 2023 20:59:26.969 * Saving the final RDB snapshot before exiting.
    15392:M 08 Oct 2023 20:59:26.972 * DB saved on disk
    15392:M 08 Oct 2023 20:59:26.972 * Removing the pid file.
    15392:M 08 Oct 2023 20:59:26.972 # Redis is now ready to exit, bye bye...

三、编译安装-编辑redis服务启动脚本

vim /usr/lib/systemd/system/redis.service
[Unit]
Description=Redis persistent key-value database
After=network.target
After=network-online.target
Wants=network-online.target

[Service]
#ExecStart=/usr/bin/redis-server /etc/redis.conf --supervised systemd
#ExecStart=/apps/redis/bin/redis-server /apps/redis/etc/redis.conf --supervised systemd
ExecStart=/usr/local/redis/bin/redis-server /usr/local/redis/etc/redis.conf --supervised systemd
#-s指定环境变量
ExecReload=/bin/kill -s HUP $MAINPID
ExecStop=/bin/kill -s QUIT $MAINPID
Type=notify
User=root
Group=root
RuntimeDirectory=redis
RuntimeDirectoryMode=0755

[Install]
WantedBy=multi-user.target

四、编译安装-创建redis用户和数据目录

     groupadd -g 1002 redis && useradd -u 1002 -g 1002 redis -s /sbin/nologin
     mkdir -pv /usr/local/redis/{etc,logs,data,run}
     chown redis.redis -R /usr/local/redis				

五、编译安装-启动redis

     systemctl daemon-reload
	 systemctl start redis
	 ss -tnl | grep 6379
	 /usr/local/redis/bin/redis-cli
	 [root@gbase8c_private home]# /usr/local/redis/bin/redis-cli
     127.0.0.1:6379> info
     # Server
     redis_version:5.0.3
     redis_git_sha1:00000000
     redis_git_dirty:0
     redis_build_id:8774dd03

六、使用客户端连接redis

注:redis.conf  中 # requirepass foobared 注释取消,并修改密码
                                bind 127.0.0.1  修改为  0.0.0.0  取消限制本地登录
     /usr/local/redis/bin/redis-cli -h IP/HOSTNAME -p PORT -a PASSWORD
	 /usr/local/redis/bin/redis-cli -h 192.168.56.199 -p 6379 

    config get requirepass   #查看当前密码
    config set requirepass 123456   #设置密码
    auth test123   #认证密码	

七、笔记

kill笔记:
Linux kill命令
信号 	名称 	描述
1 	    HUP 	挂起
2 	    INT 	中断
3 	    QUIT 	结束运行
9 	    KILL 	无条件终止
11 	    SEGV 	段错误
15 	    TERM 	尽可能终止
17 	    STOP 	无条件停止运行,但不终止
18 	    TSTP 	停止或暂停,但继续在后台运行
19 	    CONT 	在STOP或TSTP之后恢复运行
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值