1.1 mindoc部署

#!/bin/bash

# 2019-09-05
# 部署MinDoc文档管理系统
# 参考:https://www.iminho.me/wiki/docs/mindoc/mindoc-summary.md
echo "#############################################################"
echo "#         CentOS 7/8 mindoc 一键安装脚本                      #"
echo "# 网址: https://www.wangairui.com                            #"
echo "# 作者: zakkary                                              #"
echo "#############################################################"
echo ""


# 安装MySQL
function install_mysql57(){
	# 更新源
	yum install -y epel-release
	# 安装依赖包
	yum install -y  gcc gcc-c++ cmake ncurses ncurses-devel bison
	# axel:多线程下载工具,下载文件时可以替代curl、wget。(人家分享的命令,试试看好不好用)
	yum install -y axel
	# axel -n 20 下载链接
	[ ! -d /opt/software ] && mkdir -p /opt/software
	cd /opt/software
	# 好像有个bug,如果文件遇到特许情况没有下载完成,文件名还是存在的,所以它不会继续下载
	# wget -c 应该可以解决(-c 断点续传)
	# wget -c https://cdn.mysql.com//Downloads/MySQL-5.7/mysql-boost-5.7.25.tar.gz
	[ ! -f mysql-boost-5.7.25.tar.gz ] && axel -n 20 https://cdn.mysql.com//Downloads/MySQL-5.7/mysql-boost-5.7.25.tar.gz
	# 添加用户
	[ ! $(grep mysql /etc/passwd) ] && useradd -s /sbin/nologin mysql
	# 建立所需目录并更改所有者为mysql
	[ ! -d /data/mysql/data ] && mkdir -p /data/mysql/data
	chown -R mysql:mysql /data/mysql
	# 解压
	tar -zxvf mysql-boost-5.7.25.tar.gz
	# 编译安装
	cd /opt/software/mysql-5.7.25/
	# 安装到/opt/mysql目录下
	[ ! -d /opt/mysql ] && mkdir -p /opt/mysql/
	cmake -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DWITH_BOOST=boost -DCMAKE_INSTALL_PREFIX=/opt/mysql/
	make && make install
# 配置文件
cat > /etc/my.cnf << \EOF
[client]
port        = 3306
socket      = /tmp/mysql.sock

[mysqld]
port        = 3306
socket      = /tmp/mysql.sock
user = mysql

basedir = /opt/mysql/
datadir = /data/mysql/data/
pid-file = /data/mysql/mysql.pid

log_error = /data/mysql/mysql-error.log
slow_query_log = 1
long_query_time = 1
slow_query_log_file = /data/mysql/mysql-slow.log

skip-external-locking
key_buffer_size = 32M
max_allowed_packet = 1024M
table_open_cache = 128
sort_buffer_size = 768K
net_buffer_length = 8K
read_buffer_size = 768K
read_rnd_buffer_size = 512K
myisam_sort_buffer_size = 8M
thread_cache_size = 16
query_cache_size = 16M
tmp_table_size = 32M
performance_schema_max_table_instances = 1000

explicit_defaults_for_timestamp = true
max_connections = 500
max_connect_errors = 100
open_files_limit = 65535

log_bin=mysql-bin
binlog_format=mixed
server_id   = 232
expire_logs_days = 10
early-plugin-load = ""

default_storage_engine = InnoDB
innodb_file_per_table = 1
innodb_buffer_pool_size = 128M
innodb_log_file_size = 32M
innodb_log_buffer_size = 8M
innodb_flush_log_at_trx_commit = 1
innodb_lock_wait_timeout = 50

[mysqldump]
quick
max_allowed_packet = 16M

[mysql]
no-auto-rehash

[myisamchk]
key_buffer_size = 32M
sort_buffer_size = 768K
read_buffer = 2M
write_buffer = 2M

EOF

	# 修改文件目录属主属组
	chown -R mysql:mysql /opt/mysql
	# 初始化mysql
	cd /opt/mysql/bin
	./mysqld --initialize-insecure --user=mysql --basedir=/opt/mysql --datadir=/data/mysql/data
	# 拷贝可执行配置文件
	cp /opt/mysql/support-files/mysql.server /etc/init.d/mysqld
	# 启动MySQL
	service mysqld start
	# 软连接
	ln -s /opt/mysql/bin/mysql /usr/bin/mysql
	# 设置开机自启动
	systemctl enable mysqld

	# 修改密码
	mysql -uroot -e "ALTER USER 'root'@'localhost' IDENTIFIED BY '123';"
	[ $? -eq 0 ] && echo -e "\033[31mMySQL安装成功\033[0m" && echo -e "\033[31mMySQL的初始密码为:123\033[0m"
	sleep 10

	# 授权远程登录
	# GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY '123' WITH GRANT OPTION;
	# mysql -uroot -p123 -e "GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY '123' WITH GRANT OPTION;"
	# FLUSH PRIVILEGES;
	# mysql -uroot -p123 -e "FLUSH PRIVILEGES;"
}

function mindoc_install(){
	#下载
	[ ! -d /opt/mindoc ] && mkdir -p /opt/mindoc
	cd /opt/mindoc
	wget -c https://github.com/lifei6671/mindoc/releases/download/v2.0/mindoc_linux_amd64.zip
	#解压
	yum install -y unzip
	unzip mindoc_linux_amd64.zip
	# 创建数据库
	USER="root"
	PASSWORD="123"
	GRANT_COMMAND="GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY '${PASSWORD}' WITH GRANT OPTION;"
	FLUSH_COMMAND="FLUSH PRIVILEGES"
	CREATE_DATABASE_COMMAND="CREATE DATABASE mindoc_db DEFAULT CHARSET utf8mb4 COLLATE utf8mb4_general_ci;"
	# 授权远程登录
	mysql -u${USER} -p${PASSWORD} -e "${GRANT_COMMAND}"
	mysql -u${USER} -p${PASSWORD} -e "${FLUSH_COMMAND}"
	# 创建数据库
	mysql -u${USER} -p${PASSWORD} -e "${CREATE_DATABASE_COMMAND}"
	# 配置数据库
	/bin/cp conf/app.conf.example conf/app.conf

	# 将配置文件换成想要的数据
	# db_adapter="${MINDOC_DB_ADAPTER||sqlite3}"
	# db_host="${MINDOC_DB_HOST||127.0.0.1}"
	# db_port="${MINDOC_DB_PORT||3306}"
	# db_database="${MINDOC_DB_DATABASE||./database/mindoc.db}"
	# db_username="${MINDOC_DB_USERNAME||root}"
	# db_password="${MINDOC_DB_PASSWORD||123456}"

	# 替换
	sed -i 's/db_adapter="${MINDOC_DB_ADAPTER||sqlite3}"/db_adapter="${MINDOC_DB_ADAPTER||mysql}"/' conf/app.conf
	sed -i 's/db_database="${MINDOC_DB_DATABASE||\.\/database\/mindoc\.db}"/db_database="${MINDOC_DB_DATABASE||mindoc_db}"/' conf/app.conf
	sed -i 's/db_password="${MINDOC_DB_PASSWORD||123456}"/db_password="${MINDOC_DB_PASSWORD||123}"/' conf/app.conf
	# 初始化数据库
	./mindoc_linux_amd64 install
	#修改可执行权限
	chmod +x mindoc_linux_amd64
	#启动程序
	nohup ./mindoc_linux_amd64 > mindoc.log 2>&1 &

	echo -e "\033[31m日志文件在:/opt/mindoc/mindoc.log\033[0m"
	echo -e "\033[31m访问链接:http://IP地址:8181\033[0m"
	echo -e "\033[31m账号:admin\033[0m"
	echo -e "\033[31m密码:123456\033[0m"
}

