Centos6.5系统Lnmp一键安装脚本
首先上传以下软件包到root目录下libmcrypt-2.5.8.tar.bz2
mysql-5.5.20.tar.gz
pcre-8.37.tar.bz2
php-5.6.13.tar.bz2
脚本信息:
#!/bin/bash
#auto by xiaohua
dbrootpwd="123456"
soft_path=/usr/local/src
nginx_ver="nginx-1.8.0"
nginx_path=/usr/local/nginx
php_path=/usr/local/php
mysql_path=/usr/local/mysql
function install_nginx {
clear
wget http://nginx.org/download/${nginx_ver}.tar.gz
yum install gcc gcc-c++ autoconf automake zlib zlib-devel openssl openssl-devel pcre-devel -y
useradd -M -u 8001 -s /sbin/nologinnginx
tar xf pcre-8.37.tar.bz2 -C $soft_path
tar xvf ${nginx_ver}.tar.gz -C $soft_path
cd $soft_path/$nginx_ver
./configure --prefix=$nginx_path \
--with-http_dav_module \
--with-http_stub_status_module \
--with-http_addition_module \
--with-http_sub_module\
--with-http_flv_module \
--with-http_spdy_module \
#--with-http_v2_module\
--with-http_mp4_module \
--with-http_ssl_module \
--with-pcre=$soft_path/pcre-8.37
make && make install
if [$? -ne 0 ]
then
echo "install nginx faild"
exit 1
fi
cat >$nginx_path/conf/nginx.conf<<EOF
usernginx nginx;
worker_processes auto;
error_log/date/wwwlogs/nginx_error.logcrit;
pid /usr/local/nginx/logs/nginx.pid;
#Specifies the value for maximum file descriptors that can be opened by this process.
worker_rlimit_nofile 51200;
events
{
use epoll;
worker_connections 51200;
multi_accept on;
}
http
{
include mime.types;
default_typeapplication/octet-stream;
server_names_hash_bucket_size 128;
client_header_buffer_size 32k;
large_client_header_buffers 4 32k;
client_max_body_size 50m;
#include blocksip.conf; #denyip
sendfile on;
tcp_nopush on;
keepalive_timeout 60;
tcp_nodelay on;
fastcgi_connect_timeout 300;
fastcgi_send_timeout 300;
fastcgi_read_timeout 300;
fastcgi_buffer_size 64k;
fastcgi_buffers 4 64k;
fastcgi_busy_buffers_size 128k;
fastcgi_temp_file_write_size 256k;
gzip on;
gzip_min_length1k;
gzip_buffers 4 16k;
gzip_http_version 1.1;
gzip_comp_level 2;
gzip_types text/plain application/javascript application/x-javascript text/javascript text/css application/xml application/xml+rss;
gzip_vary on;
gzip_proxied expired no-cache no-store private auth;
gzip_disable "MSIE \.";
#limit_conn_zone \$binary_remote_addr zone=perip:10m;
##If enable limit_conn_zone,add "limit_conn perip 10;" to server section.
server_tokens off;
access_log off;
server
{
listen 80 default_server;
#listen [::]:80 default_server ipv6only=on;
server_name www.xiaohua.top;
index index.php index.html index.html;
root/date/www;
#error_page 404 /404.html;
#include enable-php.conf;
location ~ \.php$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_indexindex.php;
fastcgi_paramSCRIPT_FILENAME\$document_root\$fastcgi_script_name;
include fastcgi.conf;
}
location /nginx_status
{
stub_status on;
access_log off;
}
location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
{
expires 30d;
}
location ~ .*\.(js|css)?$
{
expires 12h;
}
location ~ /\.
{
deny all;
}
access_logoff;
}
#include vhost/*.conf;
}
EOF
cat >/etc/init.d/nginx<<EOF
#!/bin/bash
# chkconfig: - 30 21
# description: http service.
# Source Function Library
. /etc/init.d/functions
# Nginx Settings
NGINX_SBIN="/usr/local/nginx/sbin/nginx"
NGINX_CONF="/usr/local/nginx/conf/nginx.conf"
NGINX_PID="/usr/local/nginx/logs/nginx.pid"
RETVAL=0
prog="Nginx"
start() {
echo -n $"Starting \$prog: "
mkdir -p /dev/shm/nginx_temp
daemon \$NGINX_SBIN -c \$NGINX_CONF
RETVAL=\$?
echo
return \$RETVAL
}
stop() {
echo -n $"Stopping \$prog: "
killproc -p \$NGINX_PID \$NGINX_SBIN -TERM
rm -rf /dev/shm/nginx_temp
RETVAL=\$?
echo
return \$RETVAL
}
reload(){
echo -n $"Reloading \$prog: "
killproc -p \$NGINX_PID \$NGINX_SBIN -HUP
RETVAL=\$?
echo
return \$RETVAL
}
restart(){
stop
start
}
configtest(){
\$NGINX_SBIN -c \$NGINX_CONF -t
return 0
}
case "\$1" in
start)
start
;;
stop)
stop
;;
reload)
reload
;;
restart)
restart
;;
configtest)
configtest
;;
*)
echo $"Usage: $0 {start|stop|reload|restart|configtest}"
RETVAL=1
esac
exit \$RETVAL
EOF
mkdir -p /date/wwwlogs/
touch /date/wwwlogs/nginx_error.log
mkdir -p /date/www
echo "you are install nginx successfull">/date/www/index.html
echo "<?php phpinfo();?>" >/date/www/index.php
chmod +x /etc/init.d/nginx
/etc/init.d/nginx restart
chkconfig nginx on
}
function install_mysql(){
clear
cd
yum install gcc-c++ cmake ncurses-devel -y
tar xf mysql-5.5.20.tar.gz -C $soft_path/
useradd -M -s /sbin/nologin mysql
cd $soft_path/mysql-5.5.20/
cmake -DCMAKE_INSTALL_PREFIX=$mysql_path \
-DMYSQL_UNIX_ADDR=/tmp/mysql.sock\
-DEXTRA_CHARSETS=gbk,gb2312,utf8,ascii \
-DDEFAULT_CHARSET=utf8\
-DDEFAULT_COLLATION=utf8_general_ci\
-DWITH_EXTRA_CHARSETS=all \
-DWITH_MYISAM_STORAGE_ENGINE=1\
-DWITH_INNOBASE_STORAGE_ENGINE=1\
-DWITH_MEMORY_STORAGE_ENGINE=1\
-DWITH_READLINE=1\
-DENABLED_LOCAL_INFILE=1\
-DMYSQL_DATADIR=$mysql_path/data\
-DMYSQL-USER=mysql
make && make install
if [$? -ne 0 ]
then
echo "install mysql faild"
exit 1
fi
chown -R mysql:mysql $mysql_path/
cat $mysql_path/support-files/my-small.cnf >/etc/my.cnf
cat $mysql_path/support-files/mysql.server >/etc/init.d/mysqld
sed -i '46,+1d' /etc/init.d/mysqld
sed -i '46ibasedir='$mysql_path'' /etc/init.d/mysqld
sed -i '47idatadir='$mysql_path/data'' /etc/init.d/mysqld
chmod +x /etc/init.d/mysqld
$mysql_path/scripts/mysql_install_db --defaults-file=/etc/my.cnf --basedir=$mysql_path --datadir=$mysql_path/data --user=mysql &
ln -s $mysql_path/bin/* /bin/
chkconfig mysqld on
service mysqld start
rm -rf $mysql_path/data/test/.empty
mysqladmin -u root password '123456'
$mysql_path/bin/mysql -e "grant all privileges on *.* to root@'127.0.0.1' identified by \"$dbrootpwd\" with grant option;"
$mysql_path/bin/mysql -e "grant all privileges on *.* to root@'localhost' identified by \"$dbrootpwd\" with grant option;"
$mysql_path/bin/mysql -uroot -p$dbrootpwd -e "delete from mysql.user where Password='';"
$mysql_path/bin/mysql -uroot -p$dbrootpwd -e "delete from mysql.db where User='';"
$mysql_path/bin/mysql -uroot -p$dbrootpwd -e "delete from mysql.proxies_priv where Host!='localhost';"
$mysql_path/bin/mysql -uroot -p$dbrootpwd -e "drop database test;"
$mysql_path/bin/mysql -uroot -p$dbrootpwd -e "flush privileges;"
#$mysql_path/bin/mysql -uroot -p$dbrootpwd -e "reset master;"
}
function install_libxml (){
cd
yum install -y libxml2-devel
tar xf libmcrypt-2.5.8.tar.bz2 -C $soft_path/
cd $soft_path/libmcrypt-2.5.8/
./configure --prefix=/usr/local/libmcrypt
make && make install
cd
echo "/usr/local/libmcrypt/lib" >> /etc/ld.so.conf
echo "$mysql_path/lib" >>/etc/ld.so.conf
ldconfig
echo "ldconfig">> /etc/rc.local
}
function install_php (){
clear
yum install -ylibcurl-devel libjpeg-devel libpng-devel freetype freetype-devel php-pear
cd
tar xf php-5.6.13.tar.bz2 -C $soft_path
cd $soft_path/php-5.6.13
./configure --prefix=$php_path \
--with-config-file-path=$php_path \
--with-mysql=$mysql_path \
--with-mysqli=$mysql_path/bin/mysql_config \
--with-iconv-dir \
--with-freetype-dir \
--with-jpeg-dir \
--with-png-dir \
--with-zlib \
--with-libxml-dir=/usr \
--enable-xml \
--disable-rpath \
--enable-bcmath \
--enable-shmop \
--enable-sysvsem \
--enable-inline-optimization \
--with-curl \
--enable-mbregex \
--enable-fpm \
--enable-mbstring \
--with-gd \
--enable-gd-native-ttf \
--with-openssl \
--with-mhash \
--enable-pcntl \
--enable-sockets \
--with-xmlrpc \
--enable-zip \
--enable-soap \
--with-gettext \
--with-mcrypt=/usr/local/libmcrypt
make && make install
if [$? -ne 0 ]
then
echo "install php faild"
exit 1
fi
cp $soft_path/php-5.6.13/php.ini-production /$php_path/php.ini
cp $php_path/etc/php-fpm.conf.default $php_path/etc/php-fpm.conf
sed -i '149,+1s/nobody/nginx/' $php_path/etc/php-fpm.conf
cp $soft_path/php-5.6.13/sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
chmod +x /etc/init.d/php-fpm
chkconfig php-fpm on
/etc/init.d/php-fpm start
}
install_nginx
install_mysql
install_libxml
install_php
echo "LNMP install successfull"
注:脚本中个模块都是根据实际生产环境写的,可用于实际生产环境。更多信息请点击www.tchua.top。
页:
[1]