1、一键部署redis,版本任意指定:
如果有朋友想自定义安装路径,或者Redis的默认端口等,可以直接修改前面的变量。这个脚本主要是用到了redis源码自带的初始化脚本。如果遇到报错可以评论区反馈,由于个人写脚本不太喜欢注释,所以劳费各人仔细端详了。

#!/bin/bash
#by lutixia
#############################

REDIS_DIR="/usr/local/redis"
REDIS_IP="0.0.0.0"
REDIS_PORT="6379"
REDIS_VERSION="redis-5.0.5"

init() {
	echo -e "$REDIS_PORT\n$REDIS_DIR/$REDIS_PORT/$REDIS_PORT.conf\n$REDIS_DIR/$REDIS_PORT/$REDIS_PORT.log\n$REDIS_DIR/$REDIS_PORT\n${REDIS_DIR}/bin/redis-server" |/usr/src/$REDIS_VERSION/utils/install_server.sh
	}

install() {
		rm -rf $REDIS_VERSION && tar xf  $REDIS_VERSION.tar.gz
                cd $REDIS_VERSION  && make PREFIX=$REDIS_DIR  install
                echo -e "$REDIS_PORT\n$REDIS_DIR/$REDIS_PORT/$REDIS_PORT.conf\n$REDIS_DIR/$REDIS_PORT/$REDIS_PORT.log\n$REDIS_DIR/$REDIS_PORT\n$REDIS_DIR/bin/redis-server" | /usr/src/$REDIS_VERSION/utils/install_server.sh
                sed -i "/^bind/cbind $REDIS_IP" $REDIS_DIR/$REDIS_PORT/$REDIS_PORT.conf
                /etc/init.d/redis_$REDIS_PORT restart
	}

#安装redis
if [ -x $REDIS_DIR/bin/redis-server ];then
                echo "redis已经编译安装完成。"
		init