function main(){
	install_mysql57
	mindoc_install
}

main

1.2 rocketmq部署

#!/bin/bash

# 2019-09-05
# 安装RocketChat服务端
# https://rocket.chat/docs/installation/manual-installation/centos/

# Rocket.Chat 1.0.2
# OS: CentOS 7.6
# Mongodb 4.0.9
# NodeJS 8.11.4
echo "#############################################################"
echo "#         CentOS 7/8 RocketChat一键安装脚本                   #"
echo "# 网址: https://www.wangairui.com                            #"
echo "# 作者: 曾缘                                                  #"
echo "#############################################################"
echo ""


function rocketchat_install(){
	# 安装依赖包
	sudo yum -y check-update

cat << EOF | sudo tee -a /etc/yum.repos.d/mongodb-org-4.0.repo
[mongodb-org-4.0]
name=MongoDB Repository
baseurl=https://repo.mongodb.org/yum/redhat/7/mongodb-org/4.0/x86_64/
gpgcheck=1
enabled=1
gpgkey=https://www.mongodb.org/static/pgp/server-4.0.asc
EOF
	# 安装node
	sudo yum install -y curl && curl -sL https://rpm.nodesource.com/setup_8.x | sudo bash -
	# 安装构建工具,MongoDB,nodejs和graphicsmagick:
	sudo yum install -y gcc-c++ make mongodb-org nodejs
	sudo yum install -y epel-release && sudo yum install -y GraphicsMagick
	sudo npm install -g inherits n && sudo n 8.11.4	

	# 安装Rocket.Chat
	# 下载最新的Rocket.Chat版本:
	curl -L https://releases.rocket.chat/latest/download -o /tmp/rocket.chat.tgz
	tar -zxvf /tmp/rocket.chat.tgz -C /tmp
	# 安装
	cd /tmp/bundle/programs/server && npm install
	sudo mv /tmp/bundle /opt/Rocket.Chat	

	# 配置Rocket.Chat服务
	# 添加rocketchat用户,在Rocket.Chat文件夹上设置正确的权限,并创建Rocket.Chat服务文件:
	sudo useradd -M rocketchat && sudo usermod -L rocketchat
	sudo chown -R rocketchat:rocketchat /opt/Rocket.Chat

cat << EOF |sudo tee -a /lib/systemd/system/rocketchat.service
[Unit]
Description=The Rocket.Chat server
After=network.target remote-fs.target nss-lookup.target nginx.target mongod.target
[Service]
ExecStart=/usr/local/bin/node /opt/Rocket.Chat/main.js
StandardOutput=syslog
StandardError=syslog
SyslogIdentifier=rocketchat
User=rocketchat
Environment=MONGO_URL=mongodb://localhost:27017/rocketchat?replicaSet=rs01 MONGO_OPLOG_URL=mongodb://localhost:27017/local?replicaSet=rs01 ROOT_URL=http://localhost:3000/ PORT=3000
[Install]
WantedBy=multi-user.target
EOF

	# 为MongoDB设置存储引擎和复制(对于版本>1是强制的),并启用并启动MongoDB和Rocket.Chat:

	sudo sed -i "s/^#  engine:/  engine: mmapv1/"  /etc/mongod.conf
	sudo sed -i "s/^#replication:/replication:\n  replSetName: rs01/" /etc/mongod.conf
	sudo systemctl enable mongod && sudo systemctl start mongod
	mongo --eval "printjson(rs.initiate())"
	sudo systemctl enable rocketchat && sudo systemctl start rocketchat
	
	# 配置您的Rocket.Chat服务器
	# 打开Web浏览器并访问配置的ROOT_URL(http://your-host-name.com-as-accessed-from-internet:3000),按照配置步骤设置管理员帐户以及组织和服务器信息。
}

rocketchat_install 

1.3 jenkins部署

#!/bin/bash

# 2019-09-09
# Jenkins部署
# 参考:https://jenkins.io/doc/pipeline/tour/getting-started/
echo "#############################################################"
echo "#         CentOS 7/8Jenkins一键安装脚本                       #"
echo "# 网址: https://www.wangairui.com                            #"
echo "# 作者: 曾缘                                                  #"
echo "#############################################################"
echo ""


