LAMP&LNMP Automated Installation script code _linux

Source: Internet
Author: User
Tags bz2 curl fpm install php mcrypt openssl php and mysql zts

Introduction to the Scripting environment
Ii. Introduction to the script
Introduction to the function of the script


Introduction to the Scripting environment

This script runs on the Rhel 6.4 version
To run this script you need to note:
1, the host needs to be able to access the Internet, because the blogger is built Sohu external network yum Source, this Yum source consists of two parts, one is the CD inside all software packages, one is Epel source.
2, need to understand the mutual dependence between software.


Ii. Introduction to the script

A script is made up of functions, and each function implements a function

Copy Code code as follows:

function Create_yum #此函数是搭建sohu的yum仓库
function Download #此函数是下载全部所需的软件包
function Install_apache #此函数是安装apache软件包
function Config_apache #此函数是修改apache的服务脚本和开启
Apache Service
function Install_nginx #此函数是安装nginx软件包
function Install_mysql #此函数是安装mysql软件包
function Config_mysql #此函数是初始化mysql和开启mysql的服务
function install_php #此函数是安装php软件包
function config_php #此函数提供php的配置文件
function INSTALL_PHP_FPM #此函数是安装php-FPM package provides fastcgi services
function config_php_fpm #此函数是修改php-fpm config file box open
PHP-FPM's Services
function Install_xcache #此函数是安装为php代码加速的软件包
function Install_memcache #此函数是安装连接memcached的软件包
function Install_memcached #此函数是安装memcached软件包
function Install_lamp #此函数里面只包含了apache, mysql,php functions
function Config_lamp
function Install_lammp #此函数里面只包含了apache, MySQL,
Functions of memcached,php
function config_lammp
function Install_lnmp #此函数里面只包含了nginx, mysql,php functions
function Config_lnmp
function Install_lnmmp #此函数里面只包含了nginx, MySQL,
Functions of memcached,php
function config_lnmmp

If you believe that the path of the configuration file to store the data path and the results of your friends request, then please all Bo friends only a small change

Introduction to the function of the script

1, support a machine to install a single software, such as Apache, Nginx, MySQL, php-fpm,memcached
2), support a machine directly install lamp, LNMP, LAMMP, LNMMP architecture
3, if you want to install a lamp (LNMP) architecture, please note the Order of installation: Apache (nginx)-->
mysql-->php
4, PHP and PHP-FPM are actually installed PHP source software package, but provide a different function
If your Apache is installed on a different machine with PHP, then the PHP host is installed with the
PHP-FPM;
If your PHP and MySQL are installed on different machines, then the PHP host is also installed
PHP-FPM;
PHP-FPM and memcached are installed on different machines, then the PHP-FPM host must have Memcache installed to connect to memcached.
5, after the installation of each script, the source package will be generated files and systems can identify the header file, library files, binary
6), will provide system V script files for the service
7, will be on their own to open the service, and add to the boot automatically launched the list of services


Entire script

Copy Code code as follows:

