nginx+php (FastCGI) +mysql installation configuration and optimization on small memory VPS (T1.MICRO)

Source: Internet
Author: User
Tags fpm gmp openssl php and php and mysql stop script vps mysql command line

Background information:
Previously, because the price of AWS EC2 more expensive and rented other foreign small vendors VPS, after using more than 3 years, found that the AWS EC2 Price is much cheaper than the VPS currently in use.
The T1.MICRO model of the most ideal Japanese node of the global line and speed, the choice of 3-year long-term contract price of about 2500 yuan, less than 900 yuan a year, so it is intended to move the blog to AWS EC2.
Prior to the deployment of the VPS environment, basically a complete reference to the Zhang Yi two documents, including operating system selection is the same.

But this time I want to adopt the newer CentOS 6.4 minimal x86_64.
At the same time, choose the latest version of nginx,php and MySQL, the introduction of the Epel warehouse to simplify installation and deployment of additional dependent software installation, optimize some of the original way of working, such as creating a service management script to start/stop Nginx and MySQL, Use Logrotate to cut logs and so on;
After some toss, after filling a lot of pits, finally successfully completed the deployment of a new environment, feeling very good.

Below, this is the entire installation configuration process:
1. Install Common tools
Yum install-y vim wget unzip screen tree mlocate

2. Install the Compilation tool
Yum install-y gcc gcc-c++ autoconf patch CMake Automake

3. Install Epel Warehouse
Yum Install-y http://dl.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm

4. Install all required packages
Yum install-y libjpeg-turbo libjpeg-turbo-devel libpng libpng-devel freetype freetype-devel
Yum Install-y libxml2 libxml2-devel zlib zlib-devel glibc glibc-devel glib2 glib2-devel GMP gmp-devel
Yum install-y bzi P2 bzip2-devel ncurses ncurses-devel Curl curl-devel e2fsprogs e2fsprogs-devel unixodbc unixodbc-devel
Yum install-y Krb5-libs krb5-devel libidn libidn-devel OpenSSL openssl-devel openldap openldap-devel
Yum install-y libgcrypt LIBGCR Ypt-devel libtool
Yum install-y libmcrypt libmcrypt-devel mhash mhash-devel mcrypt pcre pcre-devel
Yum install-y ImageMagick Imagemagick-devel

5. Download all the necessary software source packages
Mkdir/root/packages
Cd/root/packages
wget http://nginx.org/download/nginx-1.4.7.tar.gz
wget http://museum.php.net/php5/php-5.2.17.tar.gz
wget http://php-fpm.org/downloads/php-5.2.17-fpm-0.5.14.diff.gz
wget http://mirrors.sohu.com/mysql/MySQL-5.5/mysql-5.5.36.tar.gz
wget http://ftp.gnu.org/pub/gnu/libiconv/libiconv-1.14.tar.gz
wget http://pecl.php.net/get/PDO_MYSQL-1.0.2.tgz
wget http://pecl.php.net/get/imagick-3.2.0RC1.tgz
wget http://pkgs.fedoraproject.org/repo/pkgs/php-eaccelerator/eaccelerator-0.9.6.1.tar.bz2/ 32ccd838e06ef5613c2610c1c65ed228/eaccelerator-0.9.6.1.tar.bz2

6. Compile and install Iconv
Cd/root/packages
Tar xzvf libiconv-1.14.tar.gz
CD libiconv-1.14
./configure
Make
Make install

7. Compile and install and configure MySQL
7.1 Compile and install MySQL
Cd/root/packages
Tar xzvf mysql-5.5.36.tar.gz
CD mysql-5.5.36
Cmake-dcmake_install_prefix=/webserver/mysql
-dsysconfdir=/webserver/mysql/etc
-dmysql_datadir=/webserver/mysql/data
-dmysql_tcp_port=3306
-dmysql_unix_addr=/werbserver/mysql/run/mysqld.sock
-dmysql_user=mysql
-dextra_charsets=all
-dwith_readline=1
-dwith_ssl=system
-dwith_embedded_server=1
-denabled_local_infile=1
-dwith_innobase_storage_engine=1
Make
Make install

