配置Linux+Nginx+PHP+MySQL运行环境

本文涉及的产品
RDS MySQL Serverless 基础系列,0.5-2RCU 50GB
云数据库 RDS MySQL,集群系列 2核4GB
推荐场景:
搭建个人博客
云数据库 RDS PostgreSQL,集群系列 2核4GB
简介:

(1)删除Linux系统默认安装的web服务器软件包,如:httpd、mysql、php等,卸载可以用以下命令

[root@test.com~]#rpm -e httpd
[root@test.com~]#rpm -e php
[root@test.com~]#rpm -e mysql

(2)使用yum更新系统组件

[root@test.com~]#yum -y install yum-fastestmirror
[root@test.com~]#yum -y update
[root@test.com~]#yum -y install patch make gcc gcc-c++ gcc-g77 flex bison file
[root@test.com~]#yum -y install libtool libtool-libs autoconf kernel-devel
[root@test.com~]#yum -y install libjpeg libjpeg-devel libpng libpng-devel libpng10 libpng10-devel gd gd-devel
[root@test.com~]#yum -y install freetype freetype-devel libxml2 libxml2-devel zlib zlib-devel
[root@test.com~]#yum -y install glib2 glib2-devel bzip2 bzip2-devel libevent libevent-devel
[root@test.com~]#yum -y install ncurses ncurses-devel curl curl-devel e2fsprogs
[root@test.com~]#yum -y install openssl openssl-devel vim-minimal nano sendmail
[root@test.com~]#yum -y install fonts-chinese gettext gettext-devel
[root@test.com~]#yum -y install ncurses-devel
[root@test.com~]#yum -y install gmp-devel pspell-devel
[root@test.com~]#yum -y install unzip

(3)准备安装需要使用的软件包,使用wget下载
>1.php-5.2.10
>2.php-5.2.10-fpm-0.5.13
>3.sohusin-patch-5.2.10-0.9.7.patch.gz
>4.PDO_MySQL-1.0.2
>5.memcache2.2.5
>6.Pcre7.9
>7.Nginx0.7.65
>8.MySQL5.1.44
>9.libiconv
>10.libmcrypt
>11.mhash
>12.mcrypt

Part 2.安装
//install libiconv

[root@test.com~]#tar zxvf libiconv-1.13.tar.gz
[root@test.com~]#cd libiconv-1.13/
[root@test.com~]#./configure --prefix=/usr/local
[root@test.com~]#make && make install
[root@test.com~]#cd ../
//install libmcrypt
[code]
[root@test.com~]#tar zxvf libmcrypt-2.5.8.tar.gz
[root@test.com~]#cd libmcrypt-2.5.8/
[root@test.com~]#./configure
[root@test.com~]#make && make install
[root@test.com~]#/sbin/ldconfig
[root@test.com~]#cd libltdl/
[root@test.com~]#./configure --enable-ltdl-install
[root@test.com~]#make && make install
[root@test.com~]#cd ../../

//install mhash

[root@test.com~]#tar zxvf mhash-0.9.9.9.tar.gz
[root@test.com~]#cd mhash-0.9.9.9/
[root@test.com~]#./configure
[root@test.com~]#make && make install
[root@test.com~]#cd ../

//使用ln -s 命令给lib组件建立软连接

[root@test.com~]#ln -s /usr/local/lib/libmcrypt.la /usr/lib/libmcrypt.la
[root@test.com~]#ln -s /usr/local/lib/libmcrypt.so /usr/lib/libmcrypt.so
[root@test.com~]#ln -s /usr/local/lib/libmcrypt.so.4 /usr/lib/libmcrypt.so.4
[root@test.com~]#ln -s /usr/local/lib/libmcrypt.so.4.4.8 /usr/lib/libmcrypt.so.4.4.8
[root@test.com~]#ln -s /usr/local/lib/libmhash.a /usr/lib/libmhash.a
[root@test.com~]#ln -s /usr/local/lib/libmhash.la /usr/lib/libmhash.la
[root@test.com~]#ln -s /usr/local/lib/libmhash.so /usr/lib/libmhash.so
[root@test.com~]#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

