Ubuntu Server 21.04 Install A key deployment Install Redis
Posted CIAS
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Ubuntu Server 21.04 Install A key deployment Install Redis相关的知识,希望对你有一定的参考价值。
前言
Ubuntu——公共云、数据中心和边缘上最受欢迎的 Linux 发行版。自成立以来,Ubuntu 一直在获得市场份额,截至今天已接近 50%。
redis
Re dis(Remote Dictionary Server ),即远程字典服务,是一个开源的使用ANSI C语言编写、支持网络、可基于内存亦可持久化的日志型、Key-Value数据库,并提供多种语言的API。
系统下载安装
ubuntu 系统安装&下载 | redis下载 | RedisDesktopManager | Linux MobaXterm 远程连接工具 |
download | download | download | download |
切换sh为bash
dpkg-reconfigure dash
-
输入NO
-
查看切换结果,结果/bin/sh -> bash切换成功
ls -al /bin/sh
一键部署 redis
- /usr/local/redis/bin(启动相关),/etc(配置文件),/logs(日志),/data(数据落地目录)
- 密码1234.com
vim /ubuntu21-redis-install.sh
#!/bin/sh
# -*- coding: utf-8 -*-
# Author: CIASM
# Date: 2022/03/31
#Define data path variables
data_downloads=/data/downloads
mkdir -p $data_downloads
#Define redis path variables
Redis_URL=http://download.redis.io/releases/
Redis_FILE=redis-6.2.6.tar.gz
Redis_FILE_DIR=redis-6.2.6
Redis_PREFIX=/usr/local/redis
Redis_6379_conf=redis-6379.conf
Redis_etc=etc
Redis_data=data
Redis_bin=bin
Redis_logs=logs
Redis_6379_service=redis-6379.service
Redis_6379_pid=redis-6379.pid
Redis_6379_log=redis-6379.log
systemd_system=/usr/lib/systemd/system
install_redis ()
if [ ! -d $Redis_PREFIX ];then
apt install build-essential -y
wget -N -P $data_downloads $Redis_URL/$Redis_FILE
tar -xf $data_downloads/$Redis_FILE -C $data_downloads
if [ $? -eq 0 ];then
mv $data_downloads/$Redis_FILE_DIR $Redis_PREFIX
cd $Redis_PREFIX && make
mkdir -p $Redis_PREFIX//$Redis_bin,/$Redis_etc,/$Redis_logs,/$Redis_data && chmod +x $Redis_PREFIX//$Redis_bin,/$Redis_etc,/$Redis_logs,/$Redis_data
cd $Redis_PREFIX/src && cp -rf redis-cli redis-server mkreleasehdr.sh redis-check-aof redis-check-rdb redis-benchmark $Redis_PREFIX/$Redis_bin
cp -rf $Redis_PREFIX/redis.conf $Redis_PREFIX/$Redis_etc/$Redis_6379_conf
ln -s $Redis_PREFIX/$Redis_bin/* /usr/local/sbin/
redis_config
echo -e "\\033[32mThe redis Install Success...\\033[0m"
else
echo -e "\\033[31mThe redis Install Failed...\\033[0m"
exit 1
fi
else
echo -e "\\033[31mThe redis already Install...\\033[0m"
exit 1
fi
redis_config ()
echo "limits config"
sleep 3
cat >>/etc/security/limits.conf<<EOF
* soft nproc 65535
* hard nproc 65535
* soft nofile 65535
* hard nofile 65535
EOF
echo "system Maximum number of connections"
echo "fs.file-max=65535" >> /etc/sysctl.conf
echo "vm.overcommit_memory = 1" >> /etc/sysctl.conf
echo "net.core.somaxconn= 1024" >> /etc/sysctl.conf
echo never > /sys/kernel/mm/transparent_hugepage/enabled
sysctl -p
echo "redis-6379.conf config"
sleep 3
sed -i 's/daemonize no/daemonize yes/g' $Redis_PREFIX/$Redis_etc/$Redis_6379_conf
sed -i 's/bind 127.0.0.1/bind 0.0.0.0/g' $Redis_PREFIX/$Redis_etc/$Redis_6379_conf
sed -i '902a requirepass 1234.com' $Redis_PREFIX/$Redis_etc/$Redis_6379_conf
sed -i 's/stop-writes-on-bgsave-error yes/stop-writes-on-bgsave-error no/g' $Redis_PREFIX/$Redis_etc/$Redis_6379_conf
sed -i "s/pidfile \\/var\\/run\\/$Redis_6379_pid/pidfile \\/usr\\/local\\/redis\\/$Redis_6379_pid/g" $Redis_PREFIX/$Redis_etc/$Redis_6379_conf
sed -i "s/dir \\.\\//dir \\/usr\\/local\\/redis\\/$Redis_data/g" $Redis_PREFIX/$Redis_etc/$Redis_6379_conf
sed -i "s/logfile \\"\\"/logfile \\"\\/usr\\/local\\/redis\\/$Redis_logs\\/$Redis_6379_log\\"/g" $Redis_PREFIX/$Redis_etc/$Redis_6379_conf
sed -i "s/dbfilename dump.rdb/dbfilename dump.rdb/g" $Redis_PREFIX/$Redis_etc/$Redis_6379_conf
sed -i "s/appendfilename \\"appendonly.aof\\"/appendfilename \\"appendonly.aof\\"/g" $Redis_PREFIX/$Redis_etc/$Redis_6379_conf
#port config
#sed -i 's/port 6379/port 6380/g' $Redis_PREFIX/$Redis_etc/$Redis_6379_conf
#sed -i '213a masterauth 1234.com' /$Redis_PREFIX/$Redis_etc/$Redis_6379_conf
#redis.service config
echo -e "[Unit]\\nDescription=redis-server\\nAfter=network.target\\n[Service]\\nType=forking\\nExecStart=$Redis_PREFIX/$Redis_bin/redis-server $Redis_PREFIX/$Redis_etc/$Redis_6379_conf\\nExecStop=$Redis_PREFIX/$Redis_bin/redis-cli shutdown\\nPrivateTmp=true\\n[Install]\\nWantedBy=multi-user.target" > $systemd_system/$Redis_6379_service
chmod 754 $systemd_system/$Redis_6379_service
echo "start redis"
sleep 3
systemctl daemon-reload && systemctl start --now $Redis_6379_service
#redis firewall config
rm -rf $data_downloads/*
main ()
install_redis
main
执行安装
sh /ubuntu21-redis-install.sh
以上是关于Ubuntu Server 21.04 Install A key deployment Install Redis的主要内容,如果未能解决你的问题,请参考以下文章
Ubuntu Server 21.04 Install ansible
Ubuntu Server 21.04 Install ansible
Ubuntu Server 21.04 Install ansible
Ubuntu Server 21.04 Install one key Generic mysql 8.0.26