#!/bin/bash
#discripte: frist,you Linux server must be surf Internet because we-use Http://mirrors.sohu.com/yum source and Epel Sourc E
function Create_yum {
dir=/etc/yum.repos.d/
MV $dir/*.repo/tmp
Cat >> $dir/sohu.repo <<eof
[CentOS]
Name=sohu-centos
Baseurl=http://mirrors.sohu.com/centos/\ $releasever/os/\ $basearch
Gpgcheck=1
Enable=0
Gpgkey=http://mirrors.sohu.com/centos/rpm-gpg-key-centos-6
[Epel]
Name=sohu-epel
baseurl=http://mirrors.sohu.com/fedora-epel/\ $releasever/\ $basearch/
Enable=1
Gpgcheck=0
Eof
Yum Clean all &>/dev/null
}
function Download {
Yum-y Install wget
Cd/root
Echo-e "\033[32m=========download about Web server source package==========\033[0m"
wget http://mirror.esocc.com/apache/apr/apr-1.4.6.tar.bz2
wget http://mirror.esocc.com/apache/apr/apr-util-1.5.2.tar.bz2
wget http://mirror.esocc.com/apache/httpd/httpd-2.4.6.tar.bz2
wget http://nginx.org/download/nginx-1.4.2.tar.gz
Echo-e "\033[32m=========download about PHP or php-fpm soure package========\033[0m"
wget http://xcache.lighttpd.net/pub/Releases/3.0.3/xcache-3.0.3.tar.bz2
wget http://pecl.php.net/get/memcache-2.2.7.tgz
wget http://downloads.php.net/stas/php-5.4.19.tar.bz2
Echo-e "\033[32m======download about memcached source package========\033[0m"
wget http://nchc.dl.sourceforge.net/project/levent/libevent/libevent-2.0/libevent-2.0.21-stable.tar.gz
wget http://memcached.googlecode.com/files/memcached-1.4.15.tar.gz
Echo-e "\033[32m======download about MySQL source package=========\033[0m"
wget http://mysql.llarian.net/Downloads/MySQL-5.5/mysql-5.5.33.tar.gz
}
function Install_apache {
Cd/root
Yum-y Install Pcre-devel
Tar XF apr-1.4.6.tar.bz2
Tar XF apr-util-1.5.2.tar.bz2
Tar XF httpd-2.4.6.tar.bz2
cd/root/apr-1.4.6
./configure--prefix=/usr/local/apr && make && make install
Echo-e "\033[32M=========APR is ok========\033[0m"
cd/root/apr-util-1.5.2
./configure--prefix=/usr/local/apr-util--with-apr=/usr/local/apr && make && make install
Echo-e "\033[32m=========apr-util is ok========\033[0m"
cd/root/httpd-2.4.6
./configure--prefix=/usr/local/apache--enable-so--enable-ssl--enable-cgi--enable-rewrite--with-zlib \
--with-pcre--with-apr=/usr/local/apr--with-apr-util=/usr/local/apr-util--enable-modules=most \
--enable-mpms-shared=all--with-mpm=event && make && make install
Echo-e "\033[32M=========HTTPD is ok========\033[0m"
}
function Config_apache {
ECHO-E "\033[32m frist,associated system path \033[0m"
echo "path=/usr/local/apache/bin/: $PATH" >/etc/profile.d/httpd.sh
source/etc/profile.d/httpd.sh
ln-sv/usr/local/apache/include//usr/include/httpd
Echo-e "\033[32m second,modify configuration files and provided SYSTEMV scripts"
ip= ' Ifconfig | grep "inet addr" | Grep-v "127.0.0.1" | Awk-f: ' {print $} ' | Cut-d '-f1 '
Cp/root/httpd-2.4.6/build/rpm/httpd.init/etc/rc.d/init.d/httpd
Sed-i '/httpd/s/usr\/sbin\/httpd/usr\/local\/apache\/bin\/httpd/g '/etc/rc.d/init.d/httpd
Sed-i '/^httpd/a\prog=httpd '/etc/rc.d/init.d/httpd
Sed-i '/^pidfile/s/var\/run/usr\/local\/apache\/logs/g '/etc/rc.d/init.d/httpd
Sed-i ' s/etc\/httpd\/conf\/httpd.conf/usr\/local\/apache\/conf\/httpd.conf/g '/etc/rc.d/init.d/httpd
Sed-i ' $a ServerName ' $IP ':/usr/local/apache/conf/httpd.conf
Chkconfig--add httpd
Chkconfig--level httpd on
Service httpd Start
}
function Install_nginx {
Cd/root
Yum-y Install Pcre-devel
Tar XF nginx-1.4.2.tar.gz
Groupadd Nginx
Useradd-r-G Nginx nginx
cd/root/nginx-1.4.2
./configure \
--PREFIX=/USR \
--sbin-path=/usr/sbin/nginx \
--conf-path=/etc/nginx/nginx.conf \
--error-log-path=/var/log/nginx/error.log \
--http-log-path=/var/log/nginx/access.log \
--pid-path=/var/run/nginx/nginx.pid \
--lock-path=/var/lock/nginx.lock \
--user=nginx \
--group=nginx \
--with-http_ssl_module \
--with-http_flv_module \
--with-http_stub_status_module \
--with-http_gzip_static_module \
--http-client-body-temp-path=/var/tmp/nginx/client/\
--http-proxy-temp-path=/var/tmp/nginx/proxy/\
--http-fastcgi-temp-path=/var/tmp/nginx/fcgi/\
--HTTP-UWSGI-TEMP-PATH=/VAR/TMP/NGINX/UWSGI \
--HTTP-SCGI-TEMP-PATH=/VAR/TMP/NGINX/SCGI \
--with-pcre && make && make install
Echo-e "\033[32m=========nginx is ok========\033[0m"
}
function Install_mysql {
Cd/root
Yum-y Install CMake Bison
Useradd-r MySQL
Tar XF mysql-5.5.33.tar.gz
cd/root/mysql-5.5.33
CMake. -DCMAKE_INSTALL_PREFIX=/USR/LOCAL/MYSQL-DMYSQL_DATADIR=/MYDATA/DATA-DSYSCONFDIR=/ETC \
-dwith_innobase_storage_engine=1-dwith_archive_storage_engine=1-dwith_blackhole_storage_engine=1 \
-dwith_readline=1-dwith_ssl=system-dwith_zlib=system-dwith_libwrap=0-dmysql_unix_addr=/tmp/mysql.sock \
-ddefault_charset=utf8-ddefault_collation=utf8_general_ci
Make && make install
Echo-e "\033[32m=========mysqld is ok========\033[0m"
}
function Config_mysql {
ECHO-E "\033[32m frist,associated system Path,and initialization Database \033[0m"
Cp/usr/local/mysql/support-files/my-large.cnf/etc/my.cnf
Cp/usr/local/mysql/support-files/mysql.server/etc/rc.d/init.d/mysqld
Chown-r root.mysql/usr/local/mysql/
Mkdir-pv/mydata/data
Chown-r mysql:mysql/mydata/data/
Sed-i '/thread_concurrency/a\ datadir =/mydata/data '/etc/my.cnf
Sed-i '/datadir/a\ innodb_file_per_table = 1 '/etc/my.cnf
/usr/local/mysql/scripts/mysql_install_db--user=mysql--datadir=/mydata/data/--basedir=/usr/local/mysql
Service mysqld Start
echo "Path=/usr/local/mysql/bin: $PATH" >/etc/profile.d/mysqld.sh
source/etc/profile.d/mysqld.sh
echo "/usr/local/mysql/lib" >/etc/ld.so.conf.d/mysqld.conf
Ldconfig-v | grep MySQL
ln-sv/usr/local/mysql/include//usr/include/mysqld
Chkconfig--add mysqld
Chkconfig--level mysqld on
}
function install_php {
Yum-y Install libxml2-devel bzip2-devel curl-devel libmcrypt-devel
Tar XF php-5.4.19.tar.bz2
cd/root/php-5.4.19
./configure--prefix=/usr/local/php--with-mysql=/usr/local/mysql--with-openssl--with-mysqli=/usr/local/mysql/ Bin/mysql_config \
--enable-mbstring--with-freetype-dir--with-jpeg-dir--with-png-dir--with-zlib--with-libxml-dir=/usr \
--enable-xml--enable-sockets--with-apxs2=/usr/local/apache/bin/apxs--with-mcrypt--with-curl \
--with-config-file-path=/etc--WITH-CONFIG-FILE-SCAN-DIR=/ETC/PHP.D--with-bz2--enable-maintainer-zts
Make && make install
Echo-e "\033[32m=========php is ok========\033[0m"
}
function config_php {
Cp/root/php-5.4.19/php.ini-production/etc/php.ini
}
function INSTALL_PHP_FPM {
Yum-y Install libxml2-devel bzip2-devel curl-devel libmcrypt-devel
Tar XF php-5.4.19.tar.bz2
cd/root/php-5.4.19
./configure--prefix=/usr/local/php--with-mysql=mysqlnd--with-pdo-mysql=mysqlnd--with-mysqli=mysqlnd \
--with-openssl--enable-sockets--enable-sysvshm--enable-mbstring--with-freetype-dir--with-jpeg-dir-- With-png-dir \
--with-zlib-dir--with-libxml-dir=/usr--enable-xml--with-mhash--with-mcrypt--with-config-file-path=/etc \
--WITH-CONFIG-FILE-SCAN-DIR=/ETC/PHP.D--with-bz2--with-curl--enable-maintainer-zts--enable-fpm && make && make Install
Echo-e "\033[32M=========PHP-FPM is ok========\033[0m"
}
function CONFIG_PHP_FPM {
ECHO-E "\033[32m frist,associated system path \033[0m"
Ip2= ' Ifconfig | grep "inet addr" | Grep-v "127.0.0.1" | Awk-f: ' {print $} ' | Cut-d '-f1 '
Cp/root/php-5.4.19/php.ini-production/etc/php.ini
echo "Path=/usr/local/php/bin:/usr/local/php/sbin: $PATH" >/etc/profile.d/php-fpm.sh
source/etc/profile.d/php-fpm.sh
Echo-e "\033[32m second,modify configuration files and provided SYSTEMV scripts"
Mv/usr/local/php/etc/php-fpm.conf.default/usr/local/php/etc/php-fpm.conf
Sed-i ' S/127\.0\.0\.1/' $IP 2 '/g '/usr/local/php/etc/php-fpm.conf
cp/root/php-5.4.19/sapi/fpm/init.d.php-fpm/etc/rc.d/init.d/php-fpm
chmod +x/etc/rc.d/init.d/php-fpm
Service PHP-FPM Start
Chkconfig--add PHP-FPM
Chkconfig--level php-fpm on
}
function Install_xcache {
Cd/root
Tar XF xcache-3.0.3.tar.bz2
if [-d/usr/local/php];then
cd/root/xcache-3.0.3
/usr/local/php/bin/phpize
./configure--enable-xcache--with-php-config=/usr/local/php/bin/php-config
Make && make install
Else
install_php_fpm
cd/root/xcache-3.0.3
/usr/local/php/bin/phpize
./configure--enable-xcache--with-php-config=/usr/local/php/bin/php-config
Make && make install
Echo-e "\033[32m=========xcache is ok========\033[0m"
Fi
}
function Install_memcache {
Cd/root
Tar XF memcache-2.2.7.tgz
if [-d/usr/local/php];then
cd/root/memcache-2.2.7
/usr/local/php/bin/phpize
./configure--with-php-config=/usr/local/php/bin/php-config--enable-memcache && make && make install
Else
install_php_fpm
cd/root/memcache-2.2.7
/usr/local/php/bin/phpize
./configure--with-php-config=/usr/local/php/bin/php-config--enable-memcache && make && make install
Echo-e "\033[32m=========memcache is ok========\033[0m"
Fi
}
function install_memcached {
Cd/root
Tar XF libevent-2.0.21-stable.tar.gz
Tar XF memcached-1.4.15.tar.gz
Cd/root/libevent-2.0.21-stable
./configure--prefix=/usr/local/libevent && make && make install
Echo-e "\033[32m=========libevent is ok========\033[0m"
cd/usr/local/libevent/
echo "/usr/local/libevent/lib" >/etc/ld.so.conf.d/libevent.conf
Ldconfig-v | grep libevent
ln-sv/usr/local/libevent//usr/include/libevent
cd/root/memcached-1.4.15
./configure--prefix=/usr/local/memcached--with-libevent=/usr/local/libevent/
Make && make install
Echo-e "\033[32m=========memcached is ok========\033[0m"
}
function Install_lamp {
Install_apache
Install_mysql
install_php
Install_xcache
}
function Config_lamp {
Config_apache
Config_mysql
config_php
}
function Install_lnmp {
Install_nginx
Install_mysql
install_php
Install_xcache
}
function Config_lnmp {
Config_mysql
config_php
}
function INSTALL_LAMMP {
Install_apache
Install_mysql
install_php
Install_xcache
Install_memcache
Install_memcached
}
function CONFIG_LAMMP {
Config_apache
Config_mysql
config_php
config_php_fpm
}
function INSTALL_LNMMP {
Install_nginx
Install_mysql
install_php
Install_xcache
Install_memcache
Install_memcached
}
function CONFIG_LNMMP {
Config_mysql
config_php
config_php_fpm
}
Echo-e "\033[32m====make sure Yum is ok=========\033[0m"
#create_yum
Echo-e "\033[32m====now,download all package====\033[0m"
#download
ECHO-E "\033[32m====install Development packages====\033[0m"
#yum-y Groupinstall "Development tools" "Server Platform Development"
Echo-e "\033[32m=========you can choice you need install package==========\033[0m"
Cat <<eof
apache| A) Install Apache source package.
Nginx| N) Install Nginx source package.
mysql| M) install MySQL source package.
php| P) Install PHP source package.
php-fpm| PF) Install PHP-FPM source package.
xcache| X) Install Xcahe source package.
memcache| ME) Install Memcache source package.
memcached| MD) Install memcached source package.
Lamp) Install lamp source package.
LAMMP) Install LAMMP source package.
LNMP) Install LNMP source package.
LNMMP) Install LNMMP source package.
q| Q) quit
Eof
Read-p "Please choose to install:" Choice
Echo-e "\033[32m=====start Install $Choice ====\033[0m"
until [$Choice = = Q-o $Choice = = Q];d o
Case $Choice in
apache| A
Install_apache
Config_apache;;
Nginx| N
Install_nginx;;
mysql| M
Install_mysql
Config_mysql;;
php| P
install_php
config_php;;
php-fpm| PF)
install_php_fpm
CONFIG_PHP_FPM;;
xcache| X
Install_xcache;;
memcache| ME)
Install_memcache;;
memcached| MD)
install_memcached;;
Lamp
Install_lamp
Config_lamp;;
LAMMP)
Install_lammp
CONFIG_LAMMP;;
LNMP)
Install_lnmp
CONFIG_LNMP;;
LNMMP)
Install_lnmmp
CONFIG_LNMMP;;
q| Q)
Break
Esac
Read-p "Have any choice agin, if you no,q| Q is quit: "Choice
Done

This script and Nginx systemv,memcached System V scripts are transmitted in the form of attachments, click here to download

Defects:

1), failed to provide Nginx automation System V script, but Nginx System V script I will upload the attachment, you need vim/etc/rc.d/init.d/nginx and then copy I provided the System V script and then add permissions , you'll be able to service Nginx start.
2), also failed to provide memcached automation System V script, but the memcached System V script will be uploaded as an attachment, you need vim/etc/rc.d/init.d/memcached bo Friends And then copy the System V script I provided and then add the permissions to the service memcached start

This article originates from the "Technology Road---Jie" blog

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.