7.2 Creating MySQL Users
Useradd mysql-d/webserver/mysql/data

7.3 Directory to create MySQL
Mkdir-p/webserver/mysql/{etc,data,tmp,run,binlogs,log}
Chown Mysql:mysql-r/webserver/mysql/{etc,data,tmp,run,binlogs,log}

7.4 Creating MY.CNF configuration Files
Vim/webserver/mysql/etc/my.cnf

[Mysqld]
# Basic Settings
DataDir =/webserver/mysql/data
Tmpdir =/webserver/mysql/tmp
Socket =/webserver/mysql/run/mysqld.sock
Port = 3306
Pid-file =/webserver/mysql/run/mysqld.pid

# InnoDB Settings
Default-storage-engine = INNODB
innodb_file_per_table = 1
Log-bin =/webserver/mysql/binlogs/bin-log-mysqld
Log-bin-index =/webserver/mysql/binlogs/bin-log-mysqld.index
Innodb_data_home_dir =/webserver/mysql/data
Innodb_data_file_path = Ibdata1:10m:autoextend
Innodb_log_group_home_dir =/webserver/mysql/data

# Increase the Max connections
Max_connections = 200

# The expiration time for logs, including binlogs
Expire_logs_days = 7

# set the character as UTF8
Character-set-server = UTF8
Collation-server = Utf8_unicode_ci

# server ID
server-id=33061

# Other Settings
[Mysqld_safe]
Log-error =/webserver/mysql/log/mysqld.log
Pid-file =/webserver/mysql/run/mysqld.pid
Open-files-limit = 8192

[Mysqlhotcopy]
Interactive-timeout

[Client]
Port = 3306
Socket =/webserver/mysql/run/mysqld.sock
Default-character-set = UTF8

Chown mysql:mysql/webserver/mysql/etc/my.cnf

7.5 Initializing MySQL system database
chmod +x scripts/mysql_install_db
scripts/mysql_install_db--user=mysql--basedir=/webserver/mysql--datadir=/webserver/mysql/data/--defaults-file= /webserver/mysql/etc/my.cnf

7.6 Creating a MySQL service management script
mkdir/webserver/init.d/
CP Support-files/mysql.server/webserver/init.d/mysqld
chmod +x/webserver/init.d/mysqld

7.7 Start MySQL Service
/webserver/init.d/mysqld start

7.8 login MySQL command line terminal
/webserver/mysql/bin/mysql-uroot-p

8. Compile installation and configure PHP
8.1 Compiling and installing PHP
Cd/root/packages
Tar xzf php-5.2.17.tar.gz
GZIP-CD php-5.2.17-fpm-0.5.14.diff.gz | Patch-d PHP-5.2.17-P1

Note: Create soft links so that PHP can successfully find the required library files at compile time
Ln-s/webserver/mysql/lib/webserver/mysql/lib64
Ln-s/usr/local/lib/libiconv.so/usr/local/lib64/libiconv.so
Ln-s/usr/lib64/libmhash.so.2/usr/lib64/libmhash.so

CD php-5.2.17
./configure--prefix=/webserver/php
--with-config-file-path=/webserver/php/etc
--with-mysql=/webserver/mysql--with-mysqli=/webserver/mysql/bin/mysql_config
--with-libdir=lib64
--with-iconv-dir=/usr/local
--with-freetype-dir--with-jpeg-dir--with-png-dir
--with-zlib--with-libxml-dir--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 '

Note: Create a soft link so that PHP can successfully locate the required library files at the time of installation
Ln-s/webserver/mysql/lib/libmysqlclient.so.18/usr/lib64/libmysqlclient.so.18
Ln-s/usr/local/lib/libiconv.so.2/usr/lib64/libiconv.so.2

Make install
CP Php.ini-dist/webserver/php/etc/php.ini

8.2 Compile and install Eaccelerator
Cd/root/packages
Tar xjf eaccelerator-0.9.6.1.tar.bz2
CD EACCELERATOR-0.9.6.1/
/webserver/php/bin/phpize
./configure--enable-eaccelerator=shared--with-php-config=/webserver/php/bin/php-config
Make
Make install
Cd.. /