# 安装jdk1.8
# 包要自己下载到本地再传到服务器上面,下载jdk的源码包花费的时间太久了
function jdk_install(){
	[ ! -d /opt/software ] && mkdir -p /opt/software
	[ ! -d /data/www ] && mkdir -p /data/www
	#安装jdk
	cd /opt/software
	wget -c http://18.179.49.196:9092/coinstar/jdk-8u191-linux-x64.tar.gz
	tar -zxvf /opt/software/jdk-8u191-linux-x64.tar.gz -C /data/www/
	mv /data/www/jdk1.8.0_191 /data/www/jdk8
	#添加jdk环境变量
cat >> /etc/profile << \EOF
#jdk8
export JAVA_HOME=/data/www/jdk8
export JRE_HOME=/data/www/jdk8/jre
export CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar:$JRE_HOME/lib:$CLASSPATH
export PATH=$JAVA_HOME/bin:$PATH
EOF
	#使环境变量生效
	source /etc/profile
	#查看java版本
	java -version
}
# 安装tomcat8
function tomcat8_jenkins_install(){
	[ ! -d /opt/software ] && mkdir -p /opt/software
	[ ! -d /data/www/tomcat8_jenkins ] && mkdir -p /data/www/tomcat8_jenkins
	cd /opt/software/
	wget -c http://18.179.49.196:9092/coinstar/apache-tomcat-8.0.36.tar.gz
	tar -zxvf apache-tomcat-8.0.36.tar.gz
	\cp -r apache-tomcat-8.0.36/* /data/www/tomcat8_jenkins/
	/data/www/tomcat8_jenkins/bin/version.sh
	rm -rf /data/www/tomcat8_jenkins/webapps/*
}
# 安装Jenkins
function jenkins_install(){
	[ ! -d /opt/software ] && mkdir -p /opt/software
	cd /opt/software/
	# 下载包
	wget -c http://mirrors.jenkins.io/war-stable/latest/jenkins.war
	# 把包放到tomcat8目录下面
	mv /opt/software/jenkins.war /data/www/tomcat8_jenkins/webapps/
	# 修改端口
	sed -i 's/<Server port="8005" shutdown="SHUTDOWN">/<Server port="38005" shutdown="SHUTDOWN">/' /data/www/tomcat8_jenkins/conf/server.xml
	sed -i 's/<Connector port="8080" protocol="HTTP/<Connector port="8091" protocol="HTTP/' /data/www/tomcat8_jenkins/conf/server.xml
	sed -i 's/<Connector port="8009" protocol="AJP/<Connector port="38009" protocol="AJP/' /data/www/tomcat8_jenkins/conf/server.xml
	# 启动
	sh /data/www/tomcat8_jenkins/bin/startup.sh
	echo -e "\033[31m浏览器访问***http://IP地址:端口/jenkins***进行Jenkins的初始化!\033[0m"
	sleep 20
	PASSWORD=$(cat /root/.jenkins/secrets/initialAdminPassword)
	echo -e "\033[31m安全令牌:${PASSWORD}\033[0m"
}

function main(){
	echo -e "\033[31m请用***source 脚本名字***来运行脚本\033[0m"
	jdk_install
	tomcat8_jenkins_install
	jenkins_install
}

main

1.4 LNMP部署

#!/bin/bash

# 2019-08-27
# 源码编译LNMP(CentOS7.6+Nginx1.15+MySQL5.7+PHP7.3)

# 参考:https://www.cnblogs.com/baorong/p/9166417.html
# 参考:https://blog.csdn.net/zhang_referee/article/details/88212695
echo "#############################################################"
echo "#         CentOS7.6+Nginx1.15+MySQL5.7+PHP7.3一键安装脚本     #"
echo "# 网址: https://www.wangairui.com                            #"
echo "# 作者: 曾缘                                                  #"
echo "#############################################################"
echo ""

function install_nginx(){
	# 更新epel源
	yum install -y epel-release
	# 安装依赖包
	yum -y install gcc gcc-c++ autoconf automake zlib zlib-devel openssl openssl-devel pcre*
	# 创建nginx运行用户
	# -M(不创建主目录) -s(不允许登录)
	[ ! $(grep nginx /etc/passwd) ] && useradd -M -s /sbin/nologin nginx
	cd /usr/local/src/
	# 下载pcre源码包
	wget -c https://jaist.dl.sourceforge.net/project/pcre/pcre/8.42/pcre-8.42.tar.gz
	tar -zxvf pcre-8.42.tar.gz
	# 下载nginx源码包
	wget -c http://nginx.org/download/nginx-1.15.0.tar.gz
	tar -zxvf nginx-1.15.0.tar.gz
	cd /usr/local/src/nginx-1.15.0/
	# 编译安装
	./configure --prefix=/usr/local/nginx --with-pcre=/usr/local/src/pcre-8.42 --with-http_ssl_module --user=nginx --group=nginx

	make && make install

	# 启动
	/usr/local/nginx/sbin/nginx
	# 输出版本
	/usr/local/nginx/sbin/nginx	-v
	[ $? -eq 0 ] && echo -e "\033[31mNginx安装成功\033[0m"
	sleep 10
}

function install_mysql57(){
	# 更新源
	yum install -y epel-release
	# 安装依赖包
	yum install -y  gcc gcc-c++ cmake ncurses ncurses-devel bison
	# axel:多线程下载工具,下载文件时可以替代curl、wget。(人家分享的命令,试试看好不好用)
	yum install -y axel
	# axel -n 20 下载链接
	cd /usr/local/src
	# 好像有个bug,如果文件遇到特许情况没有下载完成,文件名还是存在的,所以它不会继续下载
	# wget -c 应该可以解决(-c 断点续传)
	# wget -c https://cdn.mysql.com//Downloads/MySQL-5.7/mysql-boost-5.7.25.tar.gz
	[ ! -f mysql-boost-5.7.25.tar.gz ] && axel -n 20 https://cdn.mysql.com//Downloads/MySQL-5.7/mysql-boost-5.7.25.tar.gz
	# 添加用户
	[ ! $(grep mysql /etc/passwd) ] && useradd -s /sbin/nologin mysql
	# 建立所需目录并更改所有者为mysql
	[ ! -d /data/mysql/data ] && mkdir -p /data/mysql/data
	chown -R mysql:mysql /data/mysql
	# 将下载好的mysql 解压到/usr/local/mysql 目录下
	[ ! -d /usr/local/mysql/ ] && mkdir -p /usr/local/mysql/
	tar -zxvf mysql-boost-5.7.25.tar.gz -C /usr/local/mysql/
	# 编译安装
	cd /usr/local/mysql/mysql-5.7.25/
	# cmake安装MySQL默认安装在/usr/local/mysql,如果要指定目录需要加参数:-DCMAKE_INSTALL_PREFIX=
	cmake -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DWITH_BOOST=boost
	make -j 2 && make install
# 配置文件
cat > /etc/my.cnf << \EOF
[client]
port        = 3306
socket      = /tmp/mysql.sock

[mysqld]
port        = 3306
socket      = /tmp/mysql.sock
user = mysql

basedir = /usr/local/mysql
datadir = /data/mysql/data
pid-file = /data/mysql/mysql.pid

log_error = /data/mysql/mysql-error.log
slow_query_log = 1
long_query_time = 1
slow_query_log_file = /data/mysql/mysql-slow.log

skip-external-locking
key_buffer_size = 32M
max_allowed_packet = 1024M
table_open_cache = 128
sort_buffer_size = 768K
net_buffer_length = 8K
read_buffer_size = 768K
read_rnd_buffer_size = 512K
myisam_sort_buffer_size = 8M
thread_cache_size = 16
query_cache_size = 16M
tmp_table_size = 32M
performance_schema_max_table_instances = 1000

explicit_defaults_for_timestamp = true
max_connections = 500
max_connect_errors = 100
open_files_limit = 65535

log_bin=mysql-bin
binlog_format=mixed
server_id   = 232
expire_logs_days = 10
early-plugin-load = ""

default_storage_engine = InnoDB
innodb_file_per_table = 1
innodb_buffer_pool_size = 128M
innodb_log_file_size = 32M
innodb_log_buffer_size = 8M
innodb_flush_log_at_trx_commit = 1
innodb_lock_wait_timeout = 50

[mysqldump]
quick
max_allowed_packet = 16M

[mysql]
no-auto-rehash

[myisamchk]
key_buffer_size = 32M
sort_buffer_size = 768K
read_buffer = 2M
write_buffer = 2M

EOF

	# 修改文件目录属主属组
	chown -R mysql:mysql /usr/local/mysql
	# 初始化mysql
	cd /usr/local/mysql/bin
	./mysqld --initialize-insecure --user=mysql --basedir=/usr/local/mysql --datadir=/data/mysql/data
	# 拷贝可执行配置文件
	cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld
	# 启动MySQL
	service mysqld start
	# 软连接
	ln -s /usr/local/mysql/bin/mysql /usr/bin/mysql
	# 设置开机自启动
	systemctl enable mysqld

	# 修改密码
	mysql -uroot -e "ALTER USER 'root'@'localhost' IDENTIFIED BY '123';"
	[ $? -eq 0 ] && echo -e "\033[31mMySQL安装成功\033[0m" && echo -e "\033[31mMySQL的初始密码为:123\033[0m"
	sleep 10

	# 授权远程登录
	# GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY '123' WITH GRANT OPTION;
	# mysql -uroot -p123 -e "GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY '123' WITH GRANT OPTION;"
	# FLUSH PRIVILEGES;
	# mysql -uroot -p123 -e "FLUSH PRIVILEGES;"
}

function install_php(){
	# 安装依赖
	yum install -y gcc gcc-c++ php-mcrypt libmcrypt libmcrypt-devel autoconf freetype gd libmcrypt \
	libpng libpng-devel libjpeg libxml2 libxml2-devel zlib curl curl-devel re2c net-snmp-devel \
	libjpeg-devel php-ldap openldap-devel openldap-servers openldap-clients freetype-devel gmp-devel
	# 下载php源码包
	cd /usr/local/src/
	wget -c https://www.php.net/distributions/php-7.3.8.tar.gz
	tar -zxvf php-7.3.8.tar.gz
	
	# 编译安装
	# 提前解决报错
	cp -frp /usr/lib64/libldap* /usr/lib/

	cd /usr/local/src/
	wget -c https://nih.at/libzip/libzip-1.2.0.tar.gz
	tar -zxvf libzip-1.2.0.tar.gz
	cd libzip-1.2.0
	./configure
	make && make install

	# /etc/ld.so.conf 此文件记录了编译时使用的动态库的路径,也就是加载so库的路径。
cat >> /etc/ld.so.conf << \EOF
/usr/local/lib64
/usr/local/lib
/usr/lib
/usr/lib64
EOF
	# ldconfig -v的作用是将文件/etc/ld.so.conf列出的路径下的库文件缓存到/etc/ld.so.cache以供使用
	ldconfig -v

	cd /usr/local/src/php-7.3.8
	./configure --prefix=/usr/local/php --with-config-file-path=/usr/local/php/etc --with-mysqli --with-pdo-mysql \
	--with-mysql-sock=/usr/local/mysql/mysql.sock --with-iconv-dir --with-freetype-dir --with-jpeg-dir --with-png-dir \
	--with-curl --with-gd --with-gmp --with-zlib --with-xmlrpc --with-openssl --without-pear --with-snmp --with-gettext \
	--with-mhash --with-libxml-dir=/usr --with-ldap --with-ldap-sasl --with-fpm-user=nginx --with-fpm-group=nginx \
	--enable-xml --enable-fpm  --enable-ftp --enable-bcmath --enable-soap --enable-shmop --enable-sysvsem --enable-sockets \
	--enable-inline-optimization --enable-maintainer-zts --enable-mbregex --enable-mbstring --enable-pcntl --enable-zip \
	--disable-fileinfo --disable-rpath --enable-libxml --enable-opcache --enable-mysqlnd

	# 提前解决报错
	cp /usr/local/lib/libzip/include/zipconf.h /usr/local/include/zipconf.h
	sed -i 's/-lcrypto -lcrypt/-lcrypto -lcrypt -llber/' /usr/local/src/php-7.3.8/Makefile

	make && make install
	# 配置文件
	cp /usr/local/php/etc/php-fpm.d/www.conf.default /usr/local/php/etc/php-fpm.conf
	# 复制php.ini文件
	cp /usr/local/src/php-7.3.8/php.ini-production /usr/local/php/etc/php.ini
	# 启动
	cp /usr/local/src/php-7.3.8/sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
	chmod +x /etc/init.d/php-fpm 
	chkconfig --add php-fpm
	chkconfig php-fpm on
	[ ! $(grep nginx /etc/passwd) ] && useradd -M -s /sbin/nologin nginx
	service php-fpm start
	[ $? -eq 0 ] && echo -e "\033[31mPHP安装成功\033[0m"
	sleep 10

	# 报错:configure: error: Cannot find ldap libraries in /usr/lib.
	# 解决:cp -frp /usr/lib64/libldap* /usr/lib/
	# 然后再次:./configure ...
	
	# 报错:configure: error: Please reinstall the libzip distributions
	# 解决:yum install -y libzip-devel
	# 然后再次:./configure ...
	
	# 报错:checking for libzip... configure: error: system libzip must be upgraded to version >= 0.11
	#先删除旧版本:yum remove -y libzip
	#下载编译安装
	# cd /usr/local/src/
	# wget -c https://nih.at/libzip/libzip-1.2.0.tar.gz
	# tar -zxvf libzip-1.2.0.tar.gz
	# cd libzip-1.2.0
	# ./configure
	# make && make install
	# 然后再次:./configure ...

	# 报错:configure: error: off_t undefined; check your library configuration
	# 解决:
	#添加搜索路径到配置文件
	# echo '/usr/local/lib64
	# /usr/local/lib
	# /usr/lib
	# /usr/lib64'>>/etc/ld.so.conf
	#然后 更新配置
	# ldconfig -v
	# 然后再次:./configure ...

	# 报错:/usr/local/include/zip.h:59:21: 致命错误:zipconf.h:没有那个文件或目录
	# cp /usr/local/lib/libzip/include/zipconf.h /usr/local/include/zipconf.h
	# 然后再次:make && make install

	# 报错:
	# /usr/bin/ld: ext/ldap/.libs/ldap.o: undefined reference to symbol 'ber_strdup'
	# //usr/lib64/liblber-2.4.so.2: error adding symbols: DSO missing from command line
	# collect2: error: ld returned 1 exit status
	# make: *** [sapi/cli/php] 错误 1
	# 解决:在Makefile文件EXTRA_LIBS后面添加 -llber
	# EXTRA_LIBS = -lcrypt -lzip -lzip -lz -lresolv -lcrypt -lrt -lldap -lgmp -lpng -lz -ljpeg 
	# -lz -lrt -lm -ldl -lnsl -lpthread -lxml2 -lz -lm -ldl -lssl -lcrypto -lcurl -lxml2 -lz -lm 
	# -ldl -lssl -lcrypto -lfreetype -lxml2 -lz -lm -ldl -lnetsnmp -lssl -lssl -lcrypto -lm -lxml2 
	# -lz -lm -ldl -lcrypt -lxml2 -lz -lm -ldl -lxml2 -lz -lm -ldl -lxml2 -lz -lm -ldl -lxml2 -lz 
	# -lm -ldl -lssl -lcrypto -lcrypt -llber
	# 然后再次:make && make install
}

function modify_configuration_files(){
	# 备份nginx配置文件
	mv /usr/local/nginx/conf/nginx.conf{,_`date +%F`.bak}

cat > /usr/local/nginx/conf/nginx.conf << \EOF
user  nginx;
worker_processes  1;
events {
    worker_connections  1024;
}
http {
    include       mime.types;
    default_type  application/octet-stream;
    server_tokens off;
    sendfile        on;
    keepalive_timeout  65;
    server {
        listen       80;
        server_name  localhost;
        location / {
            root   html;
            index  index.html index.htm index.php;
        }
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }
        location ~ \.php$ {
            root           html;
            fastcgi_pass   127.0.0.1:9000;
            fastcgi_index  index.php;
            fastcgi_param  SCRIPT_FILENAME  /usr/local/nginx/html$fastcgi_script_name;
            include        fastcgi_params;
        }
    }
}
EOF

# 测试界面
cat > /usr/local/nginx/html/index.php << \EOF
<?php
    phpinfo();
?>
EOF

	# 检测配置文件的正确性
	/usr/local/nginx/sbin/nginx -t
	# 重新加载配置文件
	/usr/local/nginx/sbin/nginx -s reload
	# 浏览器访问:本地IP:端口/index.php
	IP=$(ip addr | grep -w inet | grep -v "127.0.0.1" | awk '{print $2}' | awk -F'/' '{print $1}')
	[ $? -eq 0 ] && echo -e "\033[31m浏览器访问:本地IP:端口/index.php\033[0m" && echo -e "\033[31m例如:${IP}/index.php\033[0m" \
	&& echo -e "\033[31m出现php信息,成功!\033[0m"
	sleep 10
}

function main(){
	# 安装服务(如果有某个模块安装成功了,可以注释该模块,执行其他的模块)
	install_nginx
	install_mysql57
	install_php
	# 可选配置文件
	modify_configuration_files
}

main

1.5 mysql5.7部署

#!/bin/bash
# 一键安装mysql5.6

# 用户使用参数(可选):mysql安装文件的绝对路径
# 功能: 自动下载安装文件,自动配置,添加服务,开机自启,设置默认密码
+++++++++++++++++++++++++++++++++++++++++++
标题:MySQL数据库实例部署
时间:2019年9月24日
内容:MySQL源码包进行编译,然后部署MySQL单实例
+++++++++++++++++++++++++++++++++++++++++++
echo "#############################################################"
echo "#         CentOS 7 mysql5.7 一键安装脚本                      #"
echo "# 网址: https://www.wangairui.com                            #"
echo "# 作者: zakkary                                              #"
echo "#############################################################"
echo ""

MYSQL_INSTALL_DIR=/opt/software/  # mysql安装目录
IS_CINTINUE='y';

# 下载mysql
install_mysql() {
	read -p "是否下载?【y/n】" IS_CINTINUE
	if [[ $IS_CINTINUE == 'y' ]]; then
		yum install -y wget && wget -c http://dev.mysql.com/get/Downloads/MySQL-5.6/mysql-5.6.37.tar.gz;
		cp mysql-5.6.37.tar.gz $MYSQL_INSTALL_DIR
		mkdir -p /data/3316
		mkdir -p /opt/mysql-5.6.37
	else
		echo "请您自行下载安装包!";
		exit;
	fi
}

# 先切换到用户目录
cd ~
echo "======> 检测 $MYSQL_INSTALL_DIR 目录是否存在 <======";
if [ -d $MYSQL_INSTALL_DIR ]; then 
	echo "======> success! 目录已经存在! <======";
else
	echo "======> warning! 目录不存在,将创建! <======";
	mkdir -p $MYSQL_INSTALL_DIR
fi

if [ $# != 0 ]; then
	if [ -f $1 ]; then
		echo "======> 将安装文件复制到制定目录 <======";
		cp $1 $MYSQL_INSTALL_DIR
		if [ $? -eq 0 ]; then
			echo "======> 复制成功! <======";
			sleep 2s
		else
			echo "======> 复制失败! <======";
			install_mysql
			exit;
		fi
	else
		echo "======> error! 文件不存在 <======";
		install_mysql
		
	fi
else
	install_mysql
fi


echo "======> 依赖安装! <======";
yum  -y install gcc gcc-c++ auto conf bison cmake automake zlib* fiex* libxml* ncurses-devel libmcrypt* libtool-ltdl-devel* perl libaio* 
echo "======> 解压文件 <======";
cd $MYSQL_INSTALL_DIR && tar -zxvf mysql-5.6.37.tar.gz
if [ $? -eq 0 ];then
	echo "======> 解压成功! <======";
	sleep 2s
	cd mysql-5.6.37
	echo "======> 安装前的设置 <======";
	cmake \
	-DCMAKE_INSTALL_PREFIX=/opt/mysql-5.6.37 \
	-DMYSQL_UNIX_ADDR=/opt/mysql-5.6.37/mysql.sock \
	-DWITH_BOOST=/usr/local/boost \
	-DDEFAULT_CHARSET=utf8 \
	-DDEFAULT_COLLATION=utf8_general_ci \
	-DWITH_MYISAM_STORAGE_ENGINE=1 \
	-DWITH_INNOBASE_STORAGE_ENGINE=1 \
	-DWITH_ARCHIVE_STORAGE_ENGINE=1 \
	-DWITH_BLACKHOLE_STORAGE_ENGINE=1 \
	-DWITH_MEMORY_STORAGE_ENGINE=1 \
	-DWITH_READLINE=1 \
	-DENABLED_LOCAL_INFILE=1 \
	-DMYSQL_DATADIR=/data/3316 \
	-DMYSQL_TCP_PORT=3316 \
	-DMYSQL_USER=mysql \
	-DENABLE_DOWNLOADS=1 
	if [ $? -eq 0 ];then
		echo "======> 设置成功!开始编译安装,大约需要20分钟,耐心等待...<======"; 
		sleep 2s
		make && make install 
		if [ $? -eq 0 ]; then
			cd ~
			echo "======> 编译成功!开始设置组和用户! <======";
			sleep 2s
			groupadd mysql && 
	  		useradd mysql -g mysql -M -s /sbin/nologin &&
	  		chown  mysql.mysql /opt/mysql-5.6.37
			chown  mysq:mysql /data/3316
	  	else
	  		echo "======> 编译失败! <======";
	  		exit;
	  	fi
	else
		echo "======> 设置失败! <======";
		exit;
	fi
else
	echo "======> 解压失败!<=======";
	exit;

fi


echo "======> 开始配置mysql <======";
cd /opt/mysql-5.6.37
touch /opt/mysql-5.6.37/mysql-error.log
echo "======> 初始化mysql <======";
./scripts/mysql_install_db --user=mysql --basedir=/opt/mysql-5.6.37 --datadir=/data/3316 --pid-file=/opt/mysql-5.6.37/mysql.pid --no-defaults
cp support-files/my-default.cnf  /etc/my.cnf

sleep 2s

echo "======> 开始修改mysql的配置文件 <======";
cat << \EOF > /etc/my.cnf
[client]
port = 3316
socket = /tmp/mysql.sock
default-character-set=utf8 
[mysqld]
user = mysql
basedir = /opt/mysql-5.6.37
datadir = /data/3316
#server_id = 100
socket = /tmp/mysql.sock
innodb_print_all_deadlocks = 1
log-error = /opt/mysql-5.6.37/mysql-error.log  #touch 创建文件
#
#default-character-set=utf8 
explicit_defaults_for_timestamp=true                  #关闭错误警告
#system_time_zone=CST
default-time-zone=system
#character-set-server=utf8
init-connect='SET NAMES utf8'
collation-server =utf8_general_ci
skip-external-locking
key_buffer_size = 16M
##max_allowed_packet = 1M
max_allowed_packet = 10000000M
max_connections=2000
table_open_cache = 64
innodb_buffer_pool_size=8G
sort_buffer_size = 1M
tmp_table_size = 256M
max_heap_table_size = 256M
net_buffer_length = 8K
read_buffer_size = 256K
read_rnd_buffer_size = 512K
myisam_sort_buffer_size = 8M
log-bin=mysql-bin
event_scheduler = ON
binlog_format=row
transaction_isolation = READ-COMMITTED
default-time_zone = '+8:00'
slow_query_log = on
EOF


echo "======> 制作服务启动 <======";
/bin/cp -rf support-files/mysql.server /etc/init.d/mysqld
chmod +x /etc/init.d/mysqld 
if [ $? -eq 0 ]; then
	echo "======> 服务设置成功! <======";
	cd ~
	service mysqld start
	sleep 2s
	service mysqld stop
	sleep 2s
else
	echo "======> 服务设置失败! <======";
fi

echo "======> 添加到开机启动项! <======";
chkconfig --add mysqld
if [ $? -eq 0 ]; then
	echo "======> 设置开机启动项成功! <======";
else
	echo "======> 设置开机启动项失败! <======";
fi


service mysqld stop
echo "======> 配置环境变量 <======";
echo "export PATH=$PATH:/opt/mysql-5.6.37/bin" >>/etc/profile
source /etc/profile

echo "启动mysql服务 ======>";
service mysqld start


cd /opt/mysql-5.6.37
echo "======> 设置root密码为: “123456” <======";
./bin/mysqladmin -u root password "123456"
if [ $? -eq 0 ];then
	echo "设置root密码成功!";
else
	echo "设置root密码失败!";
fi

```
### 2. 进行软链接
```shell
ln -s /opt/mysql-5.6.37/bin/mysql /usr/bin/mysql

1.6 nmon监控部署

#!/bin/bash

# Nmon部署
# 开源性能监控工具,用于监控linux系统的资源消耗信息,并能把结果输出到文件中,然后通过nmon_analyser工具产生数据文件与图形化结果。
# 官网:http://nmon.sourceforge.net/pmwiki.php?n=Site.Download
# 2019-09-20
# 参考
# https://www.cnblogs.com/tiechui2015/p/10439854.html
# https://www.cnblogs.com/mingerlcm/p/7748539.html
echo "#############################################################"
echo "#         CentOS 7 nmon一键安装脚本                      #"
echo "# 网址: https://www.wangairui.com                            #"
echo "# 作者: zakkary                                              #"
echo "#############################################################"
echo ""


function nmon_install(){
	[ ! -d /opt/software/nmon ] && mkdir /opt/software/nmon
	cd /opt/software/nmon
	# 下载包
	yum install -y lrzsz
	wget -c http://sourceforge.net/projects/nmon/files/nmon16e_mpginc.tar.gz
	tar -zxvf nmon16e_mpginc.tar.gz
	cp nmon_x86_64_centos7 /usr/local/bin/nmon
	chmod 777 /usr/local/bin/nmon
	nmon
	# 出现这个成功
	# ------------------------------                                                                                                                                                         x
	#  _ __  _ __ ___   ___  _ __    	 For help type H or ...                                                                                                                            x
	# | '_ \| '_ ` _ \ / _ \| '_ \          nmon -?  - hint                                                                                                                                  x
	# | | | | | | | | | (_) | | | |         nmon -h  - full details                                                                                                                          x
	# |_| |_|_| |_| |_|\___/|_| |_|                                                                                                                                                          x
	#                                      To stop nmon type q to Quit                                                                                                                       x
	# ------------------------------                                                                                                                                                         x
	#                                                                                                                                                                                        x
	# CentOS Linux release 7.5.1804 (Core)  NAME="CentOS Linux"                                                                                                                              x
	# GenuineIntel Intel(R) Xeon(R) Silver 4116 CPU @ 2.10GHz                                                                                                                                x
	# MHz=2095.078 bogomips=4190.15                                                                                                                                                          x
	# ProcessorChips=1 PhyscalCores=8                                                                                                                                                        x
	# Hyperthreads  =0 VirtualCPUs =8                                                                                                                                                        x
	#                                                                                                                                                                                        x
	# Use these keys to toggle statistics on/off:                                                                                                                                            x
	#   c = CPU         l = CPU Long-term     - = Faster screen updates                                                                                                                      x
	#   C = " WideView  U = Utilisation       + = Slower screen updates                                                                                                                      x
	#   m = Memory      V = Virtual memory    j = File Systems                                                                                                                               x
	#   d = Disks       n = Network           . = only busy disks/procs                                                                                                                      x
	#   r = Resource    N = NFS               h = more options                                                                                                                               x
	#   k = Kernel      t = Top-processes     q = Quit
}

nmon_install

1.7 docker部署

#!/bin/bash

# CentOS安装Docker
# 2019-09-19
# 参考:https://docs.docker.com/install/linux/docker-ce/centos/
echo "#############################################################"
echo "#         CentOS 7/8 docker 一键安装脚本                      #"
echo "# 网址: https://www.wangairui.com                            #"
echo "# 作者: zakkary                                              #"
echo "#############################################################"
echo ""

function docker_install(){
	# 先停止docker
	sudo systemctl stop docker
	# 移除旧版本
	sudo yum remove docker docker-client docker-client-latest \
	docker-common docker-latest docker-latest-logrotate \
	docker-logrotate docker-engine
	# 安装依赖
	sudo yum install -y yum-utils device-mapper-persistent-data lvm2
	# 设置稳定存储库
	sudo yum-config-manager --add-repo \
	https://download.docker.com/linux/centos/docker-ce.repo
	# 安装Dcoker
	sudo yum install -y docker-ce docker-ce-cli containerd.io
	# 启动
	sudo systemctl start docker
	sudo systemctl enable docker
	# 阿里云镜像加速
cat > /etc/docker/daemon.json << EOF
{
	"registry-mirrors": ["https://wixr7yss.mirror.aliyuncs.com"]
}
EOF

	sudo systemctl daemon-reload
	sudo systemctl restart docker
	
}

docker_install

1.8 vsftpd部署

#!/bin/bash


# vsftpd部署
echo "#############################################################"
echo "#         CentOS 7 vsftpd 一键安装脚本                      #"
echo "# 网址: https://www.wangairui.com                            #"
echo "# 作者: zakkary                                              #"
echo "#############################################################"
echo ""

function vsftpd_install(){
	# 服务安装
	yum install -y pam* vsftpd* db4*
	# 建立vsftpd服务的宿主用户
	useradd vsftpd -s /sbin/nologin
	# 建立vsftpd服务的虚拟宿主用户
	useradd overlord -s /sbin/nologin
	# 编辑配置文件前先备份
	cp /etc/vsftpd/vsftpd.conf /etc/vsftpd/vsftpd.conf.bak
	# 设定不允许匿名访问
	sed -i "s/anonymous_enable=YES/#anonymous_enable=YES/" /etc/vsftpd/vsftpd.conf
	sed -ri '/#anonymous_enable=YES/a\anonymous_enable=NO' /etc/vsftpd/vsftpd.conf
	# 设定本地用户可以访问
	# local_enable=YES
	# 设定可以进行写操作
	# write_enable=YES
	# 设定上传后文件的权限掩码
	# local_umask=022
	# 禁止匿名用户上传。
	sed -ri '/#anon_upload_enable=YES/a\anon_upload_enable=NO' /etc/vsftpd/vsftpd.conf
	# 禁止匿名用户建立目录
	sed -ri '/#anon_mkdir_write_enable=YES/a\anon_mkdir_write_enable=NO' /etc/vsftpd/vsftpd.conf
	# 设定开启目录标语功能
	# dirmessage_enable=YES
	# 设定开启日志记录功能
	# xferlog_enable=YES
	# 设定端口20进行数据连接
	# connect_from_port_20=YES
	# 设定禁止上传文件更改宿主
	sed -ri '/#chown_uploads=YES/a\chown_uploads=NO' /etc/vsftpd/vsftpd.conf
	# 设定Vsftpd的服务日志保存路径
	sed -ri '/#xferlog_file=/var/log/xferlog/a\xferlog_file=/var/log/xferlog' /etc/vsftpd/vsftpd.conf
	# 设定日志使用标准的记录格式
	# xferlog_std_format=YES
	# 设定空闲连接超时时间,这里使用默认
	# idle_session_timeout=600
	# 设定单次最大连续传输时间,这里使用默认
	# data_connection_timeout=120
	# 设定支撑Vsftpd服务的宿主用户为手动建立的Vsftpd用户
	sed -ri '/#nopriv_user=ftpsecure/a\nopriv_user=vsftpd' /etc/vsftpd/vsftpd.conf
	# 设定支持异步传输功能
	sed -ri '/#async_abor_enable=YES/a\async_abor_enable=YES' /etc/vsftpd/vsftpd.conf
	# 设定支持ASCII模式的上传和下载功能
	sed -ri '/#ascii_upload_enable=YES/a\ascii_upload_enable=YES' /etc/vsftpd/vsftpd.conf
	sed -ri '/#ascii_download_enable=YES/a\ascii_download_enable=YES' /etc/vsftpd/vsftpd.conf
	# 设定Vsftpd的登陆标语
	sed -ri '/#ftpd_banner=Welcome to blah FTP service/a\ftpd_banner=Welcome to blah FTP service' /etc/vsftpd/vsftpd.conf
	# 禁止用户登出自己的FTP主目录
	sed -ri '/#chroot_list_enable=YES/a\chroot_list_enable=NO' /etc/vsftpd/vsftpd.conf
	# 禁止用户登陆FTP后使用"ls -R"的命令
	sed -ri '/#ls_recurse_enable=YES/a\ls_recurse_enable=NO' /etc/vsftpd/vsftpd.conf
	# 设定该Vsftpd服务工作在StandAlone模式下
	sed -i "s/listen=NO/#listen=NO/" /etc/vsftpd/vsftpd.conf
	sed -ri '/#listen=NO/a\listen=YES' /etc/vsftpd/vsftpd.conf

	sed -i "s/listen_ipv6=YES/#listen_ipv6=YES/" /etc/vsftpd/vsftpd.conf
	# 设定PAM服务下Vsftpd的验证配置文件名
	# pam_service_name=vsftpd
	# 设定userlist_file中的用户将不得使用FTP
	# userlist_enable=YES
	# 设定支持TCP Wrappers
	# tcp_wrappers=YES
cat >> /etc/vsftpd/vsftpd.conf << \EOF
# 设定启用虚拟用户功能
guest_enable=YES
# 指定虚拟用户的宿主用户
guest_username=overlord
# 设定虚拟用户的权限符合他们的宿主用户
virtual_use_local_privs=YES
# 设定虚拟用户个人Vsftp的配置文件存放路径。
user_config_dir=/etc/vsftpd/vconf
# 将存放每个Vsftp虚拟用户个性的配置文件,一个需要注意的地方就是这些配置文件名必须和虚拟用户名相同
EOF
	touch /var/log/vsftpd.log
	chown vsftpd:vsftpd /var/log/vsftpd
	mkdir /etc/vsftpd/vconf

cat >> /etc/vsftpd/virtusers << \EOF
wuchengsong
123
zengyuan
123
zhangqian
123
EOF

	# 生成虚拟用户数据文件
	db_load -T -t hash -f /etc/vsftpd/virtusers /etc/vsftpd/virtusers.db
	# 设定PAM验证文件,并指定虚拟用户数据库文件进行读取
	sed -ri 's/^(a|s)(.*)/#\1\2/' /etc/pam.d/vsftpd
cat >> /etc/pam.d/vsftpd << \EOF
auth    sufficient      /lib64/security/pam_userdb.so     db=/etc/vsftpd/virtusers
account sufficient      /lib64/security/pam_userdb.so     db=/etc/vsftpd/virtusers
EOF

# 创建虚拟用户路径
mkdir /opt/vsftpd
mkdir /opt/vsftpd/{wuchengsong,zengyuan,zhangqian}
chown -R overlord.overlord /opt/vsftp/
NAME=(wuchengsong zengyuan zhangqian)

for i in ${NAME[@]};do
cat >> /etc/vsftpd/vconf/${i} << \EOF
local_root=/opt/vsftp/${i}
anonymous_enable=NO
write_enable=YES
local_umask=022
anon_upload_enable=NO
anon_mkdir_write_enable=NO
idle_session_timeout=300
data_connection_timeout=90
max_clients=1
max_per_ip=1
local_max_rate=25000
EOF
done

systemctl start vsftpd.service
}

vsftpd_install

1.9 python3.6部署

#!/bin/bash
# 一键安装python3.6
# 安装python3.6可能使用的依赖
echo "#############################################################"
echo "#         CentOS 7/8 python3.6一键安装脚本                    #"
echo "# 网址: https://www.wangairui.com                            #"
echo "# 作者: 曾缘                                                  #"
echo "#############################################################"
echo ""

yum -y install zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel gdbm-devel db4-devel libpcap-devel xz-devel

# 下载python3.6编译安装
wget https://www.python.org/ftp/python/3.6.5/Python-3.6.5.tgz
tar -xzvf Python-3.6.5.tgz -C /tmp
cd /tmp/Python-3.6.5/
# 把Python3.6安装到 /usr/local 目录
./configure --prefix=/usr/local/python3.6
make
make install

cd  /usr/bin/ 
mv  /usr/bin/python  /usr/bin/python_bak
mv /usr/bin/pip /usr/bin/pip_bak
ln -s /usr/local/python3.6/bin/python3.6 /usr/bin/python
ln -s /usr/local/python3.6/bin/pip3.6   /usr/bin/pip

```
#导致yum不可用 做以下修改
```yaml
[root@master bin]# vim /usr/bin/yum
#!/usr/bin/python2.7

vim /usr/libexec/urlgrabber-ext-down
#!/usr/bin/python2.7

1.10 REDIS部署

#!/bin/bash
# 2019-06-23
# 源码编译安装redis-4.0.1
# 作者:曾缘
# 数据目录:/usr/local/redis
echo "#############################################################"
echo "#         CentOS 7/8 redis4.0.1 一键安装脚本                  #"
echo "# 网址: https://www.wangairui.com                            #"
echo "# 作者: zakkary                                              #"
echo "#############################################################"
echo ""

yum install cpp binutils glibc-kernheaders glibc-common glibc-devel gcc make wget    #安装依赖库
wget http://download.redis.io/releases/redis-4.0.1.tar.gz
if [ -f /root/redis-4.0.1.tar.gz ];then
    tar zxvf redis-4.0.1.tar.gz
    mv redis-4.0.1 /usr/local/redis
    cd /usr/local/redis
    make
    cd src/
    make install 
else
    echo "文件不存在!"
    exit;
fi

sed -i '136s/daemonize no/daemonize yes/' /usr/local/redis/redis.conf    #(编辑redis服务配置文件,修改其中配置)

sed -i '69s/127.0.0.1/0.0.0.0/' /usr/local/redis/redis.conf 

sed -i '88s/protected-mode yes/protected-mode no/' /usr/local/redis/redis.conf
 mkdir -p /etc/redis
 ln -s /usr/local/redis/redis.conf /etc/redis/6379.conf   #(在默认的配置文件路劲中放置配置文件)
 ln -s /usr/local/redis/utils/redis_init_script /etc/init.d/redisd    #(将初始化文件配置到系统自启动的文件夹内,redisd为服务名,可自行修改)
 service redisd start   #(开启redis服务,服务名为:redisd)
 #redis-cli  
netstat -ntpl|grep redis
echo "Redis 部署完成!"
echo " "
echo "如果你的系统是Centos 7在安装完毕后留意防火墙,可执行以下命令来放行redis 外部通信。"
echo "firewall-cmd --zone=public --add-port=6379/tcp --permanent"    
echo "firewall-cmd --reload"
echo "firewall-cmd --zone= public --query-port=6379/tcp"

1.11