//install mcrypt

[root@test.com~]#tar zxvf mcrypt-2.6.8.tar.gz
[root@test.com~]#cd mcrypt-2.6.8/
[root@test.com~]#./configure
[root@test.com~]#make && make install
[root@test.com~]#cd ../

//install mysql

[root@test.com~]#tar -zxvf mysql-5.1.44.tar.gz
[root@test.com~]#cd mysql-5.1.44/
[root@test.com~]#./configure --prefix=/usr/local/mysql --with-extra-charsets=all --enable-thread-safe-client --enable-assembler --with-charset=utf8 --enable-thread-safe-client --with-extra-charsets=all --with-big-tables --with-readline --with-ssl --with-embedded-server --enable-local-infile
[root@test.com~]#make && make install
[root@test.com~]#cd ../

//使用独立用户运行mysql

[root@test.com~]#groupadd mysql
[root@test.com~]#useradd -g mysql mysql
[root@test.com~]#cp /usr/local/mysql/share/mysql/my-medium.cnf /etc/my.cnf
[root@test.com~]#/usr/local/mysql/bin/mysql_install_db --user=mysql
[root@test.com~]#chown -R mysql /usr/local/mysql/var
[root@test.com~]#chgrp -R mysql /usr/local/mysql/.
[root@test.com~]#cp /usr/local/mysql/share/mysql/mysql.server /etc/init.d/mysql
[root@test.com~]#chmod 755 /etc/init.d/mysql
[root@test.com~]#chkconfig --level 345 mysql on
[root@test.com~]#echo "/usr/local/mysql/lib/mysql" >> /etc/ld.so.conf
[root@test.com~]#echo "/usr/local/lib" >>/etc/ld.so.conf

[root@test.com~]#ldconfig
[root@test.com~]#ln -s /usr/local/mysql/lib/mysql /usr/lib/mysql
[root@test.com~]#ln -s /usr/local/mysql/include/mysql /usr/include/mysql
[root@test.com~]#/etc/init.d/mysql start
[root@test.com~]#/usr/local/mysql/bin/mysqladmin -u root password $pwd(这里换成自己的密码)
[root@test.com~]#/etc/init.d/mysql restart
[root@test.com~]#/etc/init.d/mysql stop
[root@test.com~]#chkconfig mysql-ndb off
[root@test.com~]#chkconfig mysql-ndb-mgm off

//install php

[root@test.com~]#tar zxvf php-5.2.10.tar.gz
[root@test.com~]#gzip -d ./suhosin-patch-5.2.10-0.9.7.patch.gz 
[root@test.com~]#gzip -cd php-5.2.10-fpm-0.5.13.diff.gz | patch -d php-5.2.10 -p1
[root@test.com~]#cd php-5.2.10/
[root@test.com~]#patch -p 1 -i ../suhosin-patch-5.2.10-0.9.7.patch
[root@test.com~]#./buildconf --force
[root@test.com~]#./configure --prefix=/usr/local/php --with-config-file-path=/usr/local/php/etc --with-mysql=/usr/local/mysql --with-mysqli=/usr/local/mysql/bin/mysql_config --with-iconv-dir --with-freetype-dir --with-jpeg-dir --with-png-dir --with-zlib --with-libxml-dir=/usr --enable-xml --disable-rpath --enable-discard-path --enable-magic-quotes --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 --enable-ftp --with-gd --enable-gd-native-ttf --with-openssl --with-mhash --enable-pcntl --enable-sockets --with-xmlrpc --enable-zip --enable-soap --without-pear --with-gettext --with-mime-magic --enable-suhosin
make ZEND_EXTRA_LIBS=-liconv
[root@test.com~]#make install
[root@test.com~]#cp php.ini-dist /usr/local/php/etc/php.ini
[root@test.com~]#cd ../