8.3 Compile and install Pdo_mysql
Tar zxvf pdo_mysql-1.0.2.tgz
CD PDO_MYSQL-1.0.2/
/webserver/php/bin/phpize
./configure--with-php-config=/webserver/php/bin/php-config--with-pdo-mysql=/webserver/mysql
Make
Make install
Cd.. /

8.4 Compile and install Imagick
Tar xzf imagick-3.2.0rc1.tgz
CD IMAGICK-3.2.0RC1
/webserver/php/bin/phpize
./configure--with-php-config=/webserver/php/bin/php-config
Make
Make install

8.5 Modifying php.ini configuration files
Vim/webserver/php/etc/php.ini

; Directory in which the loadable Extensions (modules) reside.
; extension_dir = "./"
Extension_dir = "/webserver/php/lib/php/extensions/no-debug-non-zts-20060613/"
Extension = "imagick.so"
Extension = "pdo_mysql.so"

; output_buffering = Off
Output_buffering = On

; Cgi.fix_pathinfo=0
Cgi.fix_pathinfo=0

8.6 Create cache Directory Www.111cn.net
Mkdir/webserver/eaccelerator_cache

8.7 adding eaccelerator support in php.ini
Vim/webserver/php/etc/php.ini

[Eaccelerator]
zend_extension= "/webserver/php/lib/php/extensions/no-debug-non-zts-20060613/eaccelerator.so"
Eaccelerator.shm_size= "1"
Eaccelerator.cache_dir= "/webserver/eaccelerator_cache"
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"
Eaccelerator.keys = "Disk_only"
Eaccelerator.sessions = "Disk_only"
Eaccelerator.content = "Disk_only"

8.8 Creating WWW users
Useradd-r www

8.9 Create the desired directory
Mkdir-p/webserver/blog/{rainbow,eric,keshui,logs}
Chown Www:www/webserver/blog/{rainbow,eric,keshui,logs}
chmod +w/webserver/blog/{rainbow,eric,keshui,logs}
Mkdir/webserver/php/run

8.10 Creating Php-fpm.con configuration Files
Rm-f/webserver/php/etc/php-fpm.conf
Vim/webserver/php/etc/php-fpm.conf


<?xml version= "1.0"?>
<configuration>

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

<section name= "Global_options" >

Pid file
<value name= "Pid_file" >/webserver/php/logs/php-fpm.pid</value>

Error log File
<value name= "Error_log" >/webserver/php/logs/php-fpm.log</value>

Log level
<value name= "Log_level" >notice</value>

When this amount the PHP processes exited with SIGSEGV or sigbus ...
<value name= "Emergency_restart_threshold" >10</value>

... in a less than this interval of time, a graceful restart would be initiated.
Useful to work around accidental curruptions in accelerator ' s shared memory.
<value name= "Emergency_restart_interval" >1m</value>

Time limit on waiting child ' s reaction on signals from master
<value name= "Process_control_timeout" >5s</value>

Set to ' no ' to debug FPM
<value name= "Daemonize" >yes</value>

</section>

<workers>

<section name= "Pool" >

Name of Pool. Used in logs and stats.
<value name= "Name" >default</value>

Address to accept fastcgi requests on.
Valid syntax is ' ip.ad.re.ss:port ' or just ' port ' or '/path/to/unix/socket '
<value name= "Listen_address" >/webserver/php/run/php-cgi.sock</value>

<value name= "Listen_options" >

Set Listen (2) backlog
<value name= "Backlog" >-1</value>

        Set permissions for UNIX sockets, if one used.
        in Linux read/write permissions must is set in order to allow connections From Web server.
        Many bsd-derrived systems allow connections regardless of permissions.< br>         <value name= "owner" ></VALUE>
         <value name= "group" ></VALUE>
        <value name= "mode" >0666</value>
      </value>

Additional php.ini defines, specific to this pool of workers.
<value name= "Php_defines" >
<value name= "Sendmail_path" >/usr/sbin/sendmail-t-i</value>
<value name= "Display_errors" >0</value>
</value>

