lnmp安装脚本

setenforce 0
iptables -F
LNMP_HOME=/usr/local/src
cd $LNMP_HOME
cat >> /tmp/lnmp.txt << END
http://nginx.org/download/nginx-1.6.2.tar.gz
http://cn2.php.net/distributions/php-5.6.3.tar.gz
http://ring.u-toyama.ac.jp/archives/graphics/freetype/freetype2/freetype-2.5.4.tar.gz
http://www.ijg.org/files/jpegsrc.v9a.tar.gz
END
wget -i /tmp/lnmp.txt
rm -rf /tmp/lnmp.txt
wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-6.repo
wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-6.repo
yum clean all
yum makecache
yum install -y apr* autoconf automake bison bzip2 bzip2* cloog-ppl compat* cpp curl curl-devel fontconfig fontconfig-devel freetype freetype* freetype-devel gcc gcc-c++ gtk+-devel gd gettext gettext-devel glibc kernel kernel-headers keyutils keyutils-libs-devel krb5-devel libcom_err-devel libpng libpng* libpng-devel libjpeg* libsepol-devel libselinux-devel libstdc++-devel libtool* libgomp libxml2 libxml2-devel libXpm* libX* libtiff libtiff* make mpfr ncurses* ntp openssl nasm nasm* openssl-devel patch pcre-devel perl php-common php-gd policycoreutils ppl telnet t1lib t1lib* wget zlib-devel
yum install -y pcre pcre-devel openssl openssl-devel zlib zlib-devel cmake cmake-devel yasm yasm-devel t1lib t1lib-devel libmcrypt libmcrypt-devel gd gd-devel libvpx libvpx-devel tiff tiff-devel libpng libpng-devel freetype freetype-devel jpegsrc jpegsrc-devel net-snmp net-snmp-devel libjpeg-devel freetype-devel libpng-devel
if [ `uname -m` == "x86_64" ];then
machine=x86_64
else
machine=i686
fi
mysqlBasedir=/usr/local/mysql
mysqlDatadir=${mysqlBasedir}/data/
mysqlLogdir=${mysqlBasedir}/logs
mysqlUser=mysql
mysqlGroup=mysql
mkdir -p $mysqlBasedir
mkdir -p $mysqlDatadir
mkdir -p $mysqlLogdir
cd /usr/local/src
if [ $machine == "x86_64" ];then
  rm -rf mysql-5.6.15-linux-glibc2.5-x86_64
  if [ ! -f mysql-5.6.15-linux-glibc2.5-x86_64.tar.gz ];then
     wget http://oss.aliyuncs.com/aliyunecs/onekey/mysql/mysql-5.6.15-linux-glibc2.5-x86_64.tar.gz
  fi
  /etc/init.d/mysqld stop
  rm -rf $mysqlBasedir/*
  mkdir -p $mysqlLogdir
  tar -xzvf mysql-5.6.15-linux-glibc2.5-x86_64.tar.gz
  mv /usr/local/src/mysql-5.6.15-linux-glibc2.5-x86_64/* $mysqlBasedir
else
  rm -rf mysql-5.6.15-linux-glibc2.5-i686
  if [ ! -f mysql-5.6.15-linux-glibc2.5-i686.tar.gz ];then
  wget http://oss.aliyuncs.com/aliyunecs/onekey/mysql/mysql-5.6.15-linux-glibc2.5-i686.tar.gz
  fi
  tar -xzvf mysql-5.6.15-linux-glibc2.5-i686.tar.gz
  mv /usr/local/src/mysql-5.6.15-linux-glibc2.5-i686/* $mysqlBasedir
fi
#cp -a  /usr/local/src/mysql-5.6.15-linux-glibc2.5-x86_64/* $mysqlBasedir

groupadd $mysqlGroup
useradd -g $mysqlGroup -s /sbin/nologin $mysqlUser
${mysqlBasedir}/scripts/mysql_install_db --datadir=$mysqlDatadir --basedir=$mysqlBasedir --user=$mysqlUser
chown -R ${mysqlUser}:${mysqlGroup} $mysqlBasedir
chown -R ${mysqlUser}:${mysqlGroup} $mysqlDatadir
chown -R ${mysqlUser}:${mysqlGroup} $mysqlLogdir
cp -f ${mysqlBasedir}/support-files/mysql.server /etc/init.d/mysqld
sed -i 's#^basedir=$#basedir='${mysqlBasedir}'#' /etc/init.d/mysqld
sed -i 's#^datadir=$#datadir='${mysqlDatadir}'#' /etc/init.d/mysqld
cat > /etc/my.cnf <<END
[client]
port = 3306
socket = /tmp/mysql.sock
default-character-set = utf8mb4
[mysql]
prompt="MySQL [\d]> "
no-auto-rehash
[mysqld]
port = 3306
socket = /tmp/mysql.sock
basedir = /usr/local/mysql
datadir = /usr/local/mysql/data
pid-file = /usr/local/mysql/mysql.pid
user = mysql
bind-address = 0.0.0.0
server-id = 1
init-connect = 'SET NAMES utf8mb4'
character-set-server = utf8mb4
skip-name-resolve
#skip-networking
back_log = 300
max_connections = 3936
max_connect_errors = 6000
open_files_limit = 65535
table_open_cache = 1024
max_allowed_packet = 500M
binlog_cache_size = 1M
max_heap_table_size = 8M
tmp_table_size = 128M
read_buffer_size = 2M
read_rnd_buffer_size = 8M
sort_buffer_size = 8M
join_buffer_size = 8M
key_buffer_size = 256M
thread_cache_size = 64
query_cache_type = 1
query_cache_size = 64M
query_cache_limit = 2M
ft_min_word_len = 4
log_bin = mysql-bin
binlog_format = mixed
expire_logs_days = 7
log_error = /usr/local/mysql/logs/mysql-error.log
slow_query_log = 1
long_query_time = 1
slow_query_log_file = /usr/local/mysql/logs/mysql-slow.log
performance_schema = 0
explicit_defaults_for_timestamp
#lower_case_table_names = 1
skip-external-locking
default_storage_engine = InnoDB
innodb_file_per_table = 1
innodb_open_files = 500
innodb_buffer_pool_size = 1024M
innodb_write_io_threads = 4
innodb_read_io_threads = 4
innodb_thread_concurrency = 0
innodb_purge_threads = 1
innodb_flush_log_at_trx_commit = 2
innodb_log_buffer_size = 2M
innodb_log_file_size = 32M
innodb_log_files_in_group = 3
innodb_max_dirty_pages_pct = 90
innodb_lock_wait_timeout = 120
bulk_insert_buffer_size = 8M
myisam_sort_buffer_size = 64M
myisam_max_sort_file_size = 10G
myisam_repair_threads = 1
interactive_timeout = 28800
wait_timeout = 28800
[mysqldump]
quick
max_allowed_packet = 500M
[myisamchk]
key_buffer_size = 256M
sort_buffer_size = 8M
read_buffer = 4M
write_buffer = 4M
END
chmod 755 /etc/init.d/mysqld
sed -i 's#bin#bin:/usr/local/mysql/bin#g' ~/.bash_profile
/etc/init.d/mysqld start
cd $LNMP_HOME
tar zxvf nginx-1.6.2.tar.gz
cd nginx-1.6.2
./configure --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module --with-http_gzip_static_module  --with-pcre
make
make install
/usr/local/nginx/sbin/nginx
cat > /etc/init.d/nginx <<END
. /etc/rc.d/init.d/functions
. /etc/sysconfig/network
[ "\$NETWORKING" = "no" ] && exit 0
nginx="/usr/local/nginx/sbin/nginx"
prog=\$(basename \$nginx)
NGINX_CONF_FILE="/usr/local/nginx/conf/nginx.conf"
[ -f /etc/sysconfig/nginx ] && . /etc/sysconfig/nginx
lockfile=/var/lock/nginx.lock
start() {
        [ -x \$nginx ] || exit 5
        [ -f \$NGINX_CONF_FILE ] || exit 6
        echo -n $"Starting \$prog: "
        daemon \$nginx -c \$NGINX_CONF_FILE
        retval=\$?
        echo
        [ \$retval -eq 0 ] && touch \$lockfile
        return \$retval
}
stop() {
        echo -n $"Stopping \$prog: "
        killproc \$prog -QUIT
        retval=\$?
        echo
        [ \$retval -eq 0 ] && rm -f \$lockfile
        return \$retval
}
restart() {
        configtest || return \$?
        stop
        sleep 1
        start
}
reload() {
        configtest || return \$?
        echo -n $"Reloading \$prog: "
        killproc \$nginx -HUP
        RETVAL=\$?
        echo
}
force_reload() {
        restart
}
configtest() {
  \$nginx -t -c \$NGINX_CONF_FILE
}
rh_status() {
        status \$prog
}
rh_status_q() {
        rh_status >/dev/null 2>&1
}
case "\$1" in
        start)
                rh_status_q && exit 0
                \$1
                ;;
        stop)
                rh_status_q || exit 0
               \$1
                ;;
        restart|configtest)
                \$1
                ;;
        reload)
                rh_status_q || exit 7
                \$1
                ;;
        force-reload)
                force_reload
                ;;
        status)
                rh_status
                ;;
        condrestart|try-restart)
                rh_status_q || exit 0
                        ;;
        *)
                echo $"Usage: \$0 {start|stop|status|restart|condrestart|try-restart|reload|force-reload|configtest}"
                exit 2
esac
END
chmod 775 /etc/rc.d/init.d/nginx
chkconfig nginx on
/etc/rc.d/init.d/nginx restart
cd $LNMP_HOME
tar zxvf jpegsrc.v9a.tar.gz
cd jpeg-9a
./configure --prefix=/usr/local/jpeg --enable-shared
make&&make install
cd $LNMP_HOME
tar zxvf freetype-2.5.4.tar.gz
cd freetype-2.5.4
./configure --prefix=/usr/local/freetype --enable-shared
make&&make install
cd $LNMP_HOME
tar -zvxf php-5.6.3.tar.gz
cd php-5.6.3
  ./configure --prefix=/usr/local/php --with-config-file-path=/usr/local/php/etc --with-mysql=/usr/local/mysql --with-mysqli=/usr/local/mysql/bin/mysql_config --with-mysql-sock=/tmp/mysql.sock --with-pdo-mysql=/usr/local/mysql --with-gd --with-png --with-jpeg-dir=/usr/local/jpeg --with-freetype-dir=/usr/local/freetype --with-xpm --with-vpx --with-zlib --with-t1libb --with-iconv --enable-libxml --enable-xml --enable-bcmath --enable-shmop --enable-sysvsem --enable-inline-optimization --enable-opcache --enable-mbregex --enable-fpm --enable-mbstring --enable-ftp --enable-gd-native-ttf --with-openssl --enable-pcntl --enable-sockets --with-xmlrpc --enable-zip --enable-soap --without-pear --with-gettext --enable-session --with-mcrypt --with-curl --enable-ctype
make&&make install
cp php.ini-production /usr/local/php/etc/php.ini
rm -rf /etc/php.ini
ln -s /usr/local/php/etc/php.ini /etc/php.ini
cp /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf

ln -s /usr/local/php/etc/php-fpm.conf /etc/php-fpm.conf

sed  -i 's/127.0.0.1:9000/\/tmp\/php-fpm.sock/g' /etc/php-fpm.conf

sed -i 's/\;listen.owner/listen.owner/g'  /etc/php-fpm.conf

sed -i 's/\;listen.group/listen.group/g'  /etc/php-fpm.conf

cp /usr/local/src/php-5.6.3/sapi/fpm/init.d.php-fpm /etc/rc.d/init.d/php-fpm
chmod +x /etc/rc.d/init.d/php-fpm
/etc/rc.d/init.d/php-fpm start

sed  -i '$d' /usr/local/nginx/conf/nginx.conf

sed  -i '$d' /usr/local/nginx/conf/nginx.conf

echo -e "include conf.d/*.conf;\n}" >> /usr/local/nginx/conf/nginx.conf
mkdir /usr/local/nginx/conf/conf.d
cat >> /usr/local/nginx/conf/conf.d/test.conf << END
   server {
        listen       800;
        server_name  localhost;
root /usr/local/nginx/html/;
index index.php index.html index.htm;
location ~ \.php$ {
fastcgi_pass /tmp/php-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME \$document_root\$fastcgi_script_name;
include fastcgi_params;
}
}
END
touch /usr/local/nginx/html/index.php
cat > /usr/local/nginx/html/index.php << END
<?php
phpinfo();
?>

END

参考资料

http://www.osyunwei.com/archives/8867.html

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值