//install memcache

[root@test.com~]#tar zxvf memcache-2.2.5.tgz
[root@test.com~]#cd memcache-2.2.5/
[root@test.com~]#/usr/local/php/bin/phpize
[root@test.com~]#./configure --with-php-config=/usr/local/php/bin/php-config
[root@test.com~]#make && make install
[root@test.com~]#cd ../

//install PDO_MySQL

[root@test.com~]#tar zxvf PDO_MYSQL-1.0.2.tgz
[root@test.com~]#cd PDO_MYSQL-1.0.2/
[root@test.com~]#/usr/local/php/bin/phpize
[root@test.com~]#./configure --with-php-config=/usr/local/php/bin/php-config --with-pdo-mysql=/usr/local/mysql
[root@test.com~]#make
[root@test.com~]#make install
[root@test.com~]#cd ../

[root@permit~]#groupadd www
[root@permit~]#useradd -g www www
[root@permit~]#mkdir -p /web/wwwroot
[root@permit~]#chmod +w /web/wwwroot
[root@permit~]#mkdir -p /web/wwwroot/logs
[root@permit~]#chmod 777 /web/wwwroot/logs

//install pcre

[root@test.com~]#tar zxvf pcre-7.9.tar.gz
[root@test.com~]#cd pcre-7.9/
[root@test.com~]#./configure
[root@test.com~]#make && make install
[root@test.com~]#cd ../

//install nginx

[root@test.com~]#tar zxvf nginx-0.7.65.tar.gz
[root@test.com~]#cd nginx-0.7.65/
[root@test.com~]#./config



nginx限制ip并发数,也是说限制同一个ip同时连接服务器的数量

1.添加limit_zone 
这个变量只能在http使用 
vi /usr/local/nginx/conf/nginx.conf 
limit_zone one $remote_addr 10m;

2.添加limit_conn 
这个变量可以在http, server, location使用 
我只限制一个站点,所以添加到server里面 
vi /usr/local/nginx/conf/host/gaojinbo.com.conf 
limit_conn   one 10;

3.重启nginx 
killall -HUP nginx

nginx 限速模块
参考:

关于limit_zone:http://wiki.nginx.org/NginxHttpLimitZoneModule 
关于limit_rate和limit_conn:http://wiki.nginx.org/NginxHttpCoreModule 
nginx可以通过HTTPLimitZoneModule和HTTPCoreModule两个组件来对目录进行限速。

http { 
  limit_zone   one  $binary_remote_addr  10m;  
  server { 
    location /download/ { 
      limit_conn   one  1; 
      limit_rate 300k; 
    } 
  } 
}

limit_zone,是针对每个IP定义一个存储session状态的容器。这个示例中定义了一个10m的容器,按照32bytes/session,可以处理320000个session。

limit_conn one 1;
限制每个IP只能发起一个并发连接

limit_rate 300k;
对每个连接限速300k. 注意,这里是对连接限速,而不是对IP限速。如果一个IP允许两个并发连接,那么这个IP就是限速limit_rate×2。





#运行用户   

user nobody nobody;   

#启动进程   

worker_processes 2;   

#全局错误日志及PID文档   

error_log logs/error.log notice;   

pid logs/Nginx.pid;   

#工作模式及连接数上限   

events {   

use epoll;   

worker_connections 1024;   

}   

#设定http服务器,利用他的反向代理功能提供负载均衡支持   

