linuxcentos7终极编译部署LAMP环境脚本国内网站下载速度贼快
#!/bin/bash
#LAMP终极部署
cat <<-EOF
+-------------------------------------------------------------------------+
| LAMP终极部署 V1.0 |
+-------------------------------------------------------------------------+
| a. 部署Apache服务 |
| b. 部署php服务 |
| c. 部署MySQL服务 |
| d. 一键部署LAMP |
| q. 按q键退出程序 |
+-------------------------------------------------------------------------+
EOF
#安装Apache
install_Apache()
{
systemctl stop firewalld
systemctl disable firewalld
setenforce 0
sed -i '/^\bSELINUX\b/c SELINUX=disabled' /etc/selinux/config
mkdir /usr/local/apr &> /dev/null
mkdir /usr/local/apr-util &> /dev/null
mkdir /usr/local/apache &> /dev/null
cd /usr/local/src
echo "正在下载Apache服务,请稍等!!!"
wget http://archive.apache.org/dist/apr/apr-1.6.5.tar.gz &> /dev/null
wget http://archive.apache.org/dist/apr/apr-util-1.6.1.tar.gz &> /dev/null
wget http://mirrors.hust.edu.cn/apache/httpd/httpd-2.4.37.tar.gz &> /dev/null
if [ $? -eq 0 ]
then
echo "download success"
else
echo "download failed"
exit
fi
tar xf apr-1.6.5.tar.gz
tar xf apr-util-1.6.1.tar.gz
tar xf httpd-2.4.37.tar.gz
echo "正在安装所需的依赖包"
yum -y install gcc gcc-c++ openssl openssl-devel expat-devel &> /dev/null
if [ $? -eq 0 ]
then
echo "依赖包安装成功"
else
echo "依赖包安装失败"
exit
fi
cd /usr/local/src/apr-1.6.5/
echo "正在配置和编译安装apr,请喝口水稍等!!!"
./configure --prefix=/usr/local/apr/ &> /dev/null
make &> /dev/null && make install &>/dev/null
if [ $? -eq 0 ]
then
echo "apr installed"
else
echo "apr installed failed"
exit
fi
cd /usr/local/src/apr-util-1.6.1/
./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr/ &> /dev/null
make &> /dev/null && make install &> /dev/null
if [ $? -eq 0 ]
then
echo "apr-util installed"
else
echo "apr-util installed failed"
exit
fi
cd /usr/local/src/httpd-2.4.37/
echo "正在配置Apache"
./configure --prefix=/usr/local/apache/ --with-apr=/usr/local/apr/ --with-apr-util=/usr/local/apr-util/ --enable-so --enable-ssl--enable-deflate=shared --enable-expires=shared --enable-rewrite=shared --enable-static-support &> /dev/null
make &> /dev/null && make install &> /dev/null
if [ $? -eq 0 ]
then
echo "Apache installed"
else
echo "Apache installed failed"
exit
fi
cd /usr/local/apache/bin/
echo ServerName www.fangxi.com >> /usr/local/apache/conf/httpd.conf
./apachectl start
if [ $? -eq 0 ]
then
echo "Apache安装成功并启动"
else
echo "Apache启动失败"
exit
fi
创新互联建站秉承实现全网价值营销的理念,以专业定制企业官网,网站设计制作、成都做网站,小程序设计,网页设计制作,成都做手机网站,营销型网站建设帮助传统企业实现“互联网+”转型升级专业定制企业官网,公司注重人才、技术和管理,汇聚了一批优秀的互联网技术人才,对客户都以感恩的心态奉献自己的专业和所长。
}
#安装php
install_php()
{
echo "正在安装php服务"
yum -y install php php-cli php-curl php-fpm php-intl php-mcryp php-mysql php-gd php-mbstring php-xml php-dom &> /dev/null
if [ $? -eq 0 ]
then
echo "php安装成功"
else
echo "php安装失败"
exit
fi
systemctl start php-fpm &> /dev/null
if [ $? -eq 0 ]
then
echo "php安装成功"
else
echo "php安装失败"
exit
fi
}
#编译安装Mysql
install_mysql()
{
echo "开始安装mysql"
echo "正在准备编译环境,wait a minute"
yum -y install ncurses ncurses-devel openssl-devel bison gcc gcc-c++ make cmake &> /dev/null
if [ $? -eq 0 ]
then
echo "编译环境已准备好"
else
echo "编译环境准备失败"
exit
fi
echo "正在下载源码包----请稍稍等一下"
wget https://down.51cto.com/download.php?do=attachment&aid=3110021&k=26b650aaf1d2184d58d2570ac2f8d0bb&t=1568725722&c=1
groupadd mysql
useradd -r -g mysql -s /bin/nologin mysql
tar xf mysql-boost-5.7.26.tar.gz
cd mysql-5.7.26/
echo "正在配置中,请再喝口水,小憩一下"
cmake . \
-DWITH_BOOST=boost/boost_1_59_0/ \
-DCMAKE_INSTALL_PREFIX=/usr/local/mysql \
-DSYSCONFDIR=/etc \
-DMYSQL_DATADIR=/usr/local/mysql/data \
-DINSTALL_MANDIR=/usr/share/man \
-DMYSQL_TCP_PORT=3306 \
-DMYSQL_UNIX_ADDR=/tmp/mysql.sock \
-DDEFAULT_CHARSET=utf8 \
-DEXTRA_CHARSETS=all \
-DDEFAULT_COLLATION=utf8_general_ci \
-DWITH_READLINE=1 \
-DWITH_SSL=system \
-DWITH_EMBEDDED_SERVER=1 \
-DENABLED_LOCAL_INFILE=1 \
-DWITH_INNOBASE_STORAGE_ENGINE=1 &> /dev/null
if [ $? -eq 0 ]
then
echo "mysql配置成功"
else
echo "mysql配置失败"
exit
fi
echo "----------正在安装编译安装Mysql请稍等-----------"
make &> /dev/null && make install /dev/null
if [ $? -eq 0 ]
then
echo "mysql编译安装成功"
else
echo "mysql编译安装失败"
exit
fi
echo [mysqld] > /etc/my.cnf
echo basedir=/usr/local/mysql >> /etc/my.cnf
echo datadir=/usr/local/mysql/data >> /etc/my.cnf
echo "mysql配置文件successed"
cd /usr/local/mysql/
mkdir mysql-files
chown -R mysql.mysql /usr/local/mysql
echo "-------------正在初始化Mysql请稍等--------------"
/usr/local/mysql/bin/mysqld --initialize --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data &> mima.txt
mima=awk '/password/ {print $NF}' mima.txt
echo "初始密码为:$mima"
if [ $? -eq 0 ]
then
echo "mysql初始化成功"
else
echo "mysql初始化失败"
exit
fi
bin/mysql_ssl_rsa_setup --datadir=/usr/local/mysql/data
#给数据库加密
cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld
chkconfig --add mysqld
chkconfig mysqld on
#添加到开机启动项
systemctl start mysqld
if [ $? -eq 0 ]
then
echo "mysql启动成功"
else
echo "mysql启动失败"
exit
fi
echo "export PATH=$PATH:/usr/local/mysql/bin" >> /etc/profile
source /etc/profile
echo "----------修改数据库初始密码----------"
read -p "请输入你要设置的数据库密码" new_mima
mysqladmin -uroot -p${mima} password "$new_mima"
if [ $? -eq 0 ]
then
echo "mysql初始密码修改成功,mysql部署完成"
else
echo "mysql初始密码修改失败"
exit
fi
}
while :
do
read -p "请输入你要选择的参数: " var
case $var in
a)
install_Apache
;;
b)
install_php
;;
c)
install_mysql
;;
d)
install_Apache
install_php
install_mysql
;;
q)
exit
;;
*)
printf "请按照上方提供的选项输入!!!\n"
;;
esac
done
网页标题:linuxcentos7终极编译部署LAMP环境脚本国内网站下载速度贼快
转载注明:http://scyanting.com/article/jjeocp.html