一、需求
1.修改主机名,本地解析、yum源
2.redis的安装
二、环境准备
主机 |
角色 |
IP |
prd-redis001 |
Redis服务器 |
ec2-69-230-214-114.cn-northwest-1.compute.amazonaws.com.cn |
三、相关软件版本选择
软件名称 |
版本号 |
下载地址 |
redis |
6.2.1 |
https://redis.io/download |
四、基本优化
#1.修改主机名
[root@ip-16-0-1-189 ~]# hostnamectl set-hostname prd-redis001
#2.查看主机名
[root@ip-16-0-1-189 ~]# hostname
prd-redis001
#3.备份yum源
[root@prd-redis001 ~]# mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup
#4.配置yum源
[root@prd-redis001 ~]# curl -o /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 2523 100 2523 0 0 9445 0 --:--:-- --:--:-- --:--:-- 9449
[root@prd-redis001 ~]# curl -o /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 664 100 664 0 0 13414 0 --:--:-- --:--:-- --:--:-- 13551
#5.查看yum源
[root@prd-redis001 ~]# ll /etc/yum.repos.d/
total 44
-rw-r--r-- 1 root root 2523 Mar 12 08:34 CentOS-Base.repo
-rw-r--r--. 1 root root 1664 May 17 2018 CentOS-Base.repo.backup
-rw-r--r--. 1 root root 664 Mar 12 08:35 epel.repo
#6.安装常用软件
[root@prd-redis001 ~]# yum -y install tree nmap sysstat lrzsz telnet bash-completion bash-completion-extras vim lsof net-tools rsync ntpdate nfs-utils wget
#7.同步系统时间
1.手动同步系统时间
[root@prd-redis001 ~]# ntpdate ntp.aliyun.com
23 Mar 03:30:13 ntpdate[14122]: adjust time server 203.107.6.88 offset 0.019851 sec
[root@prd-redis001 ~]# date
Tue Mar 23 03:30:15 UTC 2021
2.做定时同步系统时间
[root@prd-redis001 ~]# echo '#Timing synchronization time' >>/var/spool/cron/root
[root@prd-redis001 ~]# echo '*/5 * * * * /usr/sbin/ntpdate ntp1.aliyun.com &>/dev/null' >>/var/spool/cron/root
3.查看定时任务
[root@prd-redis001 ~]# crontab -l
#Timing synchronization time
*/5 * * * * /usr/sbin/ntpdate ntp1.aliyun.com &>/dev/null
五、修改本地解析
[root@prd-redis001 ~]# vi /etc/hosts127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4::1 localhost localhost.localdomain localhost6 localhost6.localdomain616.0.1.189 prd-inner-redis001ec2-69-230-214-114.cn-northwest-1.compute.amazonaws.com.cn prd-outer-redis001
六、格式化文件系统
#1.查看所有磁盘分区情况
[root@prd-redis001 ~]# fdisk -l
Disk /dev/nvme1n1: 107.4 GB, 107374182400 bytes, 209715200 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk /dev/nvme0n1: 53.7 GB, 53687091200 bytes, 104857600 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk label type: dos
Disk identifier: 0x000acf0a
Device Boot Start End Blocks Id System
/dev/nvme0n1p1 * 2048 104857566 52427759+ 83 Linux
#2.进行磁盘分区
[root@prd-redis001 ~]# fdisk /dev/nvme1n1
Welcome to fdisk (util-linux 2.23.2).
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.
Device does not contain a recognized partition table
Building a new DOS disklabel with disk identifier 0x5619bba8.
Command (m for help): n
Partition type:
p primary (0 primary, 0 extended, 4 free)
e extended
Select (default p): p
Partition number (1-4, default 1):
First sector (2048-209715199, default 2048):
Using default value 2048
Last sector, +sectors or +size{K,M,G} (2048-209715199, default 209715199):
Using default value 209715199
Partition 1 of type Linux and of size 100 GiB is set
Command (m for help): w
The partition table has been altered!
Calling ioctl() to re-read partition table.
Syncing disks.
#3.重读分区表
[root@prd-redis001 ~]# partprobe
#4.磁盘格式化
[root@prd-redis001 ~]# mkfs.xfs /dev/nvme1n1p1 -f
meta-data=/dev/nvme1n1p1 isize=512 agcount=4, agsize=6553536 blks
= sectsz=512 attr=2, projid32bit=1
= crc=1 finobt=0, sparse=0
data = bsize=4096 blocks=26214144, imaxpct=25
= sunit=0 swidth=0 blks
naming =version 2 bsize=4096 ascii-ci=0 ftype=1
log =internal log bsize=4096 blocks=12799, version=2
= sectsz=512 sunit=0 blks, lazy-count=1
realtime =none extsz=4096 blocks=0, rtextents=0
#5.新建数据目录data
[root@prd-redis001 ~]# mkdir /data
#6.挂载目录
[root@prd-redis001 ~]# mount /dev/nvme1n1p1 /data/
#7.查看挂载点
[root@prd-redis001 ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/nvme0n1p1 50G 1.3G 49G 3% /
devtmpfs 1.8G 0 1.8G 0% /dev
tmpfs 1.8G 0 1.8G 0% /dev/shm
tmpfs 1.8G 17M 1.8G 1% /run
tmpfs 1.8G 0 1.8G 0% /sys/fs/cgroup
tmpfs 356M 0 356M 0% /run/user/1000
/dev/nvme1n1p1 100G 33M 100G 1% /data
#8.实现永久挂载
1.查看UUID
[root@prd-redis001 ~]# blkid
/dev/nvme0n1p1: UUID="8c1540fa-e2b4-407d-bcd1-59848a73e463" TYPE="xfs"
/dev/nvme1n1: PTTYPE="dos"
/dev/nvme1n1p1: UUID="da7acd39-597f-4a62-9cc9-a9979a53700c" TYPE="xfs"
/dev/nvme0n1: PTTYPE="dos"
2.编辑永久挂载点文件
[root@prd-redis001 ~]# vi /etc/fstab
#
# /etc/fstab
# Created by anaconda on Tue Jun 5 14:06:12 2018
#
# Accessible filesystems, by reference, are maintained under '/dev/disk'
# See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info
#
UUID=8c1540fa-e2b4-407d-bcd1-59848a73e463 / xfs defaults 0 0
UUID=da7acd39-597f-4a62-9cc9-a9979a53700c / xfs defaults 0 0
七、安装Redis
1.下载安装包
#1.创建软件存放目录
[root@prd-redis001 ~]# mkdir /data/software
#2.上传安装包
[root@prd-redis001 ~]# cd /data/software
[root@prd-redis001 software]# rz redis-6.2.1.tar.gz
2.安装依赖
[root@prd-redis001 software]# yum install -y cpp binutils glibc glibc-kernheaders glibc-common glibc-devel gcc make tcl
3.更新gcc版本
centos7 默认的 gcc 版本小于 5.3 无法编译,需要先安装gcc新版才能编译
[root@prd-redis001 software]# yum -y install centos-release-scl
[root@prd-redis001 software]# yum -y install devtoolset-9-gcc devtoolset-9-gcc-c++ devtoolset-9-binutils
#临时生效,退出 shell 或重启会恢复原 gcc 版本
[root@prd-redis001 software]# scl enable devtoolset-9 bash
#永久生效
[root@prd-redis001 software]# echo "source /opt/rh/devtoolset-9/enable" >>/etc/profile
4 .编译安装
[root@prd-redis001 software]# tar zxf redis-6.2.1.tar.gz -C /opt/
[root@prd-redis001 software]# cd /opt/redis-6.2.1/
[root@prd-redis001 /opt/redis-6.2.1]# make && make install
5.修改redis.conf
[root@prd-redis001 redis-6.2.1]# mkdir /etc/redis
[root@prd-redis001 redis-6.2.1]# cp redis.conf /etc/redis/
[root@prd-redis001 redis-6.2.1]# vim /etc/redis/redis.conf
#不限制远程登录IP
bind 0.0.0.0
#关闭保护模式
protected-mode no
#修改端口号
port 16379
#开启守护进程模式
daemonize yes
#添加登录密码
requirepass xxxxxxxxxxxxxx
6. 配置system启动
#1.创建配置目录
[root@prd-redis001 redis-6.2.1]# mkdir /data/redis/
#2.配置system
[root@prd-redis001 /opt/redis-6.2.1/src]# vim/etc/systemd/system/redis.service
[Unit]
Description=Redis
After=network.target
[Service]
Type=forking
ExecStart=/opt/redis-6.2.1/src/redis-server /etc/redis/redis.conf
#ExecReload=/opt/redis-6.2.1/src/redis-server -s reload
#ExecStop=/opt/redis-6.2.1/src/redis-server -s stop
PrivateTmp=true
[Install]
WantedBy=multi-user.target
#3.使服务自动运行
[root@prd-redis001 redis-6.2.1]# systemctl daemon-reload
[root@prd-redis001 redis-6.2.1]# systemctl enable redis.service
Created symlink from /etc/systemd/system/multi-user.target.wants/redis.service to /etc/systemd/system/redis.service.
#4.启动服务
[root@prd-redis001 redis-6.2.1]# systemctl restart redis
[root@prd-redis001 redis-6.2.1]# systemctl status redis
#4.验证服务
[root@prd-redis001 redis-6.2.1]# netstat -lntp
Active Internet connections (only servers)Proto Recv-Q Send-Q Local Address
Foreign Address State PID/Program name tcp
0 0 0.0.0.0:16379 0.0.0.0:* LISTEN 25568/redis-server tcp
0 0 0.0.0.0:111 0.0.0.0:* LISTEN 523/rpcbind tcp
0 0 0.0.0.0:22 0.0.0.0:* LISTEN 1273/sshd tcp
0 0 127.0.0.1:25 0.0.0.0:* LISTEN 1058/master tcp6
0 0 :::16379 :::* LISTEN 25568/redis-server tcp6
0 0 :::111 :::* LISTEN 523/rpcbind tcp6
0 0 :::22 :::* LISTEN 1273/sshd tcp6
0 0 ::1:25 :::* LISTEN 1058/master
7.配置环境变量
#1.配置环境变量
[root@prd-redis001 /opt/redis-6.2.1/src]# vim /etc/profile.d/redis.sh
export PATH=/opt/redis-6.2.1/src:$PATH
#2.使其配置生效
[root@prd-redis001 /opt/redis-6.2.1/src]# source /etc/profile
8.测试redis连接
#1.验证密码登录成功
[root@prd-redis001 /opt/redis-6.2.1/src]# redis-cli -p 16379
127.0.0.1:16379> auth 密码
OK
127.0.0.1:16379>