else
	#创建目录
	if [ ! -d $REDIS_DIR ];then
		mkdir -p $REDIS_DIR
		cd $REDIS_DIR && mkdir $REDIS_PORT
	else
		rm -rf $REDIS_DIR/*
		cd $REDIS_DIR && mkdir $REDIS_PORT
	fi
	cd /usr/src/
	if [ ! -f $REDIS_VERSION.tar.gz ];then
		wget http://download.redis.io/releases/$REDIS_VERSION.tar.gz 
		install
	else
		install
        fi
fi

2、redis单机集群一键部署:

#!/bin/bash
# by lutixia
#############################

REDIS_DIR="/usr/local/redis-cluster"
REDIS_IP="127.0.0.1"

#安装redis
cd /usr/src/
if [ -d /usr/src/redis-5.0.5 ] && [ -x /usr/local/redis/bin/redis-server ];then
	echo "redis已经编译安装完成。"
else
	if [ ! -f redis-5.0.5.tar.gz ];then
		wget -c http://download.redis.io/releases/redis-5.0.5.tar.gz
		tar xf  redis-5.0.5.tar.gz && cd redis-5.0.5 
		make clean &&  make  PREFIX=/usr/local/redis install && cp /usr/local/redis/bin/redis-server $REDIS_DIR/
	else
		tar xf  redis-5.0.5.tar.gz && cd redis-5.0.5 
		make clean &&  make  PREFIX=/usr/local/redis install && cp /usr/local/redis/bin/redis-server $REDIS_DIR/

	fi
fi
#部署redis集群:
#创建目录
if [ ! -d $REDIS_DIR ];then
	mkdir -p $REDIS_DIR
	cd $REDIS_DIR && mkdir 700{0..5}
else
	rm -rf $REDIS_DIR/*
	cd $REDIS_DIR && mkdir 700{0..5}
fi

\cp /usr/local/redis/bin/redis-* $REDIS_DIR/
for i in `seq 0 5`;do
	 echo -e "700$i\n$REDIS_DIR/700$i/700$i.conf\n$REDIS_DIR/700$i/700$i.log\n$REDIS_DIR/700$i/\n$REDIS_DIR/redis-server" |/usr/src/redis-5.0.5/utils/install_server.sh
done

pkill redis-server
for i in `seq 0 5`;do
	sed -i "s/# cluster-enabled yes/cluster-enabled yes/" $REDIS_DIR/700$i/700$i.conf
	sed -i "s/# cluster-config-file nodes-6379.conf/cluster-config-file nodes-700$i.conf/"  $REDIS_DIR/700$i/700$i.conf
	sed -i "s/# cluster-node-timeout 15000/cluster-node-timeout 15000/" $REDIS_DIR/700$i/700$i.conf
	sed -i "s/appendonly no/appendonly yes/" $REDIS_DIR/700$i/700$i.conf
	#sed -i "s/bind 127.0.0.1/bind 0.0.0.0/" $REDIS_DIR/700$i/700$i.conf
	/etc/init.d/redis_700$i restart  &>/dev/null
	sleep 2
done
value=`ps -ef|grep redis-server|grep -v grep|wc -l`
if [ $value -eq 6 ];then
	echo yes | $REDIS_DIR/redis-cli --cluster create $REDIS_IP:7000 $REDIS_IP:7001 $REDIS_IP:7002 $REDIS_IP:7003 $REDIS_IP:7004 $REDIS_IP:7005 --cluster-replicas 1
else
	echo "redis 集群有部分节点启动失败"
fi

3、一键源码部署lnmp,版本任意选:
这个脚本可以根据需要安装单个nginx或者PHP等,也可以一键部署Nginx、PHP、MySQL。版本和路径也是可以根据自己的需要指定的,如果遇到报错可以评论区反馈,由于个人写脚本不太喜欢注释,所以劳费各人仔细端详了。

#!/bin/bash
#by lutixia
#############################

# 设置源码目录:
BASE_DIR=/usr/src/

### 部署nginx:
install_nginx() {
	NGINX_VERSION=1.18.0

	if [ -d /usr/local/nginx ];then
		echo "请核实在/usr/local/目录下是否已经安装nginx服务!"
	else
		# 安装依赖:
		yum install wget pcre-devel zlib-devel -y 
		wget -c -P "$BASE_DIR" http://nginx.org/download/nginx-$NGINX_VERSION.tar.gz 
		if [ $? -ne 0 ];then  
			echo "请检查网络是否正常或者链接是否失效!"
		else	
			cd "$BASE_DIR"
			tar xf nginx-$NGINX_VERSION.tar.gz
			cd nginx-$NGINX_VERSION
			./configure --prefix=/usr/local/nginx && make && make install 
			echo "nginx 部署成功!"
		fi
	fi
}

### 部署php:

install_php() {
	PHP_VERSION=5.6.8
	if [ -d /usr/local/php ];then
		echo "请核实在/usr/local/目录下是否已经安装php服务!"
	else
		# 安装依赖:
		yum -y install wget  gd curl curl-devel libjpeg libjpeg-devel libpng \
		libpng-devel freetype freetype-devel libxml2 libxml2-devel 

		wget -c -P /usr/src/  http://mirrors.sohu.com/php/php-$PHP_VERSION.tar.gz 
		if [ $? -ne 0 ];then  
			echo "请检查网络是否正常或者链接是否失效!"
		else
			cd $BASE_DIR
			tar xf php-$PHP_VERSION.tar.gz
			cd php-$PHP_VERSION
			./configure  --prefix=/usr/local/php  \
						 --enable-fpm \
						 --enable-debug \
						 --with-gd \
						 --with-jpeg-dir \
						 --with-png-dir \
						 --with-freetype-dir \
						 --enable-mbstring \
						 --with-curl \
						 --with-mysql=mysqlnd \
						 --with-mysqli=mysqlnd \
						 --with-pdo-mysql=mysqlnd \
						 --with-config-file-path=/usr/local/php/etc \
						 --with-zlib-dir
			 [ $? -eq 0 ] && {
					make && make install
			}
			# 初始化PHP:
			\cp php.ini-development  /usr/local/php/etc/php.ini
			\cp /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf
			\cp sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
			chmod +x /etc/init.d/php-fpm
			echo "php 部署成功!"
		fi
	fi
}


### 部署MySQL

install_mysql() {
	MYSQL_VERSION=5.5.60
	if [ -d  /usr/local/mysql ];then
			echo "请核实在/usr/local/目录下是否已经安装MySQL服务!"
	else
		# 安装依赖:
		yum install wget gcc libaio bison gcc-c++  git cmake  ncurses-devel ncurses -y
		[ $? -eq 0 ] && {
			wget -c -P $BASE_DIR \
			http://mirrors.163.com/mysql/Downloads/MySQL-5.5/mysql-$MYSQL_VERSION.tar.gz
			if [ $? -ne 0 ];then  
				echo "请检查网络或者链接是否失效!"
			else
				cd $BASE_DIR
				tar xf mysql-$MYSQL_VERSION.tar.gz
				cd mysql-$MYSQL_VERSION
				cmake . -DCMAKE_INSTALL_PREFIX=/usr/local/mysql/ \
					-DMYSQL_UNIX_ADDR=/tmp/mysql.sock \
					-DMYSQL_DATADIR=/data/mysql \
					-DSYSCONFDIR=/usr/local/mysql/ \
					-DMYSQL_USER=mysql \
					-DMYSQL_TCP_PORT=3306 \
					-DWITH_XTRADB_STORAGE_ENGINE=1 \
					-DWITH_INNOBASE_STORAGE_ENGINE=1 \
					-DWITH_PARTITION_STORAGE_ENGINE=1 \
					-DWITH_BLACKHOLE_STORAGE_ENGINE=1 \
					-DWITH_MYISAM_STORAGE_ENGINE=1 \
					-DWITH_READLINE=1 \
					-DENABLED_LOCAL_INFILE=1 \
					-DWITH_EXTRA_CHARSETS=1 \
					-DDEFAULT_CHARSET=utf8 \
					-DDEFAULT_COLLATION=utf8_general_ci \
					-DEXTRA_CHARSETS=all \
					-DWITH_BIG_TABLES=1 \
					-DWITH_DEBUG=0				
				[ $? -eq 0 ] && {
					make && make install
				}
				# 初始化MySQL:
				\cp support-files/my-large.cnf /usr/local/mysql/my.cnf
				\cp support-files/mysql.server /etc/init.d/mysqld
				chmod +x  /etc/init.d/mysqld
				mkdir -p /data/mysql
				useradd -s /sbin/nologin mysql
				chown -R mysql. /data/mysql
				/usr/local/mysql55/scripts/mysql_install_db  --user=mysql \
				--datadir=/data/mysql --basedir=/usr/local/mysql
				echo "MySQL 部署成功!"
			fi
		}							
	fi	
}

all_install() {
	install_nginx && install_php && install_mysql
	}

echo
echo -e "1) 安装nginx\n"
echo -e "2) 安装php\n"
echo -e "3) 安装mysql\n"
echo -e "4) lnmp一键部署\n"

read -p "请根据需要输入指定数值选项:"  num
case $num in
	1) 
	install_nginx
	;;
	2)
	install_php
	;;
	3)
	install_mysql
	;;
	4)
	all_install
	;;
	*)
	echo "请输入正确数值选项!"
	;;
esac

4、lvs DR模式,一键部署脚本:
在这个脚本VIP和RIP等都是可以自定义的。并且脚本可以根据主机名自动的判断是配置vip和rip,即实现一个脚本到处执行。

#!/bin/bash
#by lutixia
#############################

# 获取主机名
HOSTNAME=`hostname`
# 设置VIP和RIP的主机名变量
VIP_HOSTNAME="LVS-72-200"
RIP_HOSTNAME_1="RIP-72-127"
RIP_HOSTNAME_2="RIP-72-128"


VIP=192.168.72.200
RIP1=192.168.72.127
RIP2=192.168.72.128
PORT=80
# VIP服务器的VIP子网卡
VIP_INTERFACE=ens32:1
# 后端服务器的lo子网卡
LO_INTERFACE=lo:1
# VIP和RIP出去的网关,该网关为路由器的内网地址
GATEWAY=192.168.72.130

# 配置LVS:
if [ "$HOSTNAME" = "$VIP_HOSTNAME" ];then
	case "$1" in
		start)
			ping  -c2 $VIP &>/dev/null
			if [ $? -ne 0 ];then
				cd /etc/sysconfig/network-scripts/ 
				cat > ifcfg-$VIP_INTERFACE <<-EOF
				TYPE="Ethernet"
				BOOTPROTO="none"
				DEVICE="${VIP_INTERFACE}"
				ONBOOT="yes"
				IPADDR=$VIP
				PREFIX=24
				GATEWAY=$GATEWAY
				EOF
				ifup ${VIP_INTERFACE}
				# 设置VIP虚拟服务器
				/usr/sbin/ipvsadm -A -t $VIP:$PORT  -s rr
				for i in $RIP{1..2};do
					/usr/sbin/ipvsadm -a -t $VIP:$PORT  -r ${i}
				done
				echo -e "\nVIP服务部署成功!配置如下:\n`ipvsadm -ln`"
			else
				echo "检查VIP是否已经被使用!"
			fi
			;; 
		stop)
			/usr/sbin/ipvsadm -D -t $VIP:$PORT
			cd /etc/sysconfig/network-scripts/ 
			ifdown ${VIP_INTERFACE} &>/dev/null
			rm -rf ifcfg-${VIP_INTERFACE}
			route del default gw $GATEWAY &>/dev/null
			echo "VIP service  stopped!"
			;; 
		status) 
			ipvsadm -ln
			;; 
		*) 
			echo "Usage: $0 {start|stop|status}"
			;; 
	esac
# 配置RIP
elif [ "$HOSTNAME" = "$RIP_HOSTNAME_1" ];then
	case "$1" in
		start) 
			cd /etc/sysconfig/network-scripts/
            cat > ifcfg-$LO_INTERFACE <<-EOF
			DEVICE=$LO_INTERFACE
			IPADDR=$VIP
			NETMASK=255.255.255.255
			ONBOOT=yes
			NAME=loopback
			EOF
            ifdown $LO_INTERFACE &>/dev/null && ifup ${LO_INTERFACE}
			echo 1 > /proc/sys/net/ipv4/conf/all/arp_ignore
			echo 2 > /proc/sys/net/ipv4/conf/all/arp_announce
			route add default gw $GATEWAY &>/dev/null
			;; 
		stop) 
			ifdown $LO_INTERFACE &>/dev/null
			cd /etc/sysconfig/network-scripts/
			rm -rf ifcfg-$LO_INTERFACE
			route del default gw $GATEWAY &>/dev/null 
			;; 
		status) 
			echo "VIP: `ip a | awk '/lo:1/{print $2}'`"
			echo "GATEWAY: `route -n | awk 'NR==3{print $2}'`"
			;; 
		*) 
	        echo "$0: Usage: $0 {start|status|stop}"
	        exit 1
			;;
	esac

elif [ "$HOSTNAME" = "$RIP_HOSTNAME_2" ];then
	case "$1" in
		start) 
			cd /etc/sysconfig/network-scripts/
            cat > ifcfg-$LO_INTERFACE <<-EOF
			DEVICE=$LO_INTERFACE
			IPADDR=$VIP
			NETMASK=255.255.255.255
			ONBOOT=yes
			NAME=loopback
			EOF
            ifdown $LO_INTERFACE &>/dev/null && ifup ${LO_INTERFACE}
			echo 1 > /proc/sys/net/ipv4/conf/all/arp_ignore
			echo 2 > /proc/sys/net/ipv4/conf/all/arp_announce
			route add default gw $GATEWAY &>/dev/null
			;; 
		stop) 
			ifdown $LO_INTERFACE &>/dev/null
			cd /etc/sysconfig/network-scripts/
			rm -rf ifcfg-$LO_INTERFACE 
			;; 
		status) 
			echo "VIP: `ip a | awk '/lo:1/{print $2}'`"
			echo "GATEWAY: `route -n | awk 'NR==3{print $2}'`"
			;; 
		*) 
	        echo "$0: Usage: $0 {start|status|stop}"
	        exit 1
			;;
	esac	
fi

好吧,就暂时先分享这几个吧,一定要记得点赞,喜欢,收藏哦,你们的喜欢,就是我们的创作动力。