Unix User of processes
<value name= "User" >www</value>

Unix Group of processes
<value name= "group" >www</value>

Process Manager Settings
<value name= "PM" >

Sets style of controling worker process count.
Valid values are ' static ' and ' Apache-like '
<value name= "Style" >static</value>

Sets the limit on the number of simultaneous requests that'll be served.
Equivalent to Apache maxclients directive.
Equivalent to Php_fcgi_children environment in original php.fcgi
Used with any pm_style.
<value name= "Max_children" >5</value>

Settings Group for ' Apache-like ' pm style
<value name= "Apache_like" >

Sets the number of server processes created on startup.
Used ' Apache-like ' Pm_style is selected
<value name= "Startservers" >20</value>

Sets the desired minimum number of idle server processes.
Used ' Apache-like ' Pm_style is selected
<value name= "Minspareservers" >5</value>

Sets the desired maximum number of idle server processes.
Used ' Apache-like ' Pm_style is selected
<value name= "Maxspareservers" >35</value>

</value>

</value>

The timeout (in seconds) to serving a single request after the which the worker process would be terminated
Should be used as ' max_execution_time ' ini option does not stop script execution for some reason
' 0s ' means ' off '
<value name= "Request_terminate_timeout" >0s</value>

The timeout (in seconds) for serving of single request after which a PHP backtrace'll be dumped to Slow.log file
' 0s ' means ' off '
<value name= "Request_slowlog_timeout" >0s</value>

The log file for slow requests
<value name= "Slowlog" >logs/slow.log</value>

Set Open File desc rlimit
<value name= "Rlimit_files" >65535</value>

Set Max Core Size Rlimit
<value name= "Rlimit_core" >0</value>

Chroot to this directory at the start, absolute path
<value name= "Chroot" ></value>

Chdir to this directory at the start, absolute path
<value name= "ChDir" ></value>

Redirect workers ' stdout and stderr into main error log.
If not set, they'll be redirected to/dev/null, according to FastCGI specs
<value name= "Catch_workers_output" >yes</value>

How much requests each process should execute before respawn.
Useful to work around memory leaks at 3rd party libraries.
For endless request processing please specify 0
Equivalent to Php_fcgi_max_requests
<value name= "Max_requests" >1024</value>

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.
<value name= "Allowed_clients" >127.0.0.1</value>

Pass environment variables like Ld_library_path


All $VARIABLEs are taken from environment


&lt;value name= "Environment" &gt;


&lt;value name= "HOSTNAME" &gt; $HOSTNAME &lt;/value&gt;


&lt;value name= "PATH" &gt;/usr/local/bin:/usr/bin:/bin&lt;/value&gt;


&lt;value name= "TMP" &gt;/tmp&lt;/value&gt;


&lt;value name= "Tmpdir" &gt;/tmp&lt;/value&gt;


&lt;value name= "TEMP" &gt;/tmp&lt;/value&gt;


&lt;value name= "OSType" &gt; $OSTYPE &lt;/value&gt;


&lt;value name= "Machtype" &gt; $MACHTYPE &lt;/value&gt;


&lt;value name= "Malloc_check_" &gt;2&lt;/value&gt;


&lt;/value&gt;

</section>

</workers>

</configuration>

8.11 Creating PHP-FPM Service Management Scripts
Ln-s/WEBSERVER/PHP/SBIN/PHP-FPM/WEBSERVER/INIT.D/PHP-FPM

8.12 Start PHP-FPM Service
/WEBSERVER/INIT.D/PHP-FPM start

9 compiling, installing and configuring Nginx
9.1 Compile and install Nginx
Cd/root/packages
Tar xzf nginx-1.4.7.tar.gz
CD nginx-1.4.7/
./configure--user=www--group=www
--prefix=/usr/local/webserver/nginx
--with-http_stub_status_module--with-http_ssl_module
Make
Make install

9.2 Create the Nginx directory
Mkdir/webserver/nginx/conf/conf.d
Mkdir/webserver/nginx/run

