nginx php mysql 一键_自己写的一键安装Nginx+Mysql+PHP脚本

长孙知
2023-12-01

function __install_mysql()

{

/usr/sbin/groupadd mysql

/usr/sbin/useradd -m mysql -g mysql -d /usr/local/mysql -s /sbin/nologin

cd $dir

wget $mysql_download

filename=`ls mysql*`

foldername=`echo $filename | sed 's/\.tar.gz//'`

tar zxvf $filename

cd $foldername

./configure  --prefix=/usr/local/mysql \

--localstatedir=/data/mysql \

--enable-static \

--with-client-ldflags=-all-static \

--with-mysqld-ldflags=-all-static \

--with-charset=utf8 \

--with-extra-charsets=all \

--with-berkeley-db \

--with-innodb \

--without-readline \

--enable-assembler \

--with-pthread \

--enable-thread-safe-client \

--without-debug \

--without-ndb-debug

make;make install

}

function __install_mysql_management()

{

mkdir -p /data/mysql

cd $dir

filename=`basename $mysql_download`

foldername=`echo $filename | sed 's/\.tar.gz//'`

cat > /etc/my.cnf << "EOF"

[client]

port            = 3306

socket          = /tmp/mysql.sock

[mysqld]

port            = 3306

socket          = /tmp/mysql.sock

skip-locking

skip-bdb

skip-name-resolve

#skip-innodb

max_allowed_packet = 8M

table_cache = 2048

sort_buffer_size = 2M

read_buffer_size = 2M

query_cache_limit = 2M

myisam_sort_buffer_size = 128M

thread_cache_size = 256

query_cache_size = 128M

thread_concurrency = 8

#log-bin=mysql-bin

#log-slow-queries=slowquery.log

#long_query_time = 60

default-character-set=utf8

max_user_connections=5000

max_connections=8000

wait_timeout=31536000

tmp_table_size = 384M

bulk_insert_buffer_size = 512M

concurrent_insert = 2

back_log = 512

[mysqldump]

quick

max_allowed_packet = 16M

[isamchk]

key_buffer = 512M

sort_buffer_size = 512M

read_buffer = 2M

write_buffer = 2M

[myisamchk]

key_buffer = 512M

sort_buffer_size = 512M

read_buffer = 2M

write_buffer = 2M

[mysqlhotcopy]

interactive-timeout

datadir=/data/mysql

[mysqld_safe]

open_files_limit = 65535

EOF

/usr/local/mysql/bin/mysql_install_db --user=mysql

chown -R mysql:mysql /data/mysql

/usr/local/mysql/bin/mysqld_safe --user=mysql &

cp "$foldername"/support-files/mysql.server /etc/rc.d/init.d/mysql

chmod +x /etc/rc.d/init.d/mysql

/sbin/chkconfig --add mysql

/sbin/chkconfig --level 35 mysql on

/sbin/service mysql start

/usr/local/mysql/bin/mysqladmin -u root password 'lihuipeng007@163.com'

ln -s /usr/local/mysql/bin/mysql /sbin/mysql

ln -s /usr/local/mysql/bin/mysqladmin /sbin/mysqladmin

ln -s /usr/local/mysql/bin/mysqldump /sbin/mysqldump

}

function __install_lib()

{

yum -y install gcc gcc-c++ bison patch unzip mlocate flex wget automake autoconf gd cpp gettext readline-devel libjpeg \

libjpeg-devel libpng libpng-devel freetype freetype-devel libxml2 libxml2-devel zlib zlib-devel glibc glibc-devel glib2 \

glib2-devel bzip2 bzip2-devel ncurses ncurses-devel curl curl-devel e2fsprogs e2fsprogs-devel libidn libidn-devel openldap \

openldap-devel openldap-clients openldap-servers nss_ldap expat-devel libtool libtool-ltdl-devel bison openssl openssl-devel

}

function __install_libiconv()

{

cd $dir

wget $libiconv_download

filename=`ls libiconv*`

foldername=`echo $filename | sed 's/\.tar\.gz//'`

tar zxvf $filename

cd $foldername

./configure

make;make install

}

function __install_libmcrypt()

