=======该脚本在CentOS6.5_x86_64位系统验证通过,荐于环境限制其它平台未做测试========
安装方式:
===================================================================================
将OneKey_Install_LNMP.zip上传到Linux服务器后解压并执行包中shell脚本:
解压包:unzip OneKey_Install_LNMP.zip
切换包目录:cd OneKey_Install_LNMP
执行脚本:./linux_lnmp_install.sh
-----------------------------------------------------------------------------------
软件包版本:
===================================================================================
操作系统版本:CentOS6.5_x86_64bit
MySQL:mysql-5.6.23.tar.gz
Nginx:nginx-1.8.0.tar.gz
Php:php-5.6.8.tar.gz
Xcache:xcache-3.2.0.tar.gz
-----------------------------------------------------------------------------------
安装目录规划:
====================================================================================
MySQL程序目录:/opt/application/mysql
MySQL数据目录:/opt/data/3307
MySQL Socket目录:/opt/data/3307/mysql.sock
MySQL端口:3307
MySQL root密码:123456
Nginx程序目录:/opt/application/nginx
Php程序目录:/opt/application/php
项目文件目录:/opt/www
-------------------------------------------------------------------------------------
程序启停操作:
=====================================================================================
MySQL启停:/opt/data/3307/mysql start | stop
Nginx启停:service nginx start | stop | reload | configtest
php-fpm启停:service php-fpm start | stop | reload
脚本执行过程:
======================================================================================
第一步:配置Yum安装源,使用EPEL
第二步:检测网络环境并验证Yum安装源配置是否生效
第三步:安装依赖包
第四步:安装MySQL
第五步:MySQL基础优化
第六步:安装Nginx
第七步:安装Php
第八步:配置php-fpm
第九步:phpinfo测试
第十步:安装Xcache缓存加速模块
第十一步:交互式判断是否需要安装phpmyadmin项目,如果输入Yes则安装,如果输入No则结束安装
备注:安装完phpmyadmin后,如果想直接通过IP地址访问,则修改nginx虚拟主机的server为IP地址
然后重新加载nginx即可
---------------------------------------------------------------------------------------
#!/bin/sh ############################### #Created: William Tian #Date: 2015/8/22 #Version: 1.0.0 ############################### # This is an interactive program, we need the current locale [ -f /etc/profile.d/lang.sh ] && . /etc/profile.d/lang.sh # We can‘t Japanese on normal console at boot time, so force LANG=C. if [ "$LANG" = "ja" -o "$LANG" = "ja_JP.eucJP" ]; then if [ "$TERM" = "linux" ] ; then LANG=C fi fi # Source function library. . /etc/init.d/functions # Source networking configuration. [ -f /etc/sysconfig/network ] && . /etc/sysconfig/network Yum_Dir="/etc/yum.repos.d" Mysql_Base_Dir="/opt/application/mysql" Mysql_Data_Dir="/opt/data/3307" Mysql_Socket="$Mysql_Data_Dir/mysql.sock" Mysql_Pwd="123456" Nginx_Dir="/opt/application/nginx" Php_Dir="/opt/application/php" Web_Dir="/opt/www" ###config yum### function conf_yum() { if [ -f CentOS6.5.repo.tar.gz ];then mkdir $Yum_Dir/repobak mv $Yum_Dir/*.repo $Yum_Dir/repobak tar -zxf CentOS6.5.repo.tar.gz -C $Yum_Dir else echo -e "\033[33;1mCentOS6.5.repo.tar.gz package not found\033[0m" exit fi } ###verify yum config isvalidate### function verify_yum() { Code=`curl -I -s www.qq.com|head -1|awk ‘{print $2}‘` if [[ $Code != "200" ]];then echo -e "\033[33;1mPlease check your network\033[0m" exit fi yum clean all && yum repolist li=`yum repolist|grep epel|awk ‘{print $NF}‘` if [[ $li != "0" ]];then echo -e "\033[34;1mYum repository EPEL Success\033[0m" else echo -e "\033[31;1mYum repository EPEL Failed\033[0m" fi } ###before install lamp, check depend on the package### function preinstall_check() { Count=0 while true do num=`rpm -q wget gcc gcc-c++ make cmake tcl re2c curl libcurl-devel libxml2 libxml2-devel libjpeg-turbo libjpeg-turbo-devel libpng libpng-devel libmcrypt libmcrypt-devel zlib zlib-devel openssl openssl-devel freetype freetype-devel gd gd-devel perl perl-devel ncurses ncurses-devel bison bison-devel libtool gettext gettext-devel bzip2 bzip2-devel pcre pcre-devel|grep "not installed"|wc -l` if [ $num -ne 0 ];then yum -y install wget gcc gcc-c++ make cmake tcl re2c curl libcurl-devel libxml2 libxml2-devel libjpeg-turbo libjpeg-turbo-devel libpng libpng-devel libmcrypt libmcrypt-devel zlib zlib-devel openssl openssl-devel freetype freetype-devel gd gd-devel perl perl-devel ncurses ncurses-devel bison bison-devel libtool gettext gettext-devel bzip2 bzip2-devel pcre pcre-devel let Count++ else echo -e "\033[34;1mAll dependent packages installed success\033[0m" break fi if [ $Count -ge 3 ];then echo -e "\033[31;1mExceeded 3 times try install failed, please check yum configuration or check your network\033[0m" exit fi done } ###compile install mysql### function install_mysql() { if [ -f mysql-5.6.23.tar.gz ];then /usr/sbin/groupadd -r -g 109 mysql /usr/sbin/useradd -u 109 -g 109 -r mysql mkdir -p $Mysql_Base_Dir mkdir -p $Mysql_Data_Dir/data chown -R mysql:mysql $Mysql_Data_Dir tar -zxf mysql-5.6.23.tar.gz cd mysql-5.6.23 cmake -DCMAKE_INSTALL_PREFIX=$Mysql_Base_Dir -DMYSQL_DATADIR=$Mysql_Data_Dir/data -DSYSCONFDIR=$Mysql_Data_Dir -DWITH_MYISAM_STORAGE_ENGINE=1 -DWITH_INNOBASE_STORAGE_ENGINE=1 -DWITH_MEMORY_STORAGE_ENGINE=1 -DWITH_READLINE=1 -DMYSQL_USER=mysql -DMYSQL_UNIX_ADDR=$Mysql_Data_Dir/mysql.sock -DMYSQL_TCP_PORT=3307 -DENABLED_LOCAL_INFILE=1 -DWITH_PARTITION_STORAGE_ENGINE=1 -DEXTRA_CHARSETS=all -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci make && make install $Mysql_Base_Dir/scripts/mysql_install_db --basedir=$Mysql_Base_Dir --datadir=$Mysql_Data_Dir/data --user=mysql cd ../ && cp my.cnf mysql $Mysql_Data_Dir chmod 700 $Mysql_Data_Dir/mysql chmod 600 $Mysql_Data_Dir/my.cnf rm -f $Mysql_Data_Dir/data/ib* #delete init created log file $Mysql_Data_Dir/mysql start sleep 5 else echo -e "\033[33;1mmysql-5.6.23.tar.gz package not found\033[0m" exit fi Port=`netstat -natp|grep 3307|grep mysqld|wc -l` if [ $Port -ne 1 ];then echo -e "\033[31;1mMysql start failed,please trouble shooting\033[0m" exit else echo -e "\033[34;1mMysql install success\033[0m" fi } ###Optimization mysql### function mysql_optimize() { #alter root password $Mysql_Pwd $Mysql_Base_Dir/bin/mysqladmin -uroot password "$Mysql_Pwd" -S $Mysql_Socket $Mysql_Base_Dir/bin/mysql -uroot -p"$Mysql_Pwd" -S $Mysql_Socket -e "drop table if exists mysql.innodb_index_stats" $Mysql_Base_Dir/bin/mysql -uroot -p"$Mysql_Pwd" -S $Mysql_Socket -e "drop table if exists mysql.innodb_table_stats" $Mysql_Base_Dir/bin/mysql -uroot -p"$Mysql_Pwd" -S $Mysql_Socket -e "drop table if exists mysql.slave_master_info" $Mysql_Base_Dir/bin/mysql -uroot -p"$Mysql_Pwd" -S $Mysql_Socket -e "drop table if exists mysql.slave_relay_log_info" $Mysql_Base_Dir/bin/mysql -uroot -p"$Mysql_Pwd" -S $Mysql_Socket -e "drop table if exists mysql.slave_worker_info" $Mysql_Data_Dir/mysql stop rm -f $Mysql_Data_Dir/data/mysql/*.ibd line=`ls -l $Mysql_Data_Dir/data/mysql/*.ibd|wc -l` [ $line -eq 0 ] && $Mysql_Data_Dir/mysql start sed -i ‘19ause mysql;‘ $Mysql_Base_Dir/share/mysql_system_tables.sql $Mysql_Base_Dir/bin/mysql -uroot -p"$Mysql_Pwd" -S $Mysql_Socket < $Mysql_Base_Dir/share/mysql_system_tables.sql $Mysql_Base_Dir/bin/mysql -uroot -p"$Mysql_Pwd" -S $Mysql_Socket -e "delete from mysql.proxies_priv where Host=‘$HOSTNAME‘" $Mysql_Base_Dir/bin/mysql -uroot -p"$Mysql_Pwd" -S $Mysql_Socket -e "delete from mysql.user where password=‘‘" $Mysql_Base_Dir/bin/mysql -uroot -p"$Mysql_Pwd" -S $Mysql_Socket -e "drop database test" $Mysql_Data_Dir/mysql stop sleep 2 $Mysql_Data_Dir/mysql start } ###compile install nginx### function install_nginx() { if [ -f nginx-1.8.0.tar.gz ];then groupadd -r -g 108 nginx useradd -u 108 -g 108 -r nginx tar -zxf nginx-1.8.0.tar.gz cd nginx-1.8.0 ./configure --user=nginx --group=nginx --prefix=$Nginx_Dir --with-http_stub_status_module --with-http_ssl_module --with-pcre --with-http_gzip_static_module make && make install cd ../ && cp nginx /etc/init.d chmod +x /etc/init.d/nginx /sbin/chkconfig --add nginx && /sbin/chkconfig nginx on #mv -f nginx.conf $Nginx_Dir/conf mv $Nginx_Dir/conf/nginx.conf $Nginx_Dir/conf/nginx.conf.eri cp nginx.conf $Nginx_Dir/conf mkdir $Nginx_Dir/conf/vhosts /etc/init.d/nginx start Port=`netstat -natp|grep 80|grep nginx|wc -l` if [ $Port -ne 1 ];then echo -e "\033[31;1mNginx start failed, please check config\033[0m" exit fi else echo -e "\033[33;1mnginx-1.8.0.tar.gz package not found\033[0m" exit fi } ###compile install php### function install_php() { if [ -f php-5.6.8.tar.gz ];then tar -zxf php-5.6.8.tar.gz cd php-5.6.8 ./configure --prefix=$Php_Dir --with-config-file-path=$Php_Dir/etc --with-mysql=$Mysql_Base_Dir --with-mysql-sock=$Mysql_Data_Dir/mysql.sock --with-mysqli=$Mysql_Base_Dir/bin/mysql_config --with-libxml-dir --with-png-dir --with-jpeg-dir --with-freetype-dir --with-gd --with-zlib-dir --with-mcrypt --with-gettext --with-pdo-mysql --enable-fpm --enable-mbstring=all --enable-sockets --enable-ftp --enable-zip make && make install cp php.ini-production $Php_Dir/etc/php.ini cd ../ else echo -e "\e[1;33mphp-5.6.8.tar.gz package not found\e[0m" exit fi } ###configuration php-fpm### function conf_php_fpm() { cp php-5.6.8/sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm chmod +x /etc/init.d/php-fpm /sbin/chkconfig --add php-fpm && /sbin/chkconfig php-fpm on cp $Php_Dir/etc/php-fpm.conf.default $Php_Dir/etc/php-fpm.conf #edit php-fpm.conf sed -i ‘s/^pm.max_children.*$/pm.max_children = 150/‘ $Php_Dir/etc/php-fpm.conf sed -i ‘s/^pm.start_servers.*$/pm.start_servers = 8/‘ $Php_Dir/etc/php-fpm.conf sed -i ‘s/^pm.min_spare_servers.*$/pm.min_spare_servers = 5/‘ $Php_Dir/etc/php-fpm.conf sed -i ‘s/^pm.max_spare_servers.*$/pm.max_spare_servers = 10/‘ $Php_Dir/etc/php-fpm.conf sed -i ‘s/^;pm.max_requests.*$/pm.max_requests = 5000/‘ $Php_Dir/etc/php-fpm.conf sed -i ‘s/^;rlimit_files.*$/rlimit_files = 51200/‘ $Php_Dir/etc/php-fpm.conf sed -i ‘s/^user.*$/user = nginx/‘ $Php_Dir/etc/php-fpm.conf sed -i ‘s/^group.*$/group = nginx/‘ $Php_Dir/etc/php-fpm.conf #start php-fpm /etc/init.d/php-fpm start Foo=`netstat -natp|grep 9000|grep php-fpm|wc -l` if [ $Foo -eq 1 ];then echo -e "\e[1;34mphp-fpm service start success\e[0m" else echo -e "\e[1;31mphp-fpm service start failed\e[0m" fi } ###phpinfo access test### function phpinfo_test() { [ ! -d $Web_Dir ] && mkdir -p $Web_Dir echo "<?php phpinfo();?>" >$Web_Dir/index.php } ###install xcache acceleration### function install_xcache() { if [ -f xcache-3.2.0.tar.gz ];then tar -zxf xcache-3.2.0.tar.gz && cd xcache-3.2.0 $Php_Dir/bin/phpize ./configure --enable-xcache --with-php-config=$Php_Dir/bin/php-config make && make install cat xcache.ini >> $Php_Dir/etc/php.ini cd ../ /etc/init.d/php-fpm reload /etc/init.d/nginx stop sleep 2 /etc/init.d/nginx start else echo -e "\e[1;33mxcache-3.2.0.tar.gz package not found\e[0m" exit fi } ###create phpmyadmin project### function create_phpmyadmin_pro() { if [ -f phpMyAdmin-4.4.6-all-languages.tar.bz2 ];then tar -jxf phpMyAdmin-4.4.6-all-languages.tar.bz2 mv phpMyAdmin-4.4.6-all-languages $Web_Dir/phpmyadmin [ ! -d $Nginx_Dir/conf/vhosts ] && mkdir $Nginx_Dir/conf/vhosts cp phpmyadmin.vhost.conf $Nginx_Dir/conf/vhosts /etc/init.d/nginx reload else echo -e "\e[1;33mphpMyAdmin-4.4.6-all-languages.tar.bz2 package not found\e[0m" exit fi } ###judge create phpmyadmin project whether or not### function judge_whether_create_phpmyadmin() { while true do echo -e "\033[32;1m================================================\033[0m" read -p "Do you want to install phpmyadmin project?[Yes|No] " answer case $answer in "Yes") create_phpmyadmin_pro break ;; "No") exit 0 ;; *) echo -e "\033[33;1mPlease input Yes or No\033[0m" esac done } ###fllow the sequence active### echo -e "\033[32;1m===========================================\033[0m" echo -e "\033[32;1mConfig Yum Source\033[0m" echo conf_yum echo -e "\033[32;1m===========================================\033[0m" echo -e "\033[32;1mVerfiy Yum Source isValidate\033[0m" echo verify_yum echo -e "\033[32;1m===========================================\033[0m" echo -e "\033[32;1mCheck and Yum Install LNMP Dependent package\033[0m" echo preinstall_check echo -e "\033[32;1m===========================================\033[0m" echo -e "\033[32;1mInstall Mysql......\033[0m" echo install_mysql echo -e "\033[32;1m===========================================\033[0m" echo -e "\033[32;1mOptimization Mysql......\033[0m" echo mysql_optimize echo -e "\033[32;1m===========================================\033[0m" echo -e "\033[32;1mInstall Nginx......\033[0m" echo install_nginx echo -e "\033[32;1m===========================================\033[0m" echo -e "\033[32;1mInstall Php......\033[0m" echo install_php echo -e "\033[32;1m===========================================\033[0m" echo -e "\033[32;1mConfig php-fpm......\033[0m" echo conf_php_fpm echo -e "\033[32;1m===========================================\033[0m" echo -e "\033[32;1mphpinfo test......\033[0m" echo phpinfo_test echo -e "\033[32;1m===========================================\033[0m" echo -e "\033[32;1mInstall Xcache......\033[0m" echo install_xcache echo -e "\033[32;1m===========================================\033[0m" echo -e "\033[32;1mJudge Whether Install phpmyadmin or not......\033[0m" echo judge_whether_create_phpmyadmin
本文出自 “清枫拂面” 博客,请务必保留此出处http://crazy123.blog.51cto.com/1029610/1689323
原文地址:http://crazy123.blog.51cto.com/1029610/1689323