首页 > 代码库 > 脚本一键源码编译安装LNMP
脚本一键源码编译安装LNMP
script]# cat LNMP.sh
#!/bin/bash
echo "Compile environment installation"
source $1
envinstall() {
cd /opt
echo "--------Compile environment install Starting--------"
yum -y groupinstall "Development Tools" "Server Platform Development"
yum -y install pcre-devel openssl-devel zlib-devel cmake ncurses-devel libxml2-devel bzip2-devel wget
wget ftp://mcrypt.hellug.gr/pub/crypto/mcrypt/libmcrypt/libmcrypt-2.5.7.tar.gz
tar -xf libmcrypt-2.5.7.tar.gz
cd libmcrypt-2.5.7
./configure
make && make install
}
nginxinstall() {
id nginx &>/dev/null
if [ $? -gt 0 ];then
useradd -r -M nginx
fi
cd /opt
echo "--------Nginx Start install--------"
wget http://nginx.org/download/nginx-1.6.1.tar.gz
tar -xf nginx-1.6.1.tar.gz
cd nginx-1.6.1
./configure --prefix=$nginx_dir --conf-path=/etc/nginx/nginx.conf --user=nginx --group=nginx --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 --with-http_ssl_module --with-http_stub_status_module --with-http_gzip_static_module --with-debug make && make install
cp $package/nginx.start /etc/rc.d/init.d/nginx
chmod +x /etc/rc.d/init.d/nginx
chkconfig --add nginx
chkconfig nginx on
echo "export PATH=$nginx_dir/sbin:$PATH">/etc/profile.d/nginx
source /etc/profile.d/nginx
mv /etc/nginx/nginx.conf{,.bak}
cp -f $package/nginx.conf /etc/nginx/nginx.conf
}
mysqlinstall() {
id mysql &>/dev/null
if [ $? -gt 0 ];then
groupadd mysql
useradd -s /sbin/nologin -g mysql -M mysql
fi
if [ ! -d $mydata_dir ];then
mkdir -p $mydata_dir
fi
cd /opt
echo "--------Mysql Start install--------"
cp $package/mariadb-10.0.13.tar.gz /opt
tar -xf mariadb-10.0.13.tar.gz
cd mariadb-10.0.13
cmake . -DCMAKE_INSTALL_PREFIX=$mysql_dir -DMYSQL_DATADIR=$mydat
a_dir -DSYSCONFDIR=/etc -DWITH_INNOBASE_STORAGE_ENGINE=1 -DWITH_ARCHIVE_STORAGE_ENGINE=1 -DWITH_BLACKHOLE_STORAG
E_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 cd $mysql_dir
scripts/mysql_install_db --user=mysql --datadir=$mydata_dir
cp support-files/mysql.server /etc/init.d/mysqld
chkconfig --add mysqld
chkconfig mysqld on
#cp $package/nginx.start /etc/rc.d/init.d/nginx
chmod +x /etc/rc.d/init.d/nginx
echo "export PATH=$mysql_dir/bin:$PATH">/etc/profile.d/mysql
source /etc/profile.d/mysql
ln -sv /usr/local/mysql/include/ /usr/local/include/mysql
echo "/usr/local/mysql/lib">/etc/ld.so.conf.d/mysql.conf
ldconfig -v
mv /etc/my.cnf{,.bak}
cp -f $package/my.cnf /etc/my.cnf
service mysqld start
mysqladmin -u root -p password "oracleadmin"
}
phpinstall() {
cd /opt
echo "--------php Start install--------"
cp $package/php-5.4.26.tar.bz2 /opt
tar -xf php-5.4.26.tar.bz2
cd php-5.4.26
./configure --prefix=$php_dir --with-mysql=mysqlnd --with-openss
l --with-mysqli=mysqlnd --enable-mbstring --with-freetype-dir --with-jpeg-dir --with-png-dir --with-zlib --with-l
ibxml-dir=/usr --enable-xml --enable-sockets --enable-fpm --with-mcrypt --with-config-file-path=/etc --with-config-file-scan-dir=/etc/php.d --with-bz2 make && make install cp php.ini-production /etc/php.ini
cp $php_dir/etc/php-fpm.conf.default $php_dir/etc/php-fpm.conf
cp /root/php-5.4.26/sapi/fpm/init.d.php-fpm /etc/rc.d/init.d/php
-fpm chmod +x /etc/rc.d/init.d/php-fpm
chkconfig --add php-fpm
chkconfig php-fpm on
#cp $package/nginx.start /etc/rc.d/init.d/nginx
echo "export PATH=$php_dir/bin:$PATH">/etc/profile.d/php
source /etc/profile.d/php
cat>/usr/local/php5/etc/php-fpm.conf <<EOF
pid = /usr/local/php5/var/run/php-fpm.pid
EOF
}
envinstall
if [ $? -eq 0 ];then
echo "Compile environment install is finished Sucess!"
else
echo "Compile enviroment install Failed!"
exit 1
fi
nginxinstall
service nginx start
if [$? -eq 0 ];then
echo "nginx install is finished Sucess!"
else
echo "nginx install Failed!"
exit 1
fi
mysqlinstall
service mysqld start
if [ $? -eq 0 ];then
echo "mysql install is finished Sucess!"
else
echo "mysql install Failed!"
exit 1
fi
phpinstall
service php-fpm start
if [ $? -eq 0 ];then
echo "php install is finished Sucess!"
else
echo "php install Failed!"
exit 1
fi
[root@localhost script]# ls
dir.conf LNMP.sh package dir.conf为参数文件 package为资源文件和配置文件
[root@localhost script]# cat dir.conf
package=/root/script/package
nginx_dir=/usr/local/nginx
mysql_dir=/usr/local/mysql
mydata_dir=/data/mydata
php_dir=/usr/local/php5
[root@localhost script]# ls -l package/
总用量 62920
-rw-r--r-- 1 root root 51333762 2月 9 12:30 mariadb-10.0.13.tar.gz
-rw-r--r-- 1 root root 239 2月 9 14:06 my.cnf
-rw-r--r-- 1 root root 803301 2月 9 12:30 nginx-1.6.1.tar.gz
-rw-r--r-- 1 root root 2584 2月 9 13:53 nginx.conf
-rw-r--r-- 1 root root 2818 2月 9 10:41 nginx.start
-rw-r--r-- 1 root root 2818 2月 9 10:41 nginx.start.bak
-rw-r--r-- 1 root root 12270535 2月 9 12:30 php-5.4.26.tar.bz2
本文出自 “Open World” 博客,请务必保留此出处http://voidyao000.blog.51cto.com/12458042/1896430
脚本一键源码编译安装LNMP