Centos yum 安装nginx+PHP-FPM+eAccelerator+mysql
时间:2016-07-17 21:51 来源:linux.it.net.cn 作者:IT
一、添加安装源
Centos 默认官方源中没有nginx 和 php-fpm 所以必须添加第三方源,不然就只能自己编译了。
添加[CentALT]源
在/etc/yum.repo.d 目下创建 alt.ru.repo 文件内容如下:
[CentALT]
name=CentALT Packages for Enterprise Linux 5 - $basearch
baseurl=http://centos.alt.ru/repository/centos/5/$basearch/
enabled=1
gpgcheck=0
添加[epel]源
在/etc/yum.repo.d 目下创建 epel.repo 文件内容如下:
[epel]
name=Extra Packages for Enterprise Linux 5 - $basearch
#baseurl=http://download.fedoraproject.org/pub/epel/5/$basearch
mirrorlist=http://mirrors.fedoraproject.org/mirrorlist?repo=epel-5&arch=$basearch
failovermethod=priority
enabled=1
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL
[epel-debuginfo]
name=Extra Packages for Enterprise Linux 5 - $basearch - Debug
#baseurl=http://download.fedoraproject.org/pub/epel/5/$basearch/debug
mirrorlist=http://mirrors.fedoraproject.org/mirrorlist?repo=epel-debug-5&arch=$basearch
failovermethod=priority
enabled=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL
gpgcheck=1
[epel-source]
name=Extra Packages for Enterprise Linux 5 - $basearch - Source
#baseurl=http://download.fedoraproject.org/pub/epel/5/SRPMS
mirrorlist=http://mirrors.fedoraproject.org/mirrorlist?repo=epel-source-5&arch=$basearch
failovermethod=priority
enabled=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL
gpgcheck=1
二、启用 EPEL
64系统的用下面命令
rpm -Uvh http://download.fedora.redhat.com/pub/epel/5/x86_64/epel-release-5-4.noarch.rpm
32系统的用下面命令
rpm -Uvh http://download.fedora.redhat.com/pub/epel/5/i386/epel-release-5-4.noarch.rpm
上面的连接已经失效了,现在使用下面的,根据不同的版本选择(5.0和6.0两个版本)
CentOS 6.0
rpm -Uvh http://download.fedoraproject.org/pub/epel/6/i386/epel-release-6-5.noarch
http://mirrors.ustc.edu.cn/fedora/epel/6/x86_64/epel-release-6-8.noarch.rpm
CentOS 5.0
rpm -Uvh http://mirrors.ustc.edu.cn/fedora/epel/5/i386/epel-release-5-4.noarch.rpm
或者到这网站下载 http://mirrors.neusoft.edu.cn/
或者 http://mirrors.ustc.edu.cn/fedora/epel/ 下载
epel-release-6.x noarch.rpm
三、安装 nginx +PHP-FPM +eAccelerator +mysql(当前Nginx为1.04)
1、更新系统
yum update
2、yum方式安装nginx+php+mysql yum install nginx php-fpm php-cli php-pdo php-mysql php-mcrypt php-mbstring php-gd php-tidy php-xml php-xmlrpc php-pear php-pecl-memcache php-eaccelerator mysql mysql-server msyql-libs mysql-devel
3、配置优化Nginx 修改 /etc/nginx/nginx.conf,红色部分是要修改的地方,请注意。
#vi /etc/nginx/nginx.conf
user nginx; worker_processes 4; worker_rlimit_nofile 100000;
error_log /var/log/nginx/error.log; #error_log /var/log/nginx/error.log notice; #error_log /var/log/nginx/error.log info;
pid /var/run/nginx.pid;
#启用epoll
events { worker_connections 1024; use epoll; }
http { include /etc/nginx/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 /var/log/nginx/access.log main;
sendfile on; tcp_nopush on; tcp_nodelay on; server_tokens off; gzip on; gzip_static on; gzip_comp_level 5; gzip_min_length 1024; keepalive_timeout 65; limit_zone myzone $binary_remote_addr 10m;
#fastcgi优化 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 256k;
# Load config files from the /etc/nginx/conf.d directory include /etc/nginx/conf.d/*.conf;
server { limit_conn myzone 10; listen 80; server_name ftp.htsprings.com.cn;
charset UTF-8;
#access_log logs/host.access.log main;
location / { root /var/www/html; index index.php; }
error_page 404 /404.html;
location = /404.html { root /usr/share/nginx/html; }
# redirect server error pages to the static page /50x.html # error_page 500 502 503 504 /50x.html; location = /50x.html { root /usr/share/nginx/html; }
# proxy the PHP scripts to Apache listening on 127.0.0.1:80 # #location ~ \.php$ { # proxy_pass http://127.0.0.1; #}
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000 # location ~ \.php$ { root /var/www/html; fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; #fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name; include fastcgi_params; }
# deny access to .htaccess files, if Apache's document root # concurs with nginx's on e # #location ~ /\.ht { # deny all; #} }
# another virtual host using mix of IP-, name-, and port-based configuration # #server { # listen 8000; # listen somename:8080; # server_name somename alias another.alias;
# location / { # root html; # index index.html index.htm; # } #}
# HTTPS server # #server { # listen 443; # server_name localhost;
# ssl on; # ssl_certificate cert.pem; # ssl_certificate_key cert.key;
# ssl_session_timeout 5m;
# ssl_protocols SSLv2 SSLv3 TLSv1; # ssl_ciphers ALL:!ADH:!EXPORT56:RC4+RSA:+HIGH:+MEDIUM:+LOW:+SSLv2:+EXP; # ssl_prefer_server_ciphers on;
# location / { # root html; # index index.html index.htm; #}
} 4、php-fpm 调整 修改/etc/php-fpm.conf 将max_children 调为20
<value name="max_children">20</value>mysql 调整
5、修改/etc/my.conf [mysqld] 段加入如下指令
skip-network skip-innodb skip-locking skip-bdb key_buffer = 16K max_allowed_packet = 3M thread_stack = 64K thread_cache_size = 8 table_cache = 3 query_cache_limit = 1M query_cache_size = 16M系统内核调整
6、在/etc/sysctl.conf 加入
net.ipv4.tcp_fin_timeout = 30 net.ipv4.tcp_keepalive_time = 300 net.ipv4.tcp_tw_reuse = 1 net.ipv4.tcp_tw_recycle = 1 net.ipv4.ip_local_port_range = 5000 65000 net.ipv4.tcp_max_tw_buckets = 6000
echo “ulimit -SHn 65535” >> /etc/rc.local sysctl -p开启服务并设置系统启动默认启动
ulimit -SHn 65535
7、启动相关服务
/etc/init.d/nginx start /etc/init.d/php-fpm start /etc/init.d/mysqld start chkconfig nginx on chkconfig php-fpm on chkconfig mysqld on
完成后在你的主目录/var/www/html(我将nginx的home目录更改了,默认不是这个)下建立一个index.php文件进行测试,一般不会有什么问题的!
<?
phpinfo();
?>
(责任编辑:IT)
一、添加安装源
添加[CentALT]源
[CentALT] 添加[epel]源 在/etc/yum.repo.d 目下创建 epel.repo 文件内容如下:
[epel]
[epel-debuginfo]
[epel-source] 二、启用 EPEL
64系统的用下面命令 上面的连接已经失效了,现在使用下面的,根据不同的版本选择(5.0和6.0两个版本) CentOS 6.0 rpm -Uvh http://download.fedoraproject.org/pub/epel/6/i386/epel-release-6-5.noarch http://mirrors.ustc.edu.cn/fedora/epel/6/x86_64/epel-release-6-8.noarch.rpm CentOS 5.0 rpm -Uvh http://mirrors.ustc.edu.cn/fedora/epel/5/i386/epel-release-5-4.noarch.rpm 或者到这网站下载 http://mirrors.neusoft.edu.cn/ 或者 http://mirrors.ustc.edu.cn/fedora/epel/ 下载 epel-release-6.x noarch.rpm 三、安装 nginx +PHP-FPM +eAccelerator +mysql(当前Nginx为1.04) 1、更新系统 yum update 2、yum方式安装nginx+php+mysql yum install nginx php-fpm php-cli php-pdo php-mysql php-mcrypt php-mbstring php-gd php-tidy php-xml php-xmlrpc php-pear php-pecl-memcache php-eaccelerator mysql mysql-server msyql-libs mysql-devel 3、配置优化Nginx 修改 /etc/nginx/nginx.conf,红色部分是要修改的地方,请注意。 #vi /etc/nginx/nginx.conf user nginx; worker_processes 4; worker_rlimit_nofile 100000; error_log /var/log/nginx/error.log; #error_log /var/log/nginx/error.log notice; #error_log /var/log/nginx/error.log info; pid /var/run/nginx.pid; #启用epoll events { worker_connections 1024; use epoll; } http { include /etc/nginx/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 /var/log/nginx/access.log main; sendfile on; tcp_nopush on; tcp_nodelay on; server_tokens off; gzip on; gzip_static on; gzip_comp_level 5; gzip_min_length 1024; keepalive_timeout 65; limit_zone myzone $binary_remote_addr 10m; #fastcgi优化 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 256k; # Load config files from the /etc/nginx/conf.d directory include /etc/nginx/conf.d/*.conf; server { limit_conn myzone 10; listen 80; server_name ftp.htsprings.com.cn; charset UTF-8; #access_log logs/host.access.log main; location / { root /var/www/html; index index.php; } error_page 404 /404.html; location = /404.html { root /usr/share/nginx/html; } # redirect server error pages to the static page /50x.html # error_page 500 502 503 504 /50x.html; location = /50x.html { root /usr/share/nginx/html; } # proxy the PHP scripts to Apache listening on 127.0.0.1:80 # #location ~ \.php$ { # proxy_pass http://127.0.0.1; #} # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000 # location ~ \.php$ { root /var/www/html; fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; #fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name; include fastcgi_params; }
# deny access to .htaccess files, if Apache's document root # concurs with nginx's on # another virtual host using mix of IP-, name-, and port-based configuration # #server { # listen 8000; # listen somename:8080; # server_name somename alias another.alias; # location / { # root html; # index index.html index.htm; # } #} # HTTPS server # #server { # listen 443; # server_name localhost; # ssl on; # ssl_certificate cert.pem; # ssl_certificate_key cert.key; # ssl_session_timeout 5m; # ssl_protocols SSLv2 SSLv3 TLSv1; # ssl_ciphers ALL:!ADH:!EXPORT56:RC4+RSA:+HIGH:+MEDIUM:+LOW:+SSLv2:+EXP; # ssl_prefer_server_ciphers on; # location / { # root html; # index index.html index.htm; #} } 4、php-fpm 调整 修改/etc/php-fpm.conf 将max_children 调为20 <value name="max_children">20</value>mysql 调整 5、修改/etc/my.conf [mysqld] 段加入如下指令 skip-network skip-innodb skip-locking skip-bdb key_buffer = 16K max_allowed_packet = 3M thread_stack = 64K thread_cache_size = 8 table_cache = 3 query_cache_limit = 1M query_cache_size = 16M系统内核调整 6、在/etc/sysctl.conf 加入 net.ipv4.tcp_fin_timeout = 30 net.ipv4.tcp_keepalive_time = 300 net.ipv4.tcp_tw_reuse = 1 net.ipv4.tcp_tw_recycle = 1 net.ipv4.ip_local_port_range = 5000 65000 net.ipv4.tcp_max_tw_buckets = 6000 echo “ulimit -SHn 65535” >> /etc/rc.local sysctl -p开启服务并设置系统启动默认启动 ulimit -SHn 65535 7、启动相关服务 /etc/init.d/nginx start /etc/init.d/php-fpm start /etc/init.d/mysqld start chkconfig nginx on chkconfig php-fpm on chkconfig mysqld on 完成后在你的主目录/var/www/html(我将nginx的home目录更改了,默认不是这个)下建立一个index.php文件进行测试,一般不会有什么问题的! <? phpinfo(); ?> (责任编辑:IT) |