- 浏览: 854001 次
- 性别:
- 来自: 北京
文章分类
最新评论
-
zjhzwx1212:
为什么用threadLocal后,输出值是从20开始的,而定义 ...
j2ee的线程安全--threadlocal -
aeoluspu:
不错 mysql 测试部分感觉不详细
用sysbench(或者super-smack)测试mysql性能 -
nanPrivate:
有没有例子,只理论,实践起来还是不会啊
JMS可靠消息传送 -
lwclover:
一个网络工程师 装什么b
postfix 如何删除队列中的邮件 -
maimode:
我也欠缺不少啊
理想的计算机科学知识体系
Nginx (”engine x”) 是一个高性能的 HTTP 和反向代理服务器,由于它的高性能和稳定性,国内越来越多的网站已经开始使用 Nginx 作为 Web 服务器。以下是笔者最近一次的的安装配置笔记。
系统版本:CentOS release 5.3 (Final),安装之前,先确定服务器是否可以连通网络,否则wget、yum等网络命令均无法使用。
编辑/etc/resolv.conf
vim /etc/resolv.conf
在尾部加入下面的内容(*处填写你的DNS地址),重启就好了。
nameserver ***.***.*.**
例如北京地区的DNS为:202.106.0.20 和 211.161.46.84
以下是服务器安装的各个软件的安装版本:
nginx-0.7.67:nginx最新稳定版本
mysql-5.1.49:MySQL 5.1系列最新版本
php-5.2.14:PHP5.2系列最新版本
php-5.2.14-fpm-0.5.14:以FastCGI模式编译安装PHP5.2.14时需要用到的补丁
libiconv-1.13:编译安装PHP 5.2.14所需的支持库
libmcrypt-2.5.8:编译安装PHP 5.2.14所需的支持库
mcrypt-2.6.8:编译安装PHP 5.2.14所需的支持库
memcache-2.2.5:高性能的分布式内存缓存服务器
mhash-0.9.9.9:编译安装PHP 5.2.14所需的支持库
pcre-8.01:安装Nginx所需的pcre库
eaccelerator-0.9.6:eAccelerator可以加速PHP
PDO_MYSQL-1.0.2:mysql pdo支持
ImageMagick:ImageMagick库
imagick-2.3.0:imagick库
以上版本均为截止2010.7.30日的官方最新稳定版本,可用在ssh中直接使用wget命令从官网获得:
在 “Select Platform” 中选择 “Source Code”,选择列表中的最后一个 mysql-5.1.49.tar.gz 下载:
wget http://php-fpm.org/downloads/php-5.2.14-fpm-0.5.14.diff.gz
wget http://cn2.php.net/get/php-5.2.14.tar.gz/from/cn.php.net/mirror
wget http://ftp.gnu.org/pub/gnu/libiconv/libiconv-1.13.tar.gz
wget “http://downloads.sourceforge.net/mcrypt/libmcrypt-2.5.8.tar.gz?modtime=1171868460&big_mirror=0”
wget “http://downloads.sourceforge.net/mcrypt/mcrypt-2.6.8.tar.gz?modtime=1194463373&big_mirror=0”
wget http://pecl.php.net/get/memcache-2.2.5.tgz
wget “http://downloads.sourceforge.net/mhash/mhash-0.9.9.9.tar.gz?modtime=1175740843&big_mirror=0”
wget ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-8.01.tar.gz
wget http://bart.eaccelerator.net/source/0.9.6/eaccelerator-0.9.6.tar.bz2
wget http://pecl.php.net/get/PDO_MYSQL-1.0.2.tgz
wget http://www.plhwin.com/download/webserver/ImageMagick.tar.gz
wget http://pecl.php.net/get/imagick-2.3.0.tgz
以上所有软件笔者习惯于wget到“/usr/local/src”目录中,以备后面的安装。
以下是笔者习惯的各个目录位置:
服务器软件安装目录位于:/usr/local/webserver
原始安装软件位于:/usr/local/src
在开始安装前,强烈建议更换掉centos系统的开源软件镜像源为网易的开源软件镜像站点,这样使用yum命令安装软件时候可以获得最大的下载速度。
替换过程:
cd /etc/yum.repos.d/ mv CentOS-Base.repo CentOS-Base.repo.bak vim CentOS-Base.repo
在 vim 编辑器中填写以下内容并保存:
#
# This file uses a new mirrorlist system developed by Lance Davis for CentOS.
# The mirror system uses the connecting IP address of the client and the
# update status of each mirror to pick mirrors that are updated to and
# geographically close to the client. You should use this for CentOS updates
# unless you are manually picking other mirrors.
#
# If the mirrorlist= does not work for you, as a fall back you can try the
# remarked out baseurl= line instead.
#
#
[base]
name=CentOS-$releasever – Base
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=os
#baseurl=http://mirror.centos.org/centos/$releasever/os/$basearch/
baseurl=http://mirrors.163.com/centos/$releasever/os/$basearch/
gpgcheck=1
gpgkey=http://mirror.centos.org/centos/RPM-GPG-KEY-CentOS-5
#released updates
[updates]
name=CentOS-$releasever – Updates
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=updates
#baseurl=http://mirror.centos.org/centos/$releasever/updates/$basearch/
baseurl=http://mirrors.163.com/centos/$releasever/updates/$basearch/
gpgcheck=1
gpgkey=http://mirror.centos.org/centos/RPM-GPG-KEY-CentOS-5
#packages used/produced in the build but not released
[addons]
name=CentOS-$releasever – Addons
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=addons
#baseurl=http://mirror.centos.org/centos/$releasever/addons/$basearch/
baseurl=http://mirrors.163.com/centos/$releasever/addons/$basearch/
gpgcheck=1
gpgkey=http://mirror.centos.org/centos/RPM-GPG-KEY-CentOS-5
#additional packages that may be useful
[extras]
name=CentOS-$releasever – Extras
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=extras
#baseurl=http://mirror.centos.org/centos/$releasever/extras/$basearch/
baseurl=http://mirrors.163.com/centos/$releasever/extras/$basearch/
gpgcheck=1
gpgkey=http://mirror.centos.org/centos/RPM-GPG-KEY-CentOS-5
#additional packages that extend functionality of existing packages
[centosplus]
name=CentOS-$releasever – Plus
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=centosplus
#baseurl=http://mirror.centos.org/centos/$releasever/centosplus/$basearch/
baseurl=http://mirrors.163.com/centos/$releasever/centosplus/$basearch/
gpgcheck=1
enabled=0
gpgkey=http://mirror.centos.org/centos/RPM-GPG-KEY-CentOS-5
开始安装前的准备
mkdir -p /usr/local/webserver
mkdir -p /workspace/wwwroot
fastcgi安装PHP会用到,如果有包不需要再执行yum命令进行安装
安装nginx会用到pcre库,如果有包不需要再执行yum命令进行安装
二、接下来开始编译安装MYSQL
cd mysql-5.1.49
groupadd mysql
useradd -g mysql mysql
./configure –prefix=/usr/local/webserver/mysql –with-comment=Source –with-server-suffix=-enterprise-gpl –with-mysqld-user=mysql –without-debug –with-socket-path=/tmp/mysql.sock –with-big-tables –with-charset=utf8 –with-collation=utf8_general_ci –with-extra-charsets=all –with-pthread –enable-static –enable-thread-safe-client –with-client-ldflags=-all-static –with-mysqld-ldfags=-all-static –enable-assembler –without-ndb-debug –enable-local-infile –with-readline –with-raid –with-low-memory
make
make install
整个安装过程中,MYSQL是最慢的一个环节,所以需要有一点耐心,如果你在执行 “make install” 的时候,一直卡在”make[4]: Entering directory `/usr/local/src/mysql-5.1.49/mysql-test’”,那是因为你太心急了,等等就编译好了,呵呵,整个卡在这个的过程大概耗时20分钟。趁这个过程喝杯茶去吧。
编译安装完成后,开始配置MYSQL,具体的步骤就先不解释了,可以网上查到,只需要按照一下步骤操作即可:
cd /usr/local/webserver/mysql cp /usr/local/webserver/mysql/share/mysql/my-medium.cnf /etc/my.cnf /usr/local/webserver/mysql/bin/mysql_install_db --user=mysql chown -R root /usr/local/webserver/mysql/ chown -R root /usr/local/webserver/mysql/var/ chown -R root /usr/local/webserver/mysql/var/mysql chown -R mysql /usr/local/webserver/mysql/ chown -R mysql /usr/local/webserver/mysql/var/ chown -R mysql /usr/local/webserver/mysql/var/mysql
增加MYSQL服务为开机自动启动:
cp /usr/local/webserver/mysql/share/mysql/mysql.server /etc/rc.d/init.d/mysqld chmod 700 /etc/init.d/mysqld chkconfig --add mysqld chkconfig --level 3 mysqld on
启动MYSQL服务
service mysqld start
设置MYSQL密码为”111111″(6个1)
/usr/local/webserver/mysql/bin/mysqladmin -u root password 111111
cp /usr/local/webserver/mysql/bin/mysql /sbin/mysql cp /usr/local/webserver/mysql/bin/mysqldump /sbin/mysqldump
测试MYSQL是否正确安装:
查看所有数据库:show databases;
选择数据库: use mysql;
显示所选择数据库下的所有表名:show tables;
退出MYSQL: \q
三、编译安装PHP 5.2.14所需的支持库
tar zxvf libiconv-1.13.tar.gz cd libiconv-1.13/ ./configure --prefix=/usr/local make make install cd ../ tar zxvf libmcrypt-2.5.8.tar.gz cd libmcrypt-2.5.8/ ./configure make make install /sbin/ldconfig cd libltdl/ ./configure --enable-ltdl-install make make install cd ../../ tar zxvf mhash-0.9.9.9.tar.gz cd mhash-0.9.9.9/ ./configure make make install cd ../ 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/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 tar zxvf mcrypt-2.6.8.tar.gz cd mcrypt-2.6.8/ /sbin/ldconfig ./configure make make install cd ../
四、以FastCGI模式编译安装PHP 5.2.14
gzip -cd php-5.2.14-fpm-0.5.14.diff.gz | patch -d php-5.2.14 -p1
cd php-5.2.14/
./configure –prefix=/usr/local/webserver/php –with-config-file-path=/usr/local/webserver/php/etc –with-mysql=/usr/local/webserver/mysql –with-mysqli=/usr/local/webserver/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-xmlrpc –enable-zip –enable-soap –without-pear
make ZEND_EXTRA_LIBS=’-liconv’
make install
cp php.ini-dist /usr/local/webserver/php/etc/php.ini
cd ../
五、编译安装PHP5扩展模块
tar zxvf memcache-2.2.5.tgz cd memcache-2.2.5/ /usr/local/webserver/php/bin/phpize ./configure --with-php-config=/usr/local/webserver/php/bin/php-config make make install cd ../ tar jxvf eaccelerator-0.9.6.tar.bz2 cd eaccelerator-0.9.6/ /usr/local/webserver/php/bin/phpize ./configure --enable-eaccelerator=shared --with-php-config=/usr/local/webserver/php/bin/php-config make make install cd ../ tar zxvf PDO_MYSQL-1.0.2.tgz cd PDO_MYSQL-1.0.2/ /usr/local/webserver/php/bin/phpize ./configure --with-php-config=/usr/local/webserver/php/bin/php-config --with-pdo-mysql=/usr/local/webserver/mysql make make install cd ../ tar zxvf ImageMagick.tar.gz cd ImageMagick-6.5.1-2/ ./configure make make install cd ../ tar zxvf imagick-2.3.0.tgz cd imagick-2.3.0/ /usr/local/webserver/php/bin/phpize ./configure --with-php-config=/usr/local/webserver/php/bin/php-config make make install cd ../
六、修改php.ini文件
1、手工修改:查找/usr/local/webserver/php/etc/php.ini中的extension_dir = “./”
修改为extension_dir = “/usr/local/webserver/php/lib/php/extensions/no-debug-non-zts-20060613/”
并在此行后增加以下几行,然后保存:
extension = “memcache.so”
extension = “pdo_mysql.so”
extension = “imagick.so”
再查找output_buffering = Off
修改为output_buffering = On
再查找; cgi.fix_pathinfo=0
修改为cgi.fix_pathinfo=0,防止Nginx文件类型错误解析漏洞。
2、自动修改:若嫌手工修改麻烦,可执行以下shell命令,自动完成对php.ini文件的修改:
sed -i ’s#output_buffering = Off#output_buffering = On#’ /usr/local/webserver/php/etc/php.ini
sed -i “s#; always_populate_raw_post_data = On#always_populate_raw_post_data = On#g” /usr/local/webserver/php/etc/php.ini
sed -i “s#; cgi.fix_pathinfo=0#cgi.fix_pathinfo=0#g” /usr/local/webserver/php/etc/php.ini
七、配置eAccelerator加速PHP
创建 eaccelerator 缓存目录,并编辑php.ini
mkdir -p /usr/local/webserver/eaccelerator_cache vim /usr/local/webserver/php/etc/php.ini
按shift+g键跳到配置文件的最末尾,加上以下配置信息:
zend_extension=”/usr/local/webserver/php/lib/php/extensions/no-debug-non-zts-20060613/eaccelerator.so”
eaccelerator.shm_size=”64″
eaccelerator.cache_dir=”/usr/local/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″
八、创建www用户和组,以及供虚拟主机使用的目录:
/usr/sbin/groupadd www /usr/sbin/useradd -g www www
假设你已经有一个 www.test.com 的域名已经指向了服务器的IP.你需要增加这个虚拟主机站点:(如果你当前暂无可用的域名,你希望使用IP直接访问到,则无需进行下面的操作。待安装完 NGINX后,在nginx.conf文件中配置即可)
mkdir -p /workspace/wwwroot/test.com chmod +w /workspace/wwwroot/test.com chown -R www:www /workspace/wwwroot/test.com
以后要添加一个新的虚拟主机,则重复运行上面的步骤即可。
九、创建php-fpm配置文件(php-fpm是为PHP打的一个FastCGI管理补丁,可以平滑变更php.ini配置而无需重启php- cgi)
在/usr/local/webserver/php/etc/目录中创建php-fpm.conf文件:
rm -f /usr/local/webserver/php/etc/php-fpm.conf vim /usr/local/webserver/php/etc/php-fpm.conf
输入以下内容(如果您安装 Nginx + PHP 用于程序调试,请将以下的0改为1,以便显示PHP错误信息,否则,Nginx 会报状态为500的空白错误页):
All relative paths in this config are relative to php’s install prefix
Pid file
/usr/local/webserver/php/logs/php-fpm.pid
Error log file
/usr/local/webserver/php/logs/php-fpm.log
Log level
error
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’
/tmp/php-cgi.sock
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
102400
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
启动php-cgi进程,监听127.0.0.1的9000端口,进程数为128(如果服务器内存小于3GB,可以只开启64个进程),用户为 www:
ulimit -SHn 65535 /usr/local/webserver/php/sbin/php-fpm start
注:/usr/local/webserver/php/sbin/php-fpm还有其他参数,包括:start|stop|quit|restart|reload|logrotate,修改php.ini后不重启php-cgi,重新加载配置文件使用reload。
十、安装nginx-0.7.67
cd nginx-0.7.67/
./configure –user=www –group=www –prefix=/usr/local/webserver/nginx –with-http_stub_status_module –with-http_ssl_module
make && make install
cd ../
创建Nginx日志目录
mkdir -p /logs/nginx chmod +w /logs/nginx chown -R www:www /logs/nginx
创建Nginx配置文件:
①、在/usr/local/webserver/nginx/conf/目录中创建nginx.conf文件:
rm -f /usr/local/webserver/nginx/conf/nginx.conf vim /usr/local/webserver/nginx/conf/nginx.conf
输入以下内容:
worker_processes 8;
error_log /logs/nginx/nginx_error.log crit;
pid /usr/local/webserver/nginx/nginx.pid;
#Specifies the value for maximum file descriptors that can be opened by this process.
worker_rlimit_nofile 65535;
events
{
use epoll;
worker_connections 65535;
}
http
{
include mime.types;
default_type application/octet-stream;
server_names_hash_bucket_size 128;
client_header_buffer_size 32k;
large_client_header_buffers 4 32k;
client_max_body_size 8m;
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 128k;
gzip on;
gzip_min_length 1k;
gzip_buffers 4 16k;
#gzip_http_version 1.0;
gzip_http_version 1.1;
gzip_comp_level 2;
gzip_types text/plain application/x-javascript text/css application/xml;
gzip_vary on;
server_name_in_redirect off;
#limit_zone crawler $binary_remote_addr 10m;
server
{
listen 80;
server_name www.test.com test.com;
index index.html index.htm index.php;
root /workspace/wwwroot/test.com;
#limit_conn crawler 20;
location ~ .*\.(php|php5)?$
{
fastcgi_pass unix:/tmp/php-cgi.sock;
fastcgi_index index.php;
include fcgi.conf;
}
location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
{
expires 30d;
}
location ~ .*\.(js|css)?$
{
expires 1h;
}
access_log off;
}
server
{
listen 80;
server_name status.test.com;
location / {
stub_status on;
access_log off;
}
}
}
②、在/usr/local/webserver/nginx/conf/目录中创建fcgi.conf文件:
vim /usr/local/webserver/nginx/conf/fcgi.conf
输入以下内容:
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;
fastcgi_param SERVER_NAME $host;
# PHP only, required if PHP was built with –enable-force-cgi-redirect
fastcgi_param REDIRECT_STATUS 200;
启动Nginx:
ulimit -SHn 65535 /usr/local/webserver/nginx/sbin/nginx
配置开机自动启动Nginx + PHP
vim /etc/rc.local
在末尾增加以下内容:
/usr/local/webserver/php/sbin/php-fpm start
/usr/local/webserver/nginx/sbin/nginx
优化Linux内核参数:
vim /etc/sysctl.conf
在末尾增加以下内容:
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_fin_timeout = 30
#net.ipv4.tcp_keepalive_time = 120
net.ipv4.ip_local_port_range = 1024 65535
使配置立即生效:
/sbin/sysctl -p
在不停止Nginx服务的情况下平滑变更Nginx配置
1、修改/usr/local/webserver/nginx/conf/nginx.conf配置文件后,请执行以下命令检查配置文件是否正确:
/usr/local/webserver/nginx/sbin/nginx -t
如果屏幕显示以下两行信息,说明配置文件正确:
the configuration file /usr/local/webserver/nginx/conf/nginx.conf was tested successfully
2、创建 restart.sh:
vim /usr/local/webserver/nginx/restart.sh
输入以下内容,并保存:
kill -HUP `cat /usr/local/webserver/nginx/nginx.pid`
更改权限:
chmod 777 /usr/local/webserver/nginx/restart.sh
以后修改了 nginx.conf,php-fpm.conf,fcgi.conf 3个文件中的配置参数,都只需要运行以下shell命令即可重启nginx和PHP服务:
/usr/local/webserver/nginx/restart.sh
如果要停止NGINX服务,则执行:
kill -TERM `cat /usr/local/webserver/nginx/nginx.pid`
编写每天定时切割Nginx日志的脚本
1、创建脚本/usr/local/webserver/nginx/sbin/cut_nginx_log.sh
vim /usr/local/webserver/nginx/sbin/cut_nginx_log.sh
输入以下内容:
# This script run at 00:00
# The Nginx logs path
logs_path=”/usr/local/webserver/nginx/logs/”
mkdir -p ${logs_path}$(date -d “yesterday” +”%Y”)/$(date -d “yesterday” +”%m”)/
mv ${logs_path}access.log ${logs_path}$(date -d “yesterday” +”%Y”)/$(date -d “yesterday” +”%m”)/access_$(date -d “yesterday” +”%Y%m%d”).log
kill -USR1 `cat /usr/local/webserver/nginx/nginx.pid`
2、设置crontab,每天凌晨00:00切割nginx访问日志:
crontab -e
输入以下内容并保存:
注:如果无法运行 crontab 命令,可能原因是现在的很多vps没有/bin/vi,导致执行crontab提示/bin/vi 出错.解决方法是安装vim并设置为默认编辑器,方法如下:
1.安装vim
yum install vim-enhanced
2.修改/etc/profile文件,加入
3.让/etc/profile文件修改后立即生效 ,可以使用如下命令:
. /etc/profile
注意: . 和 /etc/profile 有空格
4.运行crontab -e,出现编辑界面,成功。
到此为止,整个环境基本已经全部安装好,不出意外,你已经可以成功的访问到你之前创建的虚拟主机目录 “www.test.com”了,但是凡是也有意外的情况,如果做完这一切,你发现你的服务器环境还是无法解析,请仔细查找原因,笔者就碰到这样的问题。我们一步步来排查:
执行以下命令,查看端口:
netstat -ntal
如果80端口已经在工作,可能是因为防火墙规则阻挡的缘故:
1、停止防火墙:
service iptables stop
2、停止了后在看能否打开网站,如果能,那就确定是防火墙的原因了,我们需要重新配置防火墙的规则:
vim /etc/sysconfig/iptables
3、增加以下内容并保存:
-A RH-Firewall-1-INPUT -m state –state NEW -m tcp -p tcp –dport 3306 -j ACCEPT
4、开启防火墙
service iptables start
如果你的服务器发现访问二级目录时候NGINX无法解析,例如当访问”http://www.test.com/test”时,服务器无法解析到 test目录,而访问”http://www.test.com/test/“则一切正常时:只需在nginx.conf中添加以下一行即可:
至此,大功基本告成。但是笔者配置的这台服务器内存为3G,CPU是双核,所以各个性能参数指标的配置均是按照这个硬件的标准来设置,在实际生产环境中,以上NGINX和PHP的配置在这个硬件换件下表现良好,但是大多数的可能是一个只有几百M内存的VPS主机,或者是自己安装配置的虚拟机环境,所以各项配置参数需要不断调优。下篇我将讲述一下都有哪些配置会影响到NGINX的运行,怎么样的配置才最合理。否则NGINX就容易出现504错误或其他的一些错误。其实这一切都不能算做是NGINX的错,只要各个参数配置合理,这样的情况是完全可以避免的。
发表评论
-
sysctl.conf
2011-07-06 14:54 1764fs.file-max=51200 net.core.net ... -
top的替代工具
2011-06-28 15:06 1475dstat -cgilpymn collectl and ... -
有用的小工具
2010-12-23 11:51 1356pv stream nessus Nikto ski ... -
调优linux i/o 行为
2010-11-25 11:27 2926http://www.westnet.com/~gsmith/ ... -
服务器部署工具
2010-11-12 16:32 2068http://www.linuxlinks.com/artic ... -
开源的配置管理工具
2010-11-12 16:24 1477最佳开源配置管理工具: Puppet / 提名:OpenQ ... -
优化ext3的mount选项
2010-11-12 10:24 1360defaults,commit=600,noatime,nod ... -
恢复r710biso 出厂设置
2010-11-10 10:30 1225ALT+E/F/B -
每进程io监控工具
2010-11-02 14:14 1664iodump iotop iopp pidstat b ... -
Intel Xeon 5500/5600系列 CPU服务器内存设置
2010-11-01 21:29 4857http://www.xasun.com/article/2a ... -
zabbix短信报警脚本文件
2010-10-21 14:28 2794附件 -
天外飞仙级别的Linux Shell命令
2010-10-16 09:59 1471本文编译自commandlinefu.com ( 应该是 Ca ... -
lenny+r710+lvm 重启问题解决方案
2010-10-15 14:22 1135ro rootdelay=10 quiet -
fai,debian 自动安装工具
2010-10-15 13:36 1123http://sys.firnow.com/linux/x80 ... -
十个服务器监控工具
2010-09-26 11:44 1841一位国外的技术博主在 ... -
restrict authorized_keys
2010-09-06 09:45 1269command="/home/someuser/rs ... -
sysctl优化设置
2010-09-05 11:25 1170sysctl 是一个用来在系统运作中查看及调整系统参数的工 ... -
proc文件系统
2010-09-05 11:22 1281什么是proc文件系统? proc文件系统是一个伪 ... -
nfs使用
2010-09-02 17:01 1160http://www.linuxhomenetworking. ... -
lsof example
2010-08-23 12:40 12781、查看文件系统阻塞 ...
相关推荐
nginx-1.6.0.tar.gz mysql-5.6.19.tar.gz php-5.5.14.tar.gz pcre-8.35.tar.gz openssl-1.0.1h.tar.gz ...安装ZIBBIX Nginx1.6.0+MySQL5.6.19+PHP5.5.14 软件包 以上软件包使用WinSCP工具上传到/usr/local/src目录
CentOS7 自动化搭建Nginx+PHP7+Mysql+Docker+Docker-Compose Shell脚本,Docker version 18.06.1-ce,docker-compose version 1.22.0
CentOS 6.2编译安装Nginx1.2.0+MySQL5.5.25+PHP5.3.13+Zend Guard Loader+WordPress-3.3.2中文版.pdf
在本教程中,我们将深入探讨如何在CentOS 7.3.1611操作系统上编译安装Nginx 1.10.3、MySQL 5.7.16和PHP 7.1.2。这个过程对于那些希望自定义安装配置或需要最新版本的开发者来说非常有用。首先,让我们逐一了解每个...
通过以上步骤,我们已经成功在 CentOS 6.5 上安装了 Nginx、PHP 和 MySQL,并完成了基本的配置。需要注意的是,在实际部署过程中可能还会遇到其他问题,比如权限问题、防火墙问题等,需要根据具体情况调整配置。此外...
本文在centos8基础上进行安装,软件版本如下: 名称 版本 安装方式 备注 jdk 13.0.2 rpm Oracle jdk,目前最新版本 nginx 1.16.1 dnf 目前最新版本,1.16.1-1.el8.ngx mysql 8.0.19 dnf 目前最新社区版 tomcat ...
### CentOS 7.0 编译安装 Nginx1.6.0 + MySQL5.6.19 + PHP5.5.14 #### 一、环境准备与配置 ...至此,您已经成功地在 CentOS 7.0 上编译安装了 Nginx1.6.0、MySQL5.6.19 和 PHP5.5.14,搭建了一个完整的 LNMP 环境。
### CentOS 7.0 编译安装 Nginx1.6.0 + MySQL5.6.19 + ...完成以上步骤后,您就已经成功地在 CentOS 7.0 上编译安装了 Nginx1.6.0、MySQL5.6.19 和 PHP5.5.14。这将为您的 Web 项目提供一个强大且稳定的开发环境。
在本教程中,我们将详细介绍如何在CentOS 7.0上编译安装Nginx 1.6.0、MySQL 5.6.19和PHP 5.5.14。这个过程涉及到多个步骤,包括环境配置、依赖库安装、源代码编译以及服务配置。以下是详细的步骤: 1. **系统环境...
综上所述,通过上述步骤可以在 CentOS 系统上搭建一个基于 Nginx + MySQL + PHP 的 Web 服务环境,这种组合通常被称为 LNMP(Linux + Nginx + MySQL + PHP)堆栈。通过这种配置,不仅可以有效提升网站的负载能力,还...
本文档将指导您在CentOS系统上安装nginx、php、mysql、memcache和mongodb五个软件包的傻瓜式安装方法。 Nginx安装 Nginx是一款轻量级的Web服务器软件,常用于构建高性能的Web应用程序。安装Nginx需要先安装依赖库...
centos7安装+tomcat+mysql+jdk+nginx配置步骤,按着步骤走傻子都能做出来,非常详细
CentOs5.5+mysql+nginx+php5.3.3安全安装手册.doc
Windows8上安装虚拟机VirtualBox,然后新建虚拟电脑,搭建CentOS6.5 + mysql + nginx + php + memcached平台环境,部署网站。文档中记录了部分FAQ。
在安装完Apache、PHP和Mysql后,需要对Apache进行配置以便支持PHP和与Mysql的交互。 - 修改Apache配置文件`httpd.conf`,加载PHP模块。 - 设置正确的Mysql模块路径和数据库配置。 - 配置虚拟主机、文档根目录等选项...
本文将详细介绍如何在CentOS7操作系统上配置PHP+nginx+MySQL的环境,以及使用自动脚本来简化这一过程。这个环境是许多网站和应用程序的常用基础架构,它提供了强大的动态内容处理(PHP),高效的静态资源服务(nginx...
以下是在CentOS下安装Nginx、MySQL和PHP及其所需扩展的详细步骤。 首先,我们需要确保系统是最新的。打开终端并运行以下命令来更新CentOS: ```bash sudo yum update -y ``` 接下来,安装一些必要的依赖项,这些...