{

cd $dir

wget $libmcrypt_download

filename=`ls libmcrypt*`

foldername=`echo $filename | sed 's/\.tar\.gz//'`

tar zxvf $filename

cd $foldername

./configure

make;make install

/sbin/ldconfig

cd libltdl

./configure --enable-ltdl-install

make;make install

ln -s /usr/local/lib/libmcrypt.la /usr/lib/libmcrypt.la

ln -s /usr/local/lib/libmcrypt.so /usr/lib/libmcrypt.so

ln -s /usr/local/lib/libmcrypt.so.4 /usr/lib/libmcrypt.so.4

ln -s /usr/local/lib/libmcrypt.so.4.4.8 /usr/lib/libmcrypt.so.4.4.8

ln -s /usr/local/bin/libmcrypt-config /usr/bin/libmcrypt-config

}

function __install_mhash()

{

cd $dir

wget $mhash_download

filename=`ls mhash*`

foldername=`echo $filename | sed 's/\.tar\.gz//'`

tar zxvf $filename

cd $foldername

./configure

make;make install

ln -s /usr/local/lib/libmhash.a /usr/lib/libmhash.a

ln -s /usr/local/lib/libmhash.la /usr/lib/libmhash.la

ln -s /usr/local/lib/libmhash.so /usr/lib/libmhash.so

ln -s /usr/local/lib/libmhash.so.2 /usr/lib/libmhash.so.2

ln -s /usr/local/lib/libmhash.so.2.0.1 /usr/lib/libmhash.so.2.0.1

}

function __install_mcrypt()

{

cd $dir

wget $mcrypt_download

filename=`ls mcrypt*`

foldername=`echo $filename | sed 's/\.tar\.gz//'`

tar zxvf  $filename

cd $foldername

/sbin/ldconfig

./configure

make;make install

}

function __install_php()

{

if [ `getconf LONG_BIT` == 64 ]

then

cp -rp /usr/lib64/libjpeg.* /usr/lib/

cp -rp /usr/lib64/libpng* /usr/lib/

cp -rp /usr/lib64/libldap* /usr/lib/

fi

cd $dir

wget $php_download

filename=`ls php*`

foldername=`echo $filename | sed 's/\.tar\.bz2//'`

tar jxvf $filename

rm -f $filename

wget $php_fpm_download

filename=`ls *diff.gz`

gzip -cd $filename | patch -d $foldername -p1

cd $foldername

./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-iconv-dir=/usr/local \

--with-freetype-dir \

--with-jpeg-dir \

--with-png-dir \

--with-zlib \

--with-libxml-dir=/usr \

--enable-xml \

--disable-rpath \

--enable-discard-path \

--enable-safe-mode \

--enable-bcmath \

--enable-shmop \

--enable-sysvsem \

--enable-inline-optimization \

--with-curl --with-curlwrappers \

--enable-mbregex \

--enable-fastcgi \

--enable-fpm \

--enable-force-cgi-redirect \

--enable-mbstring \

--with-mcrypt \

--with-gd \

--enable-gd-native-ttf \

--with-openssl \

--with-mhash \

--enable-pcntl \

--enable-sockets \

--with-ldap \

--with-ldap-sasl \

--with-xmlrpc \

--enable-zip \

--enable-soap

make ZEND_EXTRA_LIBS='-liconv'

make install

cp php.ini-dist /usr/local/php/etc/php.ini

sed -i 's@output_buffering = Off@output_buffering = On@' /usr/local/php/etc/php.ini

sed -i 's@; cgi.fix_pathinfo=0@cgi.fix_pathinfo=0@' /usr/local/php/etc/php.ini

rm -f /usr/local/php/etc/php-fpm.conf

cat > /usr/local/php/etc/php-fpm.conf << "EOF"

All relative paths in this config are relative to php's install prefix

Pid file

/usr/local/php/logs/php-fpm.pid

Error log file

/usr/local/php/logs/php-fpm.log

Log level

notice

When this amount of php processes exited with SIGSEGV or SIGBUS ...

10

... in a less than this interval of time, a graceful restart will be initiated.

Useful to work around accidental curruptions in accelerator's shared memory.

1m

Time limit on waiting child's reaction on signals from master

5s

Set to 'no' to debug fpm

yes

Name of pool. Used in logs and stats.

default

Address to accept fastcgi requests on.

Valid syntax is 'ip.ad.re.ss:port' or just 'port' or '/path/to/unix/socket'

127.0.0.1:9000

Set listen(2) backlog

-1

Set permissions for unix socket, if one used.

In Linux read/write permissions must be set in order to allow connections from web server.

Many BSD-derrived systems allow connections regardless of permissions.

0666

Additional php.ini defines, specific to this pool of workers.

/usr/sbin/sendmail -t -i

0

Unix user of processes

www

Unix group of processes

www

Process manager settings

Sets style of controling worker process count.

Valid values are 'static' and 'apache-like'

static

Sets the limit on the number of simultaneous requests that will be served.

Equivalent to Apache MaxClients directive.

Equivalent to PHP_FCGI_CHILDREN environment in original php.fcgi

Used with any pm_style.

128

Settings group for 'apache-like' pm style

Sets the number of server processes created on startup.

Used only when 'apache-like' pm_style is selected

20

Sets the desired minimum number of idle server processes.

Used only when 'apache-like' pm_style is selected

5

Sets the desired maximum number of idle server processes.

Used only when 'apache-like' pm_style is selected

35

The timeout (in seconds) for serving a single request after which the worker process will be terminated

Should be used when 'max_execution_time' ini option does not stop script execution for some reason

'0s' means 'off'

0s

The timeout (in seconds) for serving of single request after which a php backtrace will be dumped to slow.log file

'0s' means 'off'

0s

The log file for slow requests

logs/slow.log

Set open file desc rlimit

65535

Set max core size rlimit

0

Chroot to this directory at the start, absolute path

Chdir to this directory at the start, absolute path

Redirect workers' stdout and stderr into main error log.

If not set, they will be redirected to /dev/null, according to FastCGI specs

yes

How much requests each process should execute before respawn.

Useful to work around memory leaks in 3rd party libraries.

For endless request processing please specify 0

Equivalent to PHP_FCGI_MAX_REQUESTS

1024

Comma separated list of ipv4 addresses of FastCGI clients that allowed to connect.

Equivalent to FCGI_WEB_SERVER_ADDRS environment in original php.fcgi (5.2.2+)

Makes sense only with AF_INET listening socket.

127.0.0.1

Pass environment variables like LD_LIBRARY_PATH

All $VARIABLEs are taken from current environment

$HOSTNAME

/usr/local/bin:/usr/bin:/bin

/tmp

/tmp

/tmp

$OSTYPE

$MACHTYPE

2

EOF

echo "/usr/local/php/sbin/php-fpm start" >> /etc/rc.local

}

