编译安装redis5.0.9

首先去下载redis的安装包    安装的比较新 生产环境一般用不到这么新

http://download.redis.io/releases/

[root@centos7 ~]# ls
anaconda-ks.cfg   redis-5.0.9.tar.gz
[root@centos7 ~]# tar xvf redis-5.0.9.tar.gz    #有点长 
redis-5.0.9/
redis-5.0.9/.gitignore
redis-5.0.9/00-RELEASENOTES
redis-5.0.9/BUGS
redis-5.0.9/CONTRIBUTING
redis-5.0.9/COPYING
redis-5.0.9/INSTALL
.
.
[root@centos7 ~]# yum -y install gcc    #依赖包下载

[root@centos7 redis-5.0.9]# make clean         #之前不太干净 清一下
cd src && make clean
make[1]: Entering directory `/root/redis-5.0.9/src'
rm -rf redis-server redis-sentinel redis-cli redis-benchmark redis-check-rdb redis-check-aof *.o *.gcda *.gcno *.gcov redis.info lcov-html Makefile.dep dict-benchmark
make[1]: Leaving directory `/root/redis-5.0.9/src'

[root@centos7 redis-5.0.9]# make PREFIX=/apps/redis/ install          #开始编译安装

******************<我是省略的东西>******************

 

[root@centos7 redis-5.0.9]# ll /apps/redis/bin/           #这些是可执行文件
total 32772
-rwxr-xr-x 1 root root 4367128 Oct 19 21:07 redis-benchmark
-rwxr-xr-x 1 root root 8125424 Oct 19 21:07 redis-check-aof
-rwxr-xr-x 1 root root 8125424 Oct 19 21:07 redis-check-rdb
-rwxr-xr-x 1 root root 4808096 Oct 19 21:07 redis-cli
lrwxrwxrwx 1 root root 12 Oct 19 21:07 redis-sentinel -> redis-server
-rwxr-xr-x 1 root root 8125424 Oct 19 21:07 redis-server

把需要的文件夹建立

[root@centos7 redis-5.0.9]# mkdir /apps/redis/{etc,logs,data,run} -pv
mkdir: created directory ‘/apps/redis/etc’
mkdir: created directory ‘/apps/redis/logs’
mkdir: created directory ‘/apps/redis/data’
mkdir: created directory ‘/apps/redis/run’

[root@centos7 redis-5.0.9]# cp -a redis.conf /apps/redis/etc/       #直接把配置文件拷过去

#现在就可以直接启动了 这是选项帮助👇

[root@centos7 redis-5.0.9]# /apps/redis/bin/redis-server --help
Usage: ./redis-server [/path/to/redis.conf] [options]
./redis-server - (read config from stdin)
./redis-server -v or --version
./redis-server -h or --help
./redis-server --test-memory <megabytes>

Examples:
./redis-server (run the server with default conf)
./redis-server /etc/redis/6379.conf
./redis-server --port 7777
./redis-server --port 7777 --replicaof 127.0.0.1 8888
./redis-server /etc/myredis.conf --loglevel verbose

Sentinel mode:
./redis-server /etc/sentinel.conf --sentinel