9.3 Creating Fastcgi_params configuration Files
Vim Fastcgi_params

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 is built with--enable-force-cgi-redirect
Fastcgi_param Redirect_status 200;

9.4 Create nginx.conf master configuration file
Vim/webserver/nginx/conf/nginx.conf

User www www.
Worker_processes 1;

Error_log/webserver/nginx/logs/error.log;
Pid/webserver/nginx/run/nginx.pid;

Worker_rlimit_nofile 32768;

Events {
Use Epoll;
Worker_connections 32768;
}


HTTP {
Include/webserver/nginx/conf/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 ';

Access_log/webserver/nginx/logs/access.log main;

Server_names_hash_bucket_size 128;
Client_header_buffer_size 32k;
Large_client_header_buffers 4 32k;

Sendfile on;
Tcp_nopush on;

Keepalive_timeout 60;

Tcp_nodelay on;

Fastcgi_connect_timeout 300; Www.111cn.net
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.0;
Gzip_comp_level 2;
Gzip_types text/plain application/x-javascript text/css application/xml;
Gzip_vary on;

include/webserver/nginx/conf/conf.d/*.conf;
}

9.5 Creating a satellite configuration file
9.5.1 Create status.conf configuration file Admin Status page
Vim/webserver/nginx/conf/conf.d/status.conf

Server
{
Listen 80;
server_name status.nginxs.com status.heylinux.com;
Location/{
Stub_status on;
Access_log off;
}
}

9.5.2 Create rainbow.conf configuration file Management heylinux.com
Vim/webserver/nginx/conf/conf.d/rainbow.conf

Server
{
Listen 80;
server_name heylinux.com *.heylinux.com;
Index index.html index.htm index.php;
Root/webserver/blog/rainbow;

Location/{
if (-f $request _filename/index.html) {
Rewrite (. *) $1/index.html break;
}
if (-f $request _filename/index.php) {
Rewrite (. *) $1/index.php;
}
if (!-f $request _filename) {
Rewrite (. *)/index.php;
}
}

Location ~. *. (PHP|PHP5)? $
{
Fastcgi_pass Unix:/webserver/php/run/php-cgi.sock;
Fastcgi_index index.php;
Fastcgi_param Script_filename/webserver/blog/rainbow$fastcgi_script_name;
Include/webserver/nginx/conf/fastcgi_params;
}

Location ~. *. (gif|jpg|jpeg|png|bmp|swf) $
{
Expires 15d;
}

Location ~. *. (JS|CSS)? $
{
Expires 1d;
}

Log_format rainbow_access ' $remote _addr-$remote _user [$time _local] "$request"
' $status $body _bytes_sent ' $http _referer '
' $http _user_agent ' $http _x_forwarded_for ';
Access_log/webserver/blog/logs/rainbow_access.log rainbow_access;
}

9.5.3 Create eric.conf configuration file Management nginxs.com
Vim/webserver/nginx/conf/conf.d/eric.conf

Server
{
Listen 80;
server_name nginxs.com *.nginxs.com;
Index index.html index.htm index.php;
Root/webserver/blog/eric;

  Location/{
      if (-F $request _filename/index.html) {
               rewrite (. *) $1/index.html break;
     }
      if (-F $request _filename/index.php) {
               rewrite (. *) $1/index.php;
     }
      if (!-f $request _filename) {
               rewrite (. *)/index.php;
     }
 }

Location ~. *. (PHP|PHP5)? $
{
Fastcgi_pass Unix:/webserver/php/run/php-cgi.sock;
Fastcgi_index index.php;
Fastcgi_param Script_filename/webserver/blog/eric$fastcgi_script_name;
Include/webserver/nginx/conf/fastcgi_params;
}

Location ~. *. (gif|jpg|jpeg|png|bmp|swf) $
{
Expires 15d;
}

Location ~. *. (JS|CSS)? $
{
Expires 1d;
}

Log_format eric_access ' $remote _addr-$remote _user [$time _local] "$request"
' $status $body _bytes_sent ' $http _referer '
' $http _user_agent ' $http _x_forwarded_for ';
Access_log/webserver/blog/logs/eric_access.log eric_access;
}

9.6 Creating Nginx service Management Scripts
Touch/webserver/init.d/nginx
chmod +x/webserver/init.d/nginx
Vim/webserver/init.d/nginx

#!/bin/sh


#


# Nginx-this script starts and stops the Nginx daemon


#


# Chkconfig:-85 15


# Description:nginx is a HTTP (s) server, HTTP (s) reverse


# Proxy and IMAP/POP3 proxy server


# Processname:nginx


# config:/etc/nginx/nginx.conf


# config:/etc/sysconfig/nginx


# Pidfile:/var/run/nginx.pid





# Source function library.


. /etc/rc.d/init.d/functions





# Source Networking configuration.


. /etc/sysconfig/network





# Check that networking are up.


["$NETWORKING" = "no"] &amp;&amp; exit 0





nginx= "/webserver/nginx/sbin/nginx"


prog=$ (basename $nginx)





Nginx_conf_file= "/webserver/nginx/conf/nginx.conf"





Lockfile=/var/lock/subsys/nginx





Make_dirs () {


# Make required Directories


User= ' $nginx-v 2&gt;&amp;1 | grep "Configure arguments:" | Sed ' s/[^*]*--user= ([^]*). */1/g '-'


If [-Z "' grep $user/etc/passwd ']"; Then


Useradd-m-s/bin/nologin $user


Fi


Options= ' $nginx-v 2&gt;&amp;1 | grep ' Configure arguments: '


for opt in $options; Todo


If [' Echo $opt | grep '. *-temp-path ']; Then


Value= ' echo $opt | Cut-d "=" F 2 '


if [!-D "$value"]; Then


# echo "Creating" $value


Mkdir-p $value &amp;&amp; chown-r $user $value


Fi


Fi


Done


}





Start () {


[x $nginx] | | Exit 5


[f $NGINX _conf_file] | | Exit 6


Make_dirs


Echo-n $ "Starting $prog:"


Daemon $nginx-C $NGINX _conf_file


Retval=$?


Echo


[$retval-eq 0] &amp;&amp; Touch $lockfile


Return $retval


}





Stop () {


Echo-n $ "Stopping $prog:"


Killproc $prog-quit


Retval=$?


Echo


[$retval-eq 0] &amp;&amp; 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 &gt;/dev/null 2&gt;&amp;1


}





Case "$" in


Start


Rh_status_q &amp;&amp; Exit 0


$


;;


Stop


Rh_status_q | | Exit 0


$


;;


Restart|configtest)


$


;;


Reload


Rh_status_q | | Exit 7


$


;;


Force-reload)