function __install_memcache()

{

cd $dir

wget $memcache_download

filename=`ls memcache-*`

foldername=`echo $filename | sed s'/\.tgz//'`

tar zxvf $filename

cd $foldername

/usr/local/php/bin/phpize

./configure --with-php-config=/usr/local/php/bin/php-config

make;make install

sed -i 's@extension_dir = "./"@extension_dir = "/usr/local/php/lib/php/extensions/no-debug-non-zts-20060613/"@' /usr/local/php/etc/php.ini

sed -i '492iextension = "memcache.so"' /usr/local/php/etc/php.ini

}

function __install_eaccelerator()

{

cd $dir

wget $eaccelerator_download

filename=`ls eaccelerator*`

foldername=`echo $filename | sed 's/\.tar\.bz2//'`

tar jxvf $filename

cd $foldername

/usr/local/php/bin/phpize

./configure --enable-eaccelerator=shared --with-php-config=/usr/local/php/bin/php-config

make;make install

mkdir -p /tmp/eaccelerator

cat >> /usr/local/php/etc/php.ini << "EOF"

[eaccelerator]

zend_extension="/usr/local/php/lib/php/extensions/no-debug-non-zts-20060613/eaccelerator.so"

eaccelerator.shm_size="64"

eaccelerator.cache_dir="/tmp/eaccelerator"

eaccelerator.enable="1"

eaccelerator.optimizer="1"

eaccelerator.check_mtime="1"

eaccelerator.debug="0"

eaccelerator.filter=""

eaccelerator.shm_max="0"

eaccelerator.shm_ttl="3600"

eaccelerator.shm_prune_period="3600"

eaccelerator.shm_only="0"

eaccelerator.compress="1"

eaccelerator.compress_level="9"

EOF

}

function __install_PDO_MYSQL()

{

cd $dir

wget $PDO_MYSQL_download

filename=`ls PDO_MYSQL*`

foldername=`echo $filename | sed 's/\.tgz//'`

tar zxvf $filename

cd $foldername

/usr/local/php/bin/phpize

./configure --with-php-config=/usr/local/php/bin/php-config --with-pdo-mysql=/usr/local/mysql

make;make install

sed -i '492iextension = "pdo_mysql.so"' /usr/local/php/etc/php.ini

}

function __install_ImageMagick()

{

cd $dir

wget $ImageMagick_download

filename=`ls ImageMagick*`

foldername='ImageMagick-6.5.1-2'

tar zxvf $filename

cd $foldername

./configure

make;make install

}