http {   

#设定mime类型   

include conf/mime.types;   

default_type application/octet-stream;   

#设定日志格式   

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

'"$request" $status $bytes_sent '   

'"$http_referer" "$http_user_agent" '   

'"$gzip_ratio"';   

log_format download '$remote_addr - $remote_user [$time_local] '   

'"$request" $status $bytes_sent '   

'"$http_referer" "$http_user_agent" '   

'"$http_range" "$sent_http_content_range"';   

#设定请求缓冲   

client_header_buffer_size 1k;   

large_client_header_buffers 4 4k;   

#开启gzip模块   

gzip on;   

gzip_min_length 1100;   

gzip_buffers 4 8k;   

gzip_types text/plain;   

output_buffers 1 32k;   

postpone_output 1460;   

#设定access log   

access_log logs/access.log main;   

client_header_timeout 3m;   

client_body_timeout 3m;   

send_timeout 3m;   

sendfile on;   

tcp_nopush on;   

tcp_nodelay on;   

keepalive_timeout 65;   

#设定负载均衡的服务器列表   

upstream mysvr {   

#weigth参数表示权值,权值越高被分配到的几率越大   

#本机上的Squid开启3128端口   

server 192.168.8.1:3128 weight=5;   

server 192.168.8.2:80 weight=1;   

server 192.168.8.3:80 weight=6;   

}   

#设定虚拟主机   

server {   

listen 80;   

server_name 192.168.8.1   

www.yejr.com   

;   

charset gb2312;   

#设定本虚拟主机的访问日志   

access_log logs/www.yejr.com.access.log main;   

#假如访问 /img/*, /js/*, /css/* 资源,则直接取本地文档,不通过squid   

#假如这些文档较多,不推荐这种方式,因为通过squid的缓存效果更好   

location ~ ^/(img|js|css)/ {   

root /data3/Html;   

expires 24h;   

}   

#对 "/" 启用负载均衡   

location / {   

proxy_pass http://mysvr;   

proxy_redirect off;   

proxy_set_header Host $host;   

proxy_set_header X-Real-IP $remote_addr;   

proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;   

client_max_body_size 10m;   

client_body_buffer_size 128k;   

proxy_connect_timeout 90;   

proxy_send_timeout 90;   

proxy_read_timeout 90;   

proxy_buffer_size 4k;   

proxy_buffers 4 32k;   

proxy_busy_buffers_size 64k;   

proxy_temp_file_write_size 64k;   

}   

#设定查看Nginx状态的地址   

location /NginxStatus {   

stub_status on;   

access_log on;   

auth_basic "NginxStatus";   

auth_basic_user_file conf/htpasswd;   

}   

}   

}  

备注:conf/htpasswd 文档的内容用 apache 提供的 htpasswd 工具来产生即可,内容大致如下:


3.) 查看 Nginx 运行状态 输入地址http://192.168.8.1/NginxStatus/ 。输入验证帐号密码,即可看到类似如下内容:


Active connections: 328   

server accepts handled requests   

9309 8982 28890   

Reading: 1 Writing: 3 Waiting: 324  