Force_reload


;;


Status


Rh_status


;;


Condrestart|try-restart)


Rh_status_q | | Exit 0


;;


*)


echo $ "Usage: $ {start|stop|status|restart|condrestart|try-restart|reload|force-reload|configtest}"


Exit 2


Esac

9.7 Start Nginx Service
/webserver/init.d/nginx start

10. Optimize System kernel Parameters
Vim/etc/sysctl.conf

# for Nginx
Net.ipv4.tcp_max_syn_backlog = 65536
Net.core.netdev_max_backlog = 32768
Net.core.somaxconn = 32768
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_reuse = 1
Net.ipv4.ip_local_port_range = 1024 65535

Sysctl-p

Vim/etc/security/limits.conf

*-Nofile 32768
*-Nproc 32768

11. Create an interchange partition
DD If=/dev/zero of=/opt/swapfile bs=1m count=256
Mkswap/opt/wapfile
Swapon/opt/swapfile

Vi/etc/fstab

/opt/swapfile Swap Defaults 0 0

12. Configure Logrotate Cutting Log
Yum Install-y logrotate
Vim/etc/logrotate.d/blog

/webserver/blog/logs/rainbow_access.log
/webserver/blog/logs/eric_access.log
{
  daily
  Rotate 7
  Missingok
  notifempty
  dateext
  sharedscripts
  Postrota Te
    if [-f/webserver/nginx/run/nginx.pid]; then
     /bin/kill- HUP '/bin/cat/webserver/nginx/run/nginx.pid '
    fi
  Endscript
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.