function __install_imagick()

{

cd $dir

wget $imagick_download

filename=`ls imagick*`

foldername=`echo $filename | sed 's/\.tgz//'`

tar zxvf $filename

cd $foldername

/usr/local/php/bin/phpize

./configure --with-php-config=/usr/local/php/bin/php-config

make;make install

sed -i '492iextension = "imagick.so"' /usr/local/php/etc/php.ini

if [ `getconf LONG_BIT` == 64 ]

then

ln -s /usr/local/lib/libevent-2.0.so.5 /usr/lib/

ln -s /usr/local/lib/libevent-2.0.so.5 /usr/lib64/

fi

}

function __install_memcached(){

cd $dir

wget $libevent_download

filename=`ls libevent-*`

foldername=`echo $filename | sed 's/\.tar\.gz//'`

tar zxvf $filename

cd $foldername

./configure

make;make install

ln -s /usr/local/lib/libevent-1.4.so.2 /usr/lib

cd $dir

wget $memcached_download

filename=`ls memcached-*`

foldername=`echo $filename | sed 's/\.tar\.gz//'`

tar zxvf $filename

cd $foldername

./configure --prefix=/usr/local/memcached --with-libevent=/usr

make;make install

echo "/usr/local/memcached/bin/memcached -d -m 64 -p 11211 -u www -l localhost" >> /etc/rc.local

}

function __install_pcre()

{

cd $dir

wget $pcre_download

filename=`ls pcre-*`

foldername=`echo $filename | sed 's/\.zip//'`

unzip $filename

cd $foldername

./configure

make;make install

}

function __install_nginx()

{

/usr/sbin/groupadd www

/usr/sbin/useradd -m www -g www -s /sbin/nologin -d /usr/local/nginx

mkdir -p /data/www

echo "<?php phpinfo();?>" > /data/www/index.php

mkdir -p /data/www/logs

chown -R www:www /data/www

cd $dir

wget $nginx_download

filename=`ls nginx-*`

foldername=`echo $filename | sed 's/\.tar\.gz//'`

tar zxvf $filename

cd $foldername

./configure  --prefix=/usr/local/nginx \

--with-http_stub_status_module \

--with-http_ssl_module \

--user=www \

--group=www \

--with-http_realip_module \

--with-http_flv_module \

--with-http_gzip_static_module

make;make install

mv /usr/local/nginx/conf/nginx.conf /usr/local/nginx/conf/nginx.conf.bak

cat > /usr/local/nginx/conf/nginx.conf << "EOF"

user www www;

worker_processes 8;

worker_cpu_affinity 0001 0010 0100 1000 0001 0010 0100 1000;

error_log  /usr/local/nginx/logs/error.log  notice;

pid        /usr/local/nginx/logs/nginx.pid;

worker_rlimit_nofile 65535;

events {

use epoll;

worker_connections 65535;

}

http {

include       mime.types;

default_type  application/octet-stream;

log_format  main   '$remote_addr - $remote_user [$time_local] "$request" '

'$status $body_bytes_sent "$http_referer" '

'"$http_user_agent" $http_x_forwarded_for';

#charset  gb2312;

server_names_hash_bucket_size 128;

client_header_buffer_size 32k;

large_client_header_buffers 4 32k;

client_max_body_size 30m;

sendfile on;

tcp_nopush     on;

keepalive_timeout 60;

tcp_nodelay on;

server_tokens off;

client_body_buffer_size 512k;

#proxy_connect_timeout   5;

#proxy_send_timeout      60;

#proxy_read_timeout      5;

#proxy_buffer_size       16k;

#proxy_buffers           4 64k;

#proxy_busy_buffers_size 128k;

#proxy_temp_file_write_size 128k;

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 128k;

gzip on;

gzip_min_length  1k;

gzip_buffers     4 16k;

gzip_http_version 1.1;

gzip_comp_level 2;

gzip_types       text/plain application/x-javascript text/css application/xml;

gzip_vary on;

#limit_zone  crawler  $binary_remote_addr  10m; server

server{

listen       80;

server_name localhost;

index index.html index.php index.htm;

root  /data/www;

access_log  /data/www/logs/access_localhost.log main;

if (-d $request_filename){

rewrite ^/(.*)([^/])$ http://$host/$1$2/ permanent;

}

error_page   500 502 503 504 404 403 http://localhost;

location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$ {

expires 30d;

}

location ~ .*\.(js|css)?$ {

expires 6h;

}

location ~ .*\.(log|txt)$

{

deny all;

}

location ~ .*\.(php)?$

{

fastcgi_pass  127.0.0.1:9000;

fastcgi_index index.php;

include fcgi.conf;

}

}

}

EOF

cat > /usr/local/nginx/conf/fcgi.conf << "EOF"

fastcgi_param  GATEWAY_INTERFACE  CGI/1.1;

fastcgi_param  SERVER_SOFTWARE    nginx;

fastcgi_param  QUERY_STRING       $query_string;

fastcgi_param  REQUEST_METHOD     $request_method;

fastcgi_param  CONTENT_TYPE       $content_type;

fastcgi_param  CONTENT_LENGTH     $content_length;

fastcgi_param  SCRIPT_FILENAME    $document_root$fastcgi_script_name;

fastcgi_param  SCRIPT_NAME        $fastcgi_script_name;

fastcgi_param  REQUEST_URI        $request_uri;

fastcgi_param  DOCUMENT_URI       $document_uri;

fastcgi_param  DOCUMENT_ROOT      $document_root;

fastcgi_param  SERVER_PROTOCOL    $server_protocol;

fastcgi_param  REMOTE_ADDR        $remote_addr;

fastcgi_param  REMOTE_PORT        $remote_port;

fastcgi_param  SERVER_ADDR        $server_addr;

fastcgi_param  SERVER_PORT        $server_port;

fastcgi_param  SERVER_NAME        $server_name;

# PHP only, required if PHP was built with --enable-force-cgi-redirect

fastcgi_param  REDIRECT_STATUS    200;

EOF

echo "/usr/local/nginx/sbin/nginx" >> /etc/rc.local

}