第一行表示现在活跃的连接数,第三行的第三个数字表示Nginx运行到。



  1. worker_processes 1;  

  2. events {  

  3. worker_connections 1024;  

  4. }  

  5. http{  

  6. upstream myproject {  

  7. #这里指定多个源服务器,ip:端口,80端口的话可写可不写  

  8. server 192.168.43.158:80;  

  9. server 192.168.41.167;  

  10. }  

  11. server {  

  12. listen 8080;  

  13. location / {  

  14. proxy_pass http://myproject;  

  15. }  

  16. }  











本文转自 chengxuyonghu 51CTO博客,原文链接:http://blog.51cto.com/6226001001/1557250,如需转载请自行联系原作者
相关实践学习
如何快速连接云数据库RDS MySQL
本场景介绍如何通过阿里云数据管理服务DMS快速连接云数据库RDS MySQL,然后进行数据表的CRUD操作。
全面了解阿里云能为你做什么
阿里云在全球各地部署高效节能的绿色数据中心,利用清洁计算为万物互联的新世界提供源源不断的能源动力,目前开服的区域包括中国(华北、华东、华南、香港)、新加坡、美国(美东、美西)、欧洲、中东、澳大利亚、日本。目前阿里云的产品涵盖弹性计算、数据库、存储与CDN、分析与搜索、云通信、网络、管理与监控、应用服务、互联网中间件、移动服务、视频服务等。通过本课程,来了解阿里云能够为你的业务带来哪些帮助     相关的阿里云产品:云服务器ECS 云服务器 ECS(Elastic Compute Service)是一种弹性可伸缩的计算服务,助您降低 IT 成本,提升运维效率,使您更专注于核心业务创新。产品详情: https://www.aliyun.com/product/ecs
目录
相关文章
|
28天前
|
Ubuntu Unix Linux
Linux网络文件系统NFS:配置与管理指南
NFS 是 Linux 系统中常用的网络文件系统协议,通过配置和管理 NFS,可以实现跨网络的文件共享。本文详细介绍了 NFS 的安装、配置、管理和常见问题的解决方法,希望对您的工作有所帮助。通过正确配置和优化 NFS,可以显著提高文件共享的效率和安全性。
178 7
|
2月前
|
数据库连接 Linux Shell
Linux下ODBC与 南大通用GBase 8s数据库的无缝连接配置指南
本文详细介绍在Linux系统下配置GBase 8s数据库ODBC的过程,涵盖环境变量设置、ODBC配置文件编辑及连接测试等步骤。首先配置数据库环境变量如GBASEDBTDIR、PATH等,接着修改odbcinst.ini和odbc.ini文件,指定驱动路径、数据库名称等信息,最后通过catalog.c工具或isql命令验证ODBC连接是否成功。
|
2月前
|
缓存 资源调度 安全
深入探索Linux操作系统的心脏——内核配置与优化####
本文作为一篇技术性深度解析文章,旨在引领读者踏上一场揭秘Linux内核配置与优化的奇妙之旅。不同于传统的摘要概述,本文将以实战为导向,直接跳入核心内容,探讨如何通过精细调整内核参数来提升系统性能、增强安全性及实现资源高效利用。从基础概念到高级技巧,逐步揭示那些隐藏在命令行背后的强大功能,为系统管理员和高级用户打开一扇通往极致性能与定制化体验的大门。 --- ###
93 9
|
2月前
|
存储 安全 数据管理
如何在 Rocky Linux 8 上安装和配置 Elasticsearch
本文详细介绍了在 Rocky Linux 8 上安装和配置 Elasticsearch 的步骤,包括添加仓库、安装 Elasticsearch、配置文件修改、设置内存和文件描述符、启动和验证 Elasticsearch,以及常见问题的解决方法。通过这些步骤,你可以快速搭建起这个强大的分布式搜索和分析引擎。
88 5
|
3月前
|
Java Linux 网络安全
NIFI在Linux服务区上的部署配置过程是什么?
【10月更文挑战第21天】NIFI在Linux服务区上的部署配置过程是什么?
107 2
|
2月前
|
缓存 应用服务中间件 网络安全
Nginx中配置HTTP2协议的方法
Nginx中配置HTTP2协议的方法
190 7
|
3月前
|
应用服务中间件 BI nginx
Nginx的location配置详解
【10月更文挑战第16天】Nginx的location配置详解
|
3月前
|
缓存 负载均衡 安全
Nginx常用基本配置总结:从入门到实战的全方位指南
Nginx常用基本配置总结:从入门到实战的全方位指南
450 0
|
2月前
|
负载均衡 监控 应用服务中间件
配置Nginx反向代理时如何指定后端服务器的权重?
配置Nginx反向代理时如何指定后端服务器的权重?
190 61
|
1月前
|
存储 应用服务中间件 nginx
nginx反向代理bucket目录配置
该配置实现通过Nginx代理访问阿里云OSS存储桶中的图片资源。当用户访问代理域名下的图片URL(如 `http://代理域名/123.png`)时,Nginx会将请求转发到指定的OSS存储桶地址,并重写路径为 `/prod/files/2024/12/12/123.png`。
80 5