[root@centos7 redis-5.0.9]# /apps/redis/bin/redis-server /apps/redis/etc/redis.conf     #跟上配置文件  测试使用  
6202:C 19 Oct 2020 21:13:45.364 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
6202:C 19 Oct 2020 21:13:45.364 # Redis version=5.0.9, bits=64, commit=00000000, modified=0, pid=6202, just started
6202:C 19 Oct 2020 21:13:45.364 # Configuration loaded
6202:M 19 Oct 2020 21:13:45.364 * Increased maximum number of open files to 10032 (it was originally set to 1024).
_._ 
_.-``__ ''-._ 
_.-`` `. `_. ''-._ Redis 5.0.9 (00000000/0) 64 bit
.-`` .-```. ```\/ _.,_ ''-._ 
( ' , .-` | `, ) Running in standalone mode
|`-._`-...-` __...-.``-._|'` _.-'| Port: 6379
| `-._ `._ / _.-' | PID: 6202
`-._ `-._ `-./ _.-' _.-' 
|`-._`-._ `-.__.-' _.-'_.-'| 
| `-._`-._ _.-'_.-' | http://redis.io 
`-._ `-._`-.__.-'_.-' _.-' 
|`-._`-._ `-.__.-' _.-'_.-'| 
| `-._`-._ _.-'_.-' | 
`-._ `-._`-.__.-'_.-' _.-' 
`-._ `-.__.-' _.-' 
`-._ _.-' 
`-.__.-'

6202:M 19 Oct 2020 21:13:45.365 # WARNING: The TCP backlog setting of 511 cannot be enforced because /proc/sys/net/core/somaxconn is set to the lower value of 128.
6202:M 19 Oct 2020 21:13:45.365 # Server initialized
6202:M 19 Oct 2020 21:13:45.365 # WARNING overcommit_memory is set to 0! Background save may fail under low memory condition. To fix this issue add 'vm.overcommit_memory = 1' to /etc/sysctl.conf and then reboot or run the command 'sysctl vm.overcommit_memory=1' for this to take effect.
6202:M 19 Oct 2020 21:13:45.365 # WARNING you have Transparent Huge Pages (THP) support enabled in your kernel. This will create latency and memory usage issues with Redis. To fix this issue run the command 'echo never > /sys/kernel/mm/transparent_hugepage/enabled' as root, and add it to your /etc/rc.local in order to retain the setting after a reboot. Redis must be restarted after THP is disabled.
6202:M 19 Oct 2020 21:13:45.365 * Ready to accept connections

#有三个警告信息  一会处理👆

--------------------------------------------------------------------------------------------------------

#👇这是第二个端口 同一台机

[root@centos7 ~]# ss -ntl #再开个端口看看服务起来没
State Recv-Q Send-Q Local Address:Port Peer Address:Port 
LISTEN 0 128 127.0.0.1:6379 *:*

[root@centos7 ~]# /apps/redis/bin/redis-cli 
127.0.0.1:6379> set foo bar
OK
127.0.0.1:6379> get foo
"bar"

---------------------------------------------------------------------------------------------------------

开始解除警报

@1 三次握手时 server端收到client ack确认号之后的队列值 太小了 改大点

[root@centos7 ~]# vim /etc/sysctl.conf

# sysctl settings are defined through files in
# /usr/lib/sysctl.d/, /run/sysctl.d/, and /etc/sysctl.d/.
#
# Vendors settings live in /usr/lib/sysctl.d/.
# To override a whole file, create a new file with the same in
# /etc/sysctl.d/ and put new settings there. To override
# only specific settings, add a file with a lexically later
# name in /etc/sysctl.d/ and put new settings there.
#
# For more information, see sysctl.conf(5) and sysctl.d(5).

net.core.somaxconn = 1024

[root@centos7 ~]# sysctl -p             #让她生效
net.core.somaxconn = 1024

@2 0=查看是否有够用的内存 有就给 没有就报错

      1=可分配所有内存 不管当前用多少

      2=想咋用咋用 超出都行

[root@centos7 ~]# vim /etc/sysctl.conf

# sysctl settings are defined through files in
# /usr/lib/sysctl.d/, /run/sysctl.d/, and /etc/sysctl.d/.
#
# Vendors settings live in /usr/lib/sysctl.d/.
# To override a whole file, create a new file with the same in
# /etc/sysctl.d/ and put new settings there. To override
# only specific settings, add a file with a lexically later
# name in /etc/sysctl.d/ and put new settings there.
#
# For more information, see sysctl.conf(5) and sysctl.d(5).

net.core.somaxconn = 1024
vm.overcommit_memory = 1

[root@centos7 ~]# sysctl -p
net.core.somaxconn = 1024
vm.overcommit_memory = 1

@3大页内存  需要关闭让redis负责内存管理

[root@centos7 ~]# echo never > /sys/kernel/mm/transparent_hugepage/enabled

再重启一下服务

[root@centos7 redis-5.0.9]# /apps/redis/bin/redis-server /apps/redis/etc/redis.conf 
6486:C 19 Oct 2020 21:43:56.412 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
6486:C 19 Oct 2020 21:43:56.412 # Redis version=5.0.9, bits=64, commit=00000000, modified=0, pid=6486, just started
6486:C 19 Oct 2020 21:43:56.412 # Configuration loaded
6486:M 19 Oct 2020 21:43:56.412 * Increased maximum number of open files to 10032 (it was originally set to 1024).
_._ 
_.-``__ ''-._ 
_.-`` `. `_. ''-._ Redis 5.0.9 (00000000/0) 64 bit
.-`` .-```. ```\/ _.,_ ''-._ 
( ' , .-` | `, ) Running in standalone mode
|`-._`-...-` __...-.``-._|'` _.-'| Port: 6379
| `-._ `._ / _.-' | PID: 6486
`-._ `-._ `-./ _.-' _.-' 
|`-._`-._ `-.__.-' _.-'_.-'| 
| `-._`-._ _.-'_.-' | http://redis.io 
`-._ `-._`-.__.-'_.-' _.-' 
|`-._`-._ `-.__.-' _.-'_.-'| 
| `-._`-._ _.-'_.-' | 
`-._ `-._`-.__.-'_.-' _.-' 
`-._ `-.__.-' _.-' 
`-._ _.-' 
`-.__.-'

6486:M 19 Oct 2020 21:43:56.413 # Server initialized
6486:M 19 Oct 2020 21:43:56.413 * DB loaded from disk: 0.000 seconds
6486:M 19 Oct 2020 21:43:56.413 * Ready to accept connections

想让它开机生效  得放在这👇

[root@centos7 ~]# vim /etc/rc.d/rc.local

#!/bin/bash
# THIS FILE IS ADDED FOR COMPATIBILITY PURPOSES
#
# It is highly advisable to create own systemd services or udev rules
# to run scripts during boot instead of using this file.
#
# In contrast to previous versions due to parallel execution during boot
# this script will NOT be run after all other services.
#
# Please note that you must run 'chmod +x /etc/rc.d/rc.local' to ensure
# that this script will be executed during boot.

touch /var/lock/subsys/local
echo never > /sys/kernel/mm/transparent_hugepage/enabled

[root@centos7 ~]# chmod a+x /etc/rc.d/rc.local           #centos7默认没有执行权限   给它加上才能开机启动

开始准备redis服务启动文件

这是从别的机器上copy的一份

[root@centos8 ~]# scp /usr/lib/systemd/system/redis.service 10.0.0.100:/usr/lib/systemd/system/redis.service
The authenticity of host '10.0.0.100 (10.0.0.100)' can't be established.
ECDSA key fingerprint is SHA256:jb+JVp1mHGLt/2vGwE2RtsYAO/vdfE/1X0gV/YHxVWs.
Are you sure you want to continue connecting (yes/no/[fingerprint])? yes
Warning: Permanently added '10.0.0.100' (ECDSA) to the list of known hosts.
root@10.0.0.100's password: 
redis.service 100% 316 169.6KB/s 00:00
[root@centos7 ~]# 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=/apps/redis/bin/redis-server /apps/redis/etc/redis.conf --supervised systemd
ExecStop=/bin/kill -s HUP $MAINPID                      #编译安装没有shutdown文件    改成kill
ExecReload=/bin/kill -s QUIT $MAINPID
Type=notify
User=redis                   
Group=redis
RuntimeDirectory=redis
RuntimeDirectoryMode=0755

[Install]
WantedBy=multi-user.target

没有账号  创建出来

[root@centos7 ~]# useradd redis -s /sbin/nologin
[root@centos7 ~]# id redis
uid=1001(redis) gid=1001(redis) groups=1001(redis)

把服务的目录全改成redis

[root@centos7 ~]# chown redis.redis /apps/redis/ -R

试试好不好使

[root@centos7 ~]# systemctl daemon-reload
[root@centos7 ~]# systemctl start redis
[root@centos7 ~]# ss -ntl
State      Recv-Q Send-Q                    Local Address:Port                                   Peer Address:Port              
LISTEN     0      511                                   *:6379                                              *:*                  
LISTEN     0      128                                   *:22                                                *:*                  
LISTEN     0      100                           127.0.0.1:25                                                *:*                  
LISTEN     0      128                                  :::22                                               :::*                  
LISTEN     0      100                                 ::1:25                                               :::*                  
[root@centos7 ~]# systemctl stop redis
[root@centos7 ~]# ss -ntl
State      Recv-Q Send-Q                    Local Address:Port                                   Peer Address:Port              
LISTEN     0      128                                   *:22                                                *:*                  
LISTEN     0      100                           127.0.0.1:25                                                *:*                  
LISTEN     0      128                                  :::22                                               :::*                  
LISTEN     0      100                                 ::1:25                                               :::*                  
[root@centos7 ~]# 
[root@centos7 ~]# systemctl restart redis
[root@centos7 ~]# ss -ntl
State      Recv-Q Send-Q                    Local Address:Port                                   Peer Address:Port              
LISTEN     0      511                                   *:6379                                              *:*                  
LISTEN     0      128                                   *:22                                                *:*                  
LISTEN     0      100                           127.0.0.1:25                                                *:*                  
LISTEN     0      128                                  :::22                                               :::*                  
LISTEN     0      100                                 ::1:25                                               :::*    

 👇以后就不用写前面那一大串了   直接写命令👇

[root@centos7 ~]# ln -s /apps/redis/bin/* /usr/bin/

 

posted @ 2020-10-19 21:50  养了27年的狗  阅读(343)  评论(0编辑  收藏  举报
Live2D