function __cutlog()

{

cat > /root/cutlog.sh << "EOF"

#!/bin/bash

if [ ! -d /data/nginx_log_backup ]

then

mkdir -p /data/nginx_log_backup

fi

date=`date -d yesterday +%y%m%d`

mkdir /data/nginx_log_backup/"$date"

for file in `ls /data/www/logs`

do

mv /data/www/logs/"$file" /data/nginx_log_backup/"$date"/"$date"-"$file"

done

/usr/local/nginx/sbin/nginx -s reload

EOF

echo "00 00 * * * /bin/sh /root/cutlog.sh >/dev/null" >> /var/spool/cron/root

}

echo "

#mysqldatadir:/data/mysql

#mysqluser:root

#mysqlpassword:lihuipeng007@163.com

#webdir:/data/www

#installdir:/usr/local/

#srcdir:/opt

0.exit

1.Only install Mysql

2.Only install Nginx

3.Install Nginx+php

4.Install Mysql+Nginx+PHP

5.Install Mysql+Nginx+PHP+Memcached

6.Test option "

read -p "Which do you want to install{[0|1|2|3|4|5|6]}:" linecase $line in

0)

exit 0;

;;

1)

__install_mysql

__install_mysql_complete

;;

2)

__install_pcre

__install_nginx

__cutlog

/usr/local/nginx/sbin/nginx

;;

3)

__install_lib

__install_mysql

__install_libiconv

__install_libmcrypt

__install_mhash

__install_mcrypt

__install_php

__install_memcache

__install_eaccelerator

__install_PDO_MYSQL

__install_ImageMagick

__install_imagick

__install_pcre

__install_nginx

__cutlog

/usr/local/php/sbin/php-fpm start

/usr/local/nginx/sbin/nginx

;;

4)

__install_lib

__install_mysql

__install_mysql_management

__install_libiconv

__install_libmcrypt

__install_mhash

__install_mcrypt

__install_php

__install_memcache

__install_eaccelerator

__install_PDO_MYSQL

__install_ImageMagick

__install_imagick

__install_pcre

__install_nginx

__cutlog

/usr/local/php/sbin/php-fpm start

/usr/local/nginx/sbin/nginx

;;

5)

__install_lib

__install_mysql

__install_mysql_management

__install_libiconv

__install_libmcrypt

__install_mhash

__install_mcrypt

__install_php

__install_memcache

__install_eaccelerator

__install_PDO_MYSQL

__install_ImageMagick

__install_imagick

__install_memcached

/usr/local/memcached/bin/memcached -d -m 64 -p 11211 -u www -l localhost

__install_pcre

__install_nginx

__cutlog

/usr/local/php/sbin/php-fpm start

/usr/local/nginx/sbin/nginx

;;

6)

echo "test option!"

;;

*)

echo "Usage: `basename $0` {0|1|2|3|4|5|6}" >&2

exit 3

;;

esac

 类似资料: