lamp环境部署脚本
#!/bin/bash
#date:2018-01-01
#author:by yangjw
#
############################################################ function 配置区域 ##############################################################################
############################# 环境统一安装包 ################################
depend_pkg (){
yum install -y gcc gcc-c++ make cmake automake autoconf \
ncurses-devel libxml2-devel perl-devel libcurl-devel libgcrypt \
libgcrypt-devel libxslt libxslt-devel pcre-devel openssl-devel \
wget bzip2-devel curl-devel db4-devel libjpeg-* libpng-* \
freetype-devel libXpm-devel gmp-devel libc-client-devel \
openldap-devel gd freetype zlib zlib-devel libtool expat-devel \
bison libtermcap-devel
CPU_NUM=`cat /proc/cpuinfo | grep processor | wc -l`
let CPUS=${CPU_NUM}-1
network_ip=`ip a | grep "em1" | awk '{print $2}' | cut -d / -f1 | egrep "((1[0-9][0-9]|2[0-4][0-9]|25[0-5]|[1-9][0-9]|[0-9]).){3}(1[0-9][0-9]|2[0-4][0-9]|25[0-5]|[1-9][0-9]|[0-9])"`
}
######################### 变量修改函数区域 ############################
All_path_1(){
Server_ip=${network_ip} # 本主机IP
Apache_version=2.4.39 # Apache 服务的版本号,如果没有限制,推荐默认安装的版本为 2.4.25 和 apr 1.5.2 apr-util1.5.4 是兼容的
Mysql_version=5.6.17 # Mysql 版本号,如果没有限制,默认安装的版本为 5.6.17
Libmcrypt_version=2.5.8 # 安装的版本号 默认推荐2.5.8
Mhash_version=0.9.9.9 # 默认推荐的版本0.9.9.9
Libiconv_version=1.13 # 默认推荐的版本1.13
Php_version=5.6.32 # Php的版本号,如果没有限制,默认安装的版本为 5.6.26
Apr_version=1.7.0 # Apr 的版本号,如果没有兼容性要求,默认安装的版本为 1.5.2
Apr_util_version=1.6.0 # Apr_util 的版本号,如果没有兼容性要求,默认安装的版本为 1.5.4
Mysql_port=3306 # MySQL 的监听端口号
soft_sign="PXJY_WebSer" # 隐藏apache名字和版本后,显示的标志名字
} All_path_2(){
Work_dir=/app/src # 源码包的存放路径
App_dir=/app # 如果想把MySQL安装目录和数据目录分开,就启用这个变量参数,针对mysql的数据目录存储的修改 Web_root_dir=${App_dir}/webroot/project # web 测试网站的程序目录位置
Web_logs_dir=${App_dir}/applog # web 日志路径位置
Web_install_dir=${App_dir}/httpd${Apache_version} # apache 的安装路径
Web_config_dir=${Web_install_dir}/conf # apache 的主配置文件目录 Mysql_boost_dir=${App_dir}/mysql${Mysql_version} # 针对MySQL boost文件配置的存放路径
Mysql_install_dir=${App_dir}/mysql${Mysql_version} # mysql 的安装路径
Mysql_conf_dir=${App_dir}/mysql${Mysql_version}/etc # mysql 配置文件的路径
Mysql_data_dir=${App_dir}/mysql${Mysql_version}/data # mysql 数据存放目录
Mysql_log_dir=${App_dir}/mysql${Mysql_version}/data # mysql 日志存放目录
Mysql_socket_dir=${App_dir}/mysql${Mysql_version}/data # mysql socket 存放路径位置
Mysql_server_id=${Mysql_port} # mysql 唯一的ID值 Php_install_dir=${App_dir}/php${Php_version} # php 安装路径
Php_config_dir=${Php_install_dir}/etc # php 配置文件路径
} ######################### Apache 安装相关函数 ###########################
Apr_install(){
cd $Work_dir
[ -f "apr-${Apr_version}.tar.gz" ] || wget http://archive.apache.org/dist/apr/apr-${Apr_version}.tar.gz
tar xvf apr-${Apr_version}.tar.gz
cd apr-${Apr_version}
echo -e "\033[34m 开始安装apache依赖软件包apr. . . . . .\033[0m"
sleep 2
./configure --prefix=/usr/local/apr
make -j ${CPUS} && make install
}
Apr_util_install(){
if [ $? -eq 0 ];then
echo -e "\033[34m Apr Install Successed ! \033[0m"
sleep 2
echo -e "\033[34m Beging Starting Install Apr-util \033[0m"
sleep 2
cd $Work_dir
[ -f "apr-util-${Apr_util_version}.tar.gz" ] || wget http://archive.apache.org/dist/apr/apr-util-${Apr_util_version}.tar.gz
tar xvf apr-util-${Apr_util_version}.tar.gz
cd apr-util-${Apr_util_version}
sleep 2
./configure --with-apr=/usr/local/apr
#./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr
make -j ${CPUS} && make install
if [ $? -eq 0 ];then
echo -e "\033[34m Apr-util Install Successed ! \033[0m" ; sleep 2
else
echo -e "\033[34m Apr-util Install Failed ! \033[0m"
fi
else
echo -e "\033[34m Apr Install Failed ! \033[0m"
exit 1
fi
sleep 2
} #隐藏apache版本号和更改软件名字标志的函数
Hidden_version(){
sed -i "/#define AP_SERVER_BASEPRODUCT/s/Apache/PXJY WebSer/" ${Work_dir}/httpd-${Apache_version}/include/ap_release.h
} Apache_install(){
cd $Work_dir
[ -f "httpd-${Apache_version}.tar.gz" ] || wget http://archive.apache.org/dist/httpd/httpd-${Apache_version}.tar.gz
tar zxf httpd-${Apache_version}.tar.gz
cd httpd-${Apache_version} #优化apache的请求数操作
perl -pi -e "s/DEFAULT_SERVER_LIMIT 256/DEFAULT_SERVER_LIMIT 15000/g" server/mpm/prefork/prefork.c
Hidden_version; echo -e "\033[34m 开始编译 apache 服务. . . . . .\033[0m"
sleep 2
#./configure --prefix=$Web_install_dir --with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util
./configure --prefix=$Web_install_dir --enable-modules=all --with-apr=/usr/local/apr \
--enable-expires=shared --enable-usertrack=shared --enable-vhost-alias=shared \
--enable-rewrite=shared --enable-speling=shared --enable-proxy=shared --enable-so \
--with-mpm=prefork --with-expat=builtin --enable-ssl
make -j ${CPUS} && make install
if [ $? -eq 0 ] ;then
echo -e "\033[34m Apache Service Install Successed ! \033[0m"
sleep 2
useradd -s /sbin/nologin apache
sed -i "s/#ServerName www.example.com:80/ServerName ${Server_ip}:80/g" ${Web_config_dir}/httpd.conf
sed -i "$ a Include conf/extra/httpd-vhosts.conf" ${Web_config_dir}/httpd.conf
sed -i "s/User daemon/User apache/g" ${Web_config_dir}/httpd.conf
sed -i "s/Group daemon/Group apache/g" ${Web_config_dir}/httpd.conf
sed -i 's/DirectoryIndex index.html/DirectoryIndex index.php index.html/g' ${Web_config_dir}/httpd.conf
sed -i '$ a ServerTokens Prod' ${Web_config_dir}/httpd.conf
sed -i '$ a ServerSignature Off' ${Web_config_dir}/httpd.conf
sed -i "s/#LoadModule/LoadModule/g" ${Web_config_dir}/httpd.conf
############## Include conf/extra/httpd-vhosts.conf ###################
mkdir -p ${Web_config_dir}/extra
mkdir -p ${Web_root_dir}
mkdir -p ${Web_logs_dir}
\cp ${Web_config_dir}/extra/httpd-vhosts.conf ${Web_config_dir}/extra/httpd-vhosts.conf.BAK
echo ${Apache_version} | grep "2.4.*" > /dev/null 2>&1
if [ $? -eq 0 ] ;then
#apache 2.4.X 版本的配置,版本2.2 和2.4 版本的配置文件有点区别
cat << EOF > ${Web_config_dir}/extra/httpd-vhosts.conf
<VirtualHost *:83>
ServerAdmin webmaster@dummy-host2.example.com
DocumentRoot "${Web_root_dir}"
ServerName ${Server_ip}
ErrorLog "${Web_logs_dir}/project_error.log"
CustomLog "${Web_logs_dir}/project_access.log" combined
DirectoryIndex index.php index.Html index.html
#php_admin_value open_basedir "${Web_root_dir}:/tmp:."
<Directory "${Web_root_dir}">
Options FollowSymLinks
AllowOverride All
Require all granted
</Directory>
</VirtualHost>
EOF
else
##apache 2.2.X 版本的配置
cat << EOF > ${Web_config_dir}/extra/httpd-vhosts.conf
NameVirtualHost *:80
<VirtualHost *:80>
DocumentRoot "${Web_root_dir}"
ServerName ${Server_ip}
DirectoryIndex index.php index.Html index.html
CustomLog "${Web_logs_dir}/project_access.log" common
ErrorLog "${Web_logs_dir}/project_error.log"
#限制跨站,安全访问,避免木马文件破坏其他目录下的文件
php_admin_value open_basedir "${Web_root_dir}/:/tmp:."
<Directory "${Web_root_dir}">
Options -Indexes MultiViews FollowSymLinks
AllowOverride All
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
EOF
fi
cat << EOF >> ${Web_config_dir}/httpd.conf
<IfModule prefork.c>
StartServers 10
MinSpareServers 10
MaxSpareServers 30
MaxClients 5000
MaxRequestsPerChild 0
</IfModule>
EOF
########## 配置网站默认页以及连接数据库的状态信息 ##############
cat << EOF > ${Web_root_dir}/index.html
<center><h1>Test ${Server_ip} : Apache-${Apache_version}</h1></center>
EOF
cat << EOF > ${Web_root_dir}/index.php
<?php
\$link = mysqli_connect("127.0.0.1:${Mysql_port}",'root','');
if (\$link)
echo "Success...";
else
echo "Failure...";
mysql_close();
phpinfo();
?>
EOF
##################### 正在启动apahce 服务 ###################
echo -e "\033[34m 正在启动Apache Service \033[0m"
sleep 2
${Web_install_dir}/bin/apachectl -k start
if [ $? -eq 0 ]; then
echo -e "\033[34m Apache Service Started Successed ! \033[0m"
else
echo -e "\033[34m Apache Service Started Failed ! \033[0m"
fi
else
echo -e "\033[34m Apache make install abnormal ! \033[0m"
exit 1
fi
}
######################### MySQL 安装相关函数 ############################
Config_MySQL_conf(){
cat << EOF > ${Mysql_conf_dir}/my.cnf
[mysqld]
# Remove leading # and set to the amount of RAM for the most important data
# cache in MySQL. Start at 70% of total RAM for dedicated server, else 10%.
innodb_buffer_pool_size = 1024M
# Remove leading # to turn on a very important data integrity option: logging
# changes to the binary log between backups.
log_bin = mysql-bin
default-storage-engine = InnoDB
character-set-server = utf8
# These are commonly set, remove the # and set as required.
basedir = ${Mysql_install_dir}
datadir = ${Mysql_data_dir}
port = ${Mysql_port}
server_id = ${Mysql_server_id}
socket = ${Mysql_socket_dir}/mysql.sock
#
#开启安全更新模式
#SQL_SAFE_UPDATES = 1
# per table for ibdatafile
innodb-file-per-table=1
pid-file=${Mysql_data_dir}/mysql.pid #binlog do db
#binlog-do-db = atrip_db_blog
#binlog-do-db = atrip_db_website
#binlog-ignore-db = mysql
#binlog-ignore-db = test # add connecton config by yangjw
max_heap_table_size = 64M
tmp_table_size = 64M
max_connections = 10000
max_connect_errors = 10000 skip_name_resolve = 1
event_scheduler = 1 #slow query log
slow_query_log=on
long_query_time=5 # Remove leading # to set options mainly useful for reporting servers.
# The server defaults are faster for transactions and fast SELECTs.
# Adjust sizes as needed, experiment to find the optimal values.
# join_buffer_size = 128M
# sort_buffer_size = 2M
# read_rnd_buffer_size = 2M
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
EOF
} MySQL_5_6_X(){
if [[ $Mysql_version =~ ^5.6 ]];then
id mysql > /dev/null 2>&1 || /usr/sbin/useradd -s /sbin/nologin mysql
mkdir -p ${Mysql_data_dir} ${Mysql_conf_dir}
cd ${Work_dir}
[ -f "mysql-${Mysql_version}.tar.gz" ] || wget https://downloads.mysql.com/archives/get/file/mysql-${Mysql_version}.tar.gz
tar zxvf mysql-${Mysql_version}.tar.gz -C $Work_dir/
cd mysql-${Mysql_version} echo -e "\n\033[34m 开始安装编译 mysql . . . . . . \033[0m\n"
sleep 2
/usr/bin/cmake -DCMAKE_INSTALL_PREFIX=${Mysql_install_dir} \
-DMYSQL_UNIX_ADDR=${Mysql_socket_dir}/mysql.sock \
-DSYSCONFDIR=${Mysql_conf_dir} \
-DDEFAULT_CHARSET=utf8 \
-DDEFAULT_COLLATION=utf8_general_ci \
-DWITH_EXTRA_CHARSETS:STRING=all \
-DWITH_MYISAM_STORAGE_ENGINE=1 \
-DWITH_INNOBASE_STORAGE_ENGINE=1 \
-DWITH_MEMORY_STORAGE_ENGINE=1 \
-DWITH_READLINE=1 \
-DENABLED_LOCAL_INFILE=1 \
-DWITH_SSL=bundled \
-DWITH_ZLIB=system \
-Dwith-mysqld-ldflags=-all-static \
-Dwith-client-ldflags=-all-static \
-DMYSQL_DATADIR=${Mysql_data_dir} \
-DMYSQL_USER=mysql \
-DMYSQL_TCP_PORT=${Mysql_port}
if [ $? -eq 0 ];then
if [ $CPUS -eq 0 ];then
echo -e "\e[1;33m +++++++++++++++++++++ \e[0m"
echo -e "\e[1;33m \ make 开始编译 \ \e[0m"
echo -e "\e[1;33m +++++++++++++++++++++ \e[0m"
sleep 3
make
echo -e "\e[1;33m +++++++++++++++++++++++++ \e[0m"
echo -e "\e[1;33m \make install 开始编译\ \e[0m"
echo -e "\e[1;33m ++++++++++++++++++++++++ \e[0m"
sleep 3
make install
else
echo -e "\e[1;33m +++++++++++++++++++++ \e[0m"
echo -e "\e[1;33m \ make 开始编译 \ \e[0m"
echo -e "\e[1;33m +++++++++++++++++++++ \e[0m"
sleep 3
make -j ${CPUS}
echo -e "\e[1;33m +++++++++++++++++++++++++ \e[0m"
echo -e "\e[1;33m \make install 开始编译\ \e[0m"
echo -e "\e[1;33m ++++++++++++++++++++++++ \e[0m"
sleep 3
make install
fi
[ $? -ne 0 ] && exit 1
chown -R mysql.mysql ${Mysql_data_dir}
cd ${Mysql_install_dir}
else
echo -e "\n\e[1;33m 编译有错误,请重新检查,编译 ! \e[0m\n"
exit 1
fi
else
echo -e "\n\e[1;33m 选择错误,请重新选择! \e[0m\n"
exit 1
fi
chmod +x scripts/mysql_install_db echo -e "\e[1;33m 开始初始化数据库实例\e[0m"
sleep 2
scripts/mysql_install_db --user=mysql --datadir=${Mysql_data_dir}
[ $? -eq 0 ] && echo -e "\n\e[1;33m== 初始化 successed ==\e[0m\n" || echo -e "\n\e[1;33m== 初始化 failed ==\e[0m\n" Config_MySQL_conf; echo -e "\e[1;33m 开始启动Mysql服务\e[0m"
sleep 2
${Mysql_install_dir}/bin/mysqld_safe --defaults-file=${Mysql_conf_dir}/my.cnf --user=mysql &
echo -e "\n\n" sleep 3
ss -ntl | grep $Mysql_port > /dev/null 2>&1
if [ $? -eq 0 ] ;then
echo
echo -e "\e[1;33m +------------------------------------------+ \e[0m"
echo -e "\e[1;33m /| /| \e[0m"
echo -e "\e[1;33m +------------------------------------------+ | \e[0m"
echo -e "\e[1;33m | | | | \e[0m"
echo -e "\e[1;33m | +-- Wecome to use MySQL${Mysql_version}------------|-+ \e[0m"
echo -e "\e[1;33m |/ |/ \e[0m"
echo -e "\e[1;33m +___________Successful_____________________+ \e[0m"
echo -e "\e[1;33m / / \e[0m"
echo -e "\e[1;33m / Perfect / \e[0m"
echo -e "\e[1;33m /__________________________________________/ \e[0m"
else
echo -e "\e[1;35m +---------------------------------+ \e[0m"
echo -e "\e[1;35m |\ Failed |\ \e[0m"
echo -e "\e[1;35m | +-------------------------------|-+ \e[0m"
echo -e "\e[1;35m | | | | \e[0m"
echo -e "\e[1;35m +-|---I'm Sorry,Please Checking---+-| \e[0m"
echo -e "\e[1;35m \| \| \e[0m"
echo -e "\e[1;35m +---------------------------------+ \e[0m"
echo -e "\e[1;35m \ \ \e[0m"
echo -e "\e[1;35m \ 请重新执行脚本 \ \e[0m"
echo -e "\e[1;35m \ \ \e[0m"
echo -e "\e[1;35m +---------------------------------+ \e[0m"
exit 1
fi
} MySQL_5_7_X(){
if [[ $Mysql_version =~ ^5.7 ]];then
id mysql > /dev/null 2>&1 || /usr/sbin/useradd -s /sbin/nologin mysql
mkdir -p ${Mysql_data_dir} ${Mysql_conf_dir}
cd ${Work_dir}
[ -f "${Work_dir}/boost_1_59_0.tar.gz" ] || wget http://liquidtelecom.dl.sourceforge.net/project/boost/boost/1.59.0/boost_1_59_0.tar.gz
tar zxvf boost_1_59_0.tar.gz -C ${Mysql_boost_dir} [ -f "mysql-${Mysql_version}.tar.gz" ] || wget https://downloads.mysql.com/archives/get/file/mysql-${Mysql_version}.tar.gz
tar zxvf mysql-${Mysql_version}.tar.gz -C $Work_dir/
cd mysql-${Mysql_version} echo -e "\n\033[34m 开始安装编译 mysql . . . . . . \033[0m\n"
sleep 2
/usr/bin/cmake -DCMAKE_INSTALL_PREFIX=${Mysql_install_dir} \
-DMYSQL_UNIX_ADDR=${Mysql_socket_dir}/mysql.sock \
-DSYSCONFDIR=${Mysql_conf_dir} \
-DDEFAULT_CHARSET=utf8 \
-DDEFAULT_COLLATION=utf8_general_ci \
-DWITH_EXTRA_CHARSETS:STRING=all \
-DWITH_MYISAM_STORAGE_ENGINE=1 \
-DWITH_INNOBASE_STORAGE_ENGINE=1 \
-DWITH_MEMORY_STORAGE_ENGINE=1 \
-DWITH_READLINE=1 \
-DENABLED_LOCAL_INFILE=1 \
-DWITH_SSL=bundled \
-DWITH_ZLIB=system \
-Dwith-mysqld-ldflags=-all-static \
-Dwith-client-ldflags=-all-static \
-DMYSQL_DATADIR=${Mysql_data_dir} \
-DMYSQL_USER=mysql \
-DMYSQL_TCP_PORT=${Mysql_port} \
-DWITH_BOOST=${Mysql_boost_dir}/boost_1_59_0
if [ $? -eq 0 ];then
if [ $CPUS -eq 0 ];then
echo -e "\e[1;33m +++++++++++++++++++++ \e[0m"
echo -e "\e[1;33m \ make 开始编译 \ \e[0m"
echo -e "\e[1;33m +++++++++++++++++++++ \e[0m"
sleep 3
make
echo -e "\e[1;33m +++++++++++++++++++++++++ \e[0m"
echo -e "\e[1;33m \make install 开始编译\ \e[0m"
echo -e "\e[1;33m ++++++++++++++++++++++++ \e[0m"
sleep 3
make install
else
echo -e "\e[1;33m +++++++++++++++++++++ \e[0m"
echo -e "\e[1;33m \ make 开始编译 \ \e[0m"
echo -e "\e[1;33m +++++++++++++++++++++ \e[0m"
sleep 3
make -j ${CPUS}
echo -e "\e[1;33m +++++++++++++++++++++++++ \e[0m"
echo -e "\e[1;33m \make install 开始编译\ \e[0m"
echo -e "\e[1;33m ++++++++++++++++++++++++ \e[0m"
sleep 3
make install
fi
[ $? -ne 0 ] && exit 1
chown -R mysql.mysql ${Mysql_data_dir}
cd ${Mysql_install_dir}
else
echo -e "\n\e[1;33m 编译有错误,请重新检查,编译 ! \e[0m\n"
exit 1
fi
else
echo -e "\n\e[1;33m 选择错误,请重新选择! \e[0m\n"
exit 1
fi echo -e "\n\e[1;33m 开始进行初始化数据库实例\e[0m\n"
sleep 2
${Mysql_install_dir}/bin/mysqld --initialize-insecure --user=mysql --basedir=${Mysql_install_dir} --datadir=${Mysql_data_dir}
[ $? -eq 0 ] && echo -e "\n\e[1;33m== 初始化 successed ==\e[0m\n" || echo -e "\n\e[1;33m== 初始化 failed ==\e[0m\n" Config_MySQL_conf; echo -e "\e[1;33m 开始启动Mysql服务\e[0m"
${Mysql_install_dir}/bin/mysqld_safe --defaults-file=${Mysql_conf_dir}/my.cnf --user=mysql &
echo -e "\n\n" sleep 3
ss -ntl | grep $Mysql_port > /dev/null 2>&1
if [ $? -eq 0 ] ;then
echo
echo -e "\e[1;33m +------------------------------------------+ \e[0m"
echo -e "\e[1;33m /| /| \e[0m"
echo -e "\e[1;33m +------------------------------------------+ | \e[0m"
echo -e "\e[1;33m | | | | \e[0m"
echo -e "\e[1;33m | +-- Wecome to use MySQL${Mysql_version}------------|-+ \e[0m"
echo -e "\e[1;33m |/ |/ \e[0m"
echo -e "\e[1;33m +___________Successful_____________________+ \e[0m"
echo -e "\e[1;33m / / \e[0m"
echo -e "\e[1;33m / Perfect / \e[0m"
echo -e "\e[1;33m /__________________________________________/ \e[0m"
else
echo -e "\e[1;35m +---------------------------------+ \e[0m"
echo -e "\e[1;35m |\ Failed |\ \e[0m"
echo -e "\e[1;35m | +-------------------------------|-+ \e[0m"
echo -e "\e[1;35m | | | | \e[0m"
echo -e "\e[1;35m +-|---I'm Sorry,Please Checking---+-| \e[0m"
echo -e "\e[1;35m \| \| \e[0m"
echo -e "\e[1;35m +---------------------------------+ \e[0m"
echo -e "\e[1;35m \ \ \e[0m"
echo -e "\e[1;35m \ 请重新执行脚本 \ \e[0m"
echo -e "\e[1;35m \ \ \e[0m"
echo -e "\e[1;35m +---------------------------------+ \e[0m"
exit 1
fi
} MySQL_8_X_X(){
if [[ $Mysql_version =~ ^8 ]];then
id mysql > /dev/null 2>&1 || /usr/sbin/useradd -s /sbin/nologin mysql
mkdir -p ${Mysql_data_dir} ${Mysql_conf_dir}
cd ${Work_dir}
[ -f "mysql-boost-${Mysql_version}.tar.gz" ] || wget https://downloads.mysql.com/archives/get/file/mysql-boost-${Mysql_version}.tar.gz
tar zxvf mysql-boost-${Mysql_version}.tar.gz -C $Work_dir/
cd mysql-${Mysql_version} echo -e "\n\033[34m 开始安装编译 mysql . . . . . . \033[0m\n"
sleep 2
/usr/bin/cmake -DCMAKE_INSTALL_PREFIX=${Mysql_install_dir} \
-DMYSQL_UNIX_ADDR=${Mysql_socket_dir}/mysql.sock \
-DSYSCONFDIR=${Mysql_conf_dir} \
-DDEFAULT_CHARSET=utf8 \
-DDEFAULT_COLLATION=utf8_general_ci \
-DWITH_EXTRA_CHARSETS:STRING=all \
-DWITH_MYISAM_STORAGE_ENGINE=1 \
-DWITH_INNOBASE_STORAGE_ENGINE=1 \
-DWITH_MEMORY_STORAGE_ENGINE=1 \
-DWITH_READLINE=1 \
-DENABLED_LOCAL_INFILE=1 \
-DWITH_SSL=bundled \
-DWITH_ZLIB=system \
-Dwith-mysqld-ldflags=-all-static \
-Dwith-client-ldflags=-all-static \
-DMYSQL_DATADIR=${Mysql_data_dir} \
-DMYSQL_USER=mysql \
-DMYSQL_TCP_PORT=${Mysql_port} \
-DWITH_BOOST=${Mysql_boost_dir}/src/mysql-${Mysql_version}/boost/
if [ $? -eq 0 ];then
if [ $CPUS -eq 0 ];then
echo -e "\e[1;33m +++++++++++++++++++++ \e[0m"
echo -e "\e[1;33m \ make 开始编译 \ \e[0m"
echo -e "\e[1;33m +++++++++++++++++++++ \e[0m"
sleep 3
make
echo -e "\e[1;33m +++++++++++++++++++++++++ \e[0m"
echo -e "\e[1;33m \make install 开始编译\ \e[0m"
echo -e "\e[1;33m ++++++++++++++++++++++++ \e[0m"
sleep 3
make install
else
echo -e "\e[1;33m +++++++++++++++++++++ \e[0m"
echo -e "\e[1;33m \ make 开始编译 \ \e[0m"
echo -e "\e[1;33m +++++++++++++++++++++ \e[0m"
sleep 3
make -j ${CPUS}
echo -e "\e[1;33m +++++++++++++++++++++++++ \e[0m"
echo -e "\e[1;33m \make install 开始编译\ \e[0m"
echo -e "\e[1;33m ++++++++++++++++++++++++ \e[0m"
sleep 3
make install
fi
[ $? -ne 0 ] && exit 1
chown -R mysql.mysql ${Mysql_data_dir}
cd ${Mysql_install_dir}
else
echo -e "\n\e[1;33m 编译有错误,请重新检查,编译 ! \e[0m\n"
exit 1
fi
else
echo -e "\n\e[1;33m 选择错误,请重新选择! \e[0m\n"
exit 1
fi echo -e "\n\e[1;33m 开始进行初始化数据库实例\e[0m\n"
sleep 2
${Mysql_install_dir}/bin/mysqld --initialize-insecure --user=mysql --basedir=${Mysql_install_dir} --datadir=${Mysql_data_dir}
[ $? -eq 0 ] && echo -e "\n\e[1;33m== 初始化 successed ==\e[0m\n" || echo -e "\n\e[1;33m== 初始化 failed ==\e[0m\n" Config_MySQL_conf; echo -e "\e[1;33m 开始启动Mysql服务\e[0m"
${Mysql_install_dir}/bin/mysqld_safe --defaults-file=${Mysql_conf_dir}/my.cnf --user=mysql &
echo -e "\n" sleep 3
ss -ntl | grep $Mysql_port > /dev/null 2>&1
if [ $? -eq 0 ] ;then
echo
echo -e "\e[1;33m +------------------------------------------+ \e[0m"
echo -e "\e[1;33m /| /| \e[0m"
echo -e "\e[1;33m +------------------------------------------+ | \e[0m"
echo -e "\e[1;33m | | | | \e[0m"
echo -e "\e[1;33m | +-- Wecome to use MySQL${Mysql_version}------------|-+ \e[0m"
echo -e "\e[1;33m |/ |/ \e[0m"
echo -e "\e[1;33m +___________Successful_____________________+ \e[0m"
echo -e "\e[1;33m / / \e[0m"
echo -e "\e[1;33m / Perfect / \e[0m"
echo -e "\e[1;33m /__________________________________________/ \e[0m"
else
echo -e "\e[1;35m +---------------------------------+ \e[0m"
echo -e "\e[1;35m |\ Failed |\ \e[0m"
echo -e "\e[1;35m | +-------------------------------|-+ \e[0m"
echo -e "\e[1;35m | | | | \e[0m"
echo -e "\e[1;35m +-|---I'm Sorry,Please Checking---+-| \e[0m"
echo -e "\e[1;35m \| \| \e[0m"
echo -e "\e[1;35m +---------------------------------+ \e[0m"
echo -e "\e[1;35m \ \ \e[0m"
echo -e "\e[1;35m \ 请重新执行脚本 \ \e[0m"
echo -e "\e[1;35m \ \ \e[0m"
echo -e "\e[1;35m +---------------------------------+ \e[0m"
exit 1
fi
} Mysql_install(){
echo -e "\n选择匹配数据库的安装版本 \n"
echo -e "\t 1. Install 5.6.X: \n"
echo -e "\t 2. Install 5.7.X: \n"
echo -e "\t 3. Install 8.X.X: \n"
echo -e "\t 0. 退出本次循环: \n"
read -n 1 -p "Please Input Numbers : " DB_Version
case $DB_Version in
1)
depend_pkg;
All_path_1;
All_path_2;
mkdir -p $Work_dir;
MySQL_5_6_X;
;;
2)
depend_pkg;
All_path_1;
All_path_2;
mkdir -p $Work_dir;
MySQL_5_7_X;
;;
3)
depend_pkg;
All_path_1;
All_path_2;
mkdir -p $Work_dir;
MySQL_8_X_X;
;;
0)
continue
;;
*)
clear
echo -e "\nI'm Sorry ! please input numbers [1,2,3,0]\n"
;;
esac
echo -en "\t\t\t 任意键继续\n"
read -n 1 line
} ######################### Php 安装相关函数 ############################
Qdbm_install(){
cd ${Work_dir}
[ -f qdbm-1.8.78.tar.gz ] || wget http://fallabs.com/qdbm/qdbm-1.8.78.tar.gz
tar xf qdbm-1.8.78.tar.gz
cd qdbm-1.8.78
./configure
make -j ${CPUS} && make install
} #此libmcrypt安装主要是考虑到后面会用到mcrypt模块,提前先安装上,如果需要安装mcrypt模块的话直接在php源码目录里装即可
Libmcrypt_install(){
cd ${Work_dir}
[ -f "libmcrypt-${Libmcrypt_version}.tar.gz" ] || wget https://jaist.dl.sourceforge.net/project/mcrypt/Libmcrypt/${Libmcrypt_version}/libmcrypt-${Libmcrypt_version}.tar.gz
tar -zxvf libmcrypt-${Libmcrypt_version}.tar.gz
cd libmcrypt-${Libmcrypt_version}
./configure
make -j $CPUS && make install
cd libltdl
./configure --with-gmetad --enable-gexec --enable-ltdl-install
make -j $CPUS && make install
} Mhash_install(){
cd ${Work_dir}
[ -f "mhash-${Mhash_version}.tar.gz" ] || wget https://jaist.dl.sourceforge.net/project/mhash/mhash/${Mhash_version}/mhash-${Mhash_version}.tar.gz
tar -zxvf mhash-${Mhash_version}.tar.gz
cd mhash-${Mhash_version}
./configure
make -j $CPUS && make install
} Libiconv_install(){
cd $Work_dir
[ -f "libiconv-${Libiconv_version}.tar.gz" ] || wget http://ftp.gnu.org/pub/gnu/libiconv/libiconv-${Libiconv_version}.tar.gz
tar -zxvf libiconv-${Libiconv_version}.tar.gz
cd libiconv-${Libiconv_version}
./configure
make -j $CPUS && make install
} Php_install(){
cd ${Work_dir}
[ -f "php-${Php_version}.tar.gz" ] || wget http://am1.php.net/distributions/php-${Php_version}.tar.gz
tar xvf php-${Php_version}.tar.gz
cd php-${Php_version}
echo -e "\033[34m 开始安装编译 php . . . . . . \033[0m"
sleep 3
./configure --prefix=${Php_install_dir} --with-mysql=mysqlnd --with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd \
--with-apxs2=${Web_install_dir}/bin/apxs --with-config-file-path=${Php_install_dir}/etc --enable-pic --disable-static \
--enable-mbstring --enable-inline-optimization --with-regex=system --with-gettext --with-gd --with-png --with-zlib \
--enable-debugger --disable-debug --enable-magic-quotes --enable-safe-mode --enable-sysvmsg --enable-sysvsem --enable-sysvshm\
--enable-track-vars --enable-yp --enable-ftp --with-xml --with-freetype-dir=/usr --with-png-dir=/usr --enable-gd-native-ttf \
--with-ttf --with-ncurses --with-gmp --with-iconv --with-jpeg-dir=/usr --with-expat-dir=/usr --enable-bcmath --enable-exif \
--enable-sockets --enable-discard-path --enable-wddx --enable-trans-sid --enable-wddx --enable-versioning --enable-calendar \
--enable-dbx --enable-dio --enable-mcal --enable-shmop --with-curl --with-openssl --with-qdbm --enable-fpm --enable-fastcgi\
--enable-zip --with-mcrypt --with-mhash --with-qdbm
if [ $? -eq 0 ];then
echo -e "\e[1;33m +++++++++++++++++++++ \e[0m"
echo -e "\e[1;33m \ make 开始编译 \ \e[0m"
echo -e "\e[1;33m +++++++++++++++++++++ \e[0m"
sleep 3
make -j ${CPUS} ZEND_EXTRA_LIBS='-liconv'
echo -e "\e[1;33m +++++++++++++++++++++++++ \e[0m"
echo -e "\e[1;33m \make install 开始编译\ \e[0m"
echo -e "\e[1;33m ++++++++++++++++++++++++ \e[0m"
sleep 3
make install
if [ $? -eq 0 ];then
echo -e "\033[34m PHP Install Successed ! \033[0m"
cp php.ini-production ${Php_config_dir}/php.ini
sed -i '/upload_max_filesize/s/2/50/' ${Php_config_dir}/php.ini
sed -i '/post_max_size/s/8/50/' ${Php_config_dir}/php.ini
sed -i "/expose_php/s/On/OFF/" ${Php_config_dir}/php.ini
sed -i '$a ;date.timezone=PRC\ndate.timezone = Asia/Shanghai' ${Php_config_dir}/php.ini
sed -i '$a ;关闭高危函数应用\ndisable_functions = passthru,exec,system,chroot' ${Php_config_dir}/php.ini echo -e "\033[34m php.ini config complete !!! \033[0m"
mkdir -p ${Web_root_dir} ${Web_logs_dir}
#lamp环境编译php时,主要进行的配置
echo "AddType application/x-httpd-php .php" >> ${Web_config_dir}/httpd.conf
echo "AddType application/x-httpd-php-source .phps" >> ${Web_config_dir}/httpd.conf
echo -e "\033[34m php modules append to httpd.conf complete!!! \033[0m" echo -e "\033[34m 重启动 apache 服务\033[0m"
${Web_install_dir}/bin/apachectl restart
sleep 3
#egrep -i "export PHPRC=${Php_config_dir}/php.ini " /etc/profile > /dev/null 2>&1
#if [ $? -ne 0 ] ;then
# echo "export PHPRC=${Php_config_dir}/php.ini " >> /etc/profile
#fi
#source /etc/profile
else
echo -e "\033[34m PHP Install Failed ! \033[0m"
exit 1
fi
else
echo -e "\033[34m Congfigure Install Php Abnormal \033[0m"
exit 1
fi
}
###########################################################################################################################################################################
############################# 脚本主程序内容 ##################################
while [ 1 ]
do
echo
All_path_1
echo -e "\t\t\tSys Admin Menu\n"
echo -e "\t 1. Install Apache: ${Apache_version}\n"
echo -e "\t 2. Install Mysql: Continue...... \n"
echo -e "\t 3. Install Php: ${Php_version} \n"
echo -e "\t 0. 退出脚本程序 \n" read -n 1 -p "Please Input Numbers : " NUM
case $NUM in
1)
echo -e "\033[34m 安装配置 Apache 环境 ............... \033[0m"
sleep 2
depend_pkg;
All_path_1;
All_path_2;
mkdir -p $Work_dir;
Apr_install;
Apr_util_install;
Apache_install;
;;
2)
echo -e "\033[34m 安装配置 MySQL 环境 ............... \033[0m"
sleep 2
Mysql_install;
;;
3)
echo -e "\033[34m 安装配置 Php 环境 ............... \033[0m"
sleep 2
depend_pkg;
All_path_1;
All_path_2;
mkdir -p $Work_dir;
Qdbm_install;
Libmcrypt_install;
Mhash_install;
Libiconv_install;
Php_install;
;;
0)
echo -e "\n"
exit 1
;;
*)
clear
echo -e "\033[34m Please Input [ 1 | 2 | 3 | 0 ] \033[0m"
esac
echo -en "\t\t\t 任意键继续"
read -n 1 line
done
lamp环境部署脚本的更多相关文章
- 搭建LAMP环境部署GLPI资源管理系统
搭建LAMP环境部署GLPI资源管理系统 一.关闭防火墙和Selinux [root@localhost ~]# systemctl disable --now firewalld [root@loc ...
- 搭建LAMP环境部署opensns微博网站
搭建LAMP环境部署opensns微博网站 实验环境 centos7 ip: 192.168.121.17 一.关闭防火墙和selinux [root@localhost ~]# systemctl ...
- 搭建LAMP环境部署Nextcloud私人网盘
搭建 LAMP 环境部署 Nextcloud 私人网盘 前言 Nextcloudd 是一个开源的.基于本地的文件共享和协作平台,它允许您保存文件并通过多个设备(如PC.智能手机和平板电脑)访问它们. ...
- LAMP环境部署物联网项目
今天来在LAMP环境下搭建一个PHP项目,开始之前,先来普及下物联网常识: 物联网,即Internet of Things,简写IOT.让所有能行使独立功能的普通物体实现互联互通的网络,通过物联网可以 ...
- 安装Rocky版OpenStack 1控制节点+1计算节点环境部署脚本
在上一篇文章中叙述了具体的安装部署过程,在这里把相应的部署脚本写出来,供大家参考: 一.执行部署的setup.sh脚本: #!/bin/bash ########################### ...
- 搭建LAMP环境部署Ecshop电商网站
实战-部署Ecshop电商网站 实验环境 Centos7 ip:192.168.121.17 一.关闭防火墙和selinux [root@localhost ~]# systemctl stop fi ...
- linux系统LAMP环境部署
一.安装虚拟机 二.安装CentOS7 注意:以下安装,用的root权限. 三.安装Apache 1.安装 yum -y install httpd 2.开启apache服务 systemctl st ...
- lnmp环境部署脚本-y
系统环境:centos6.X #!/bin/bash#date:2018-01-01## MySQL 安装8版本的话不太适合,有待于添加安装脚本进行测试#新版的MySQL安装需要高版本2.8以上cma ...
- 搭建LAMP环境部署discuz论坛
!!!什么是LAMP: LAMP是指一组通常一起使用来运行动态网站或者服务器的自由软件名称首字母缩写: Linux,操作系统 Apache,网页服务器 MariaDB或MySQL,数据库管理系统(或者 ...
随机推荐
- Mac下Charles Contents乱码解决办法
用到Charles,下载最新的4.0.1版本,但是发生乱码问题.百度好久才找到个靠谱的,那些说什么在Info.plist文件加字符串的,都是假的,反正我是试了都没用,这里记下详细的操作步骤解决: 1. ...
- mysql 查看索引使用情况
show status like 'Handler_read%'; Handler_read_key 代表着一个行被索引值读取的次数,值很低表明索引不经常用到,增加索引对性能改善不高. Handle ...
- mybatis实战教程三:多对多关联
MyBatis3.0 添加了association和collection标签专门用于对多个相关实体类数据进行级联查询,但仍不支持多个相关实体类数据的级联保存和级联删除操作 一.创建student.te ...
- JS的for循环小例子
1.输出1-100的和 var sum = 0; for(var i=1;i<=100;i++){ sum = sum + i; } document.write(sum); 2.输出1-100 ...
- 计算器(Ext)
<html> <head> <title>计算器</title> <meta charset="UTF-8"> < ...
- backupMysql.sh
#!/bin/sh #!/bin/bash function backup() { for i in $* do mysqldump -h$hostip -P$port -u$username -p$ ...
- shell获取字符串长度
方法1: 使用wc -L命令 wc -L可以获取到当前行的长度,因此对于单独行的字符串可以用这个简单的方法获取,另外wc -l则是获取当前字符串内容的行数. 代码如下: echo "abc& ...
- print,printf,println
1.print,打印你要打印的东西. 2.printf,可以定义要打印数据的格式,弄个%d,%f之类的.而print不行. 3.println, 会在打印完内容后换行. println和print的差 ...
- 浅谈最大流的Dinic算法
PART 1 什么是网络流 网络流(network-flows)是一种类比水流的解决问题方法,与线性规划密切相关.网络流的理论和应用在不断发展,出现了具有增益的流.多终端流.多商品流以及网络流的分解与 ...
- Tomcat+Servlet面试题都在这里
下面是我整理下来的Servlet知识点:  图上的知识点都可以在我其他的文章内找到相应内容. Tomcat常见面试题 Tomcat的缺省端口是多少,怎么修改 Tomcat的缺省端口是多少,怎么修改 ...