LNMP构建高可用WEB服务器安装篇

本文涉及的产品
RDS MySQL Serverless 基础系列,0.5-2RCU 50GB
RDS MySQL Serverless 高可用系列,价值2615元额度,1个月
简介:

声明:此文章有部分内容参考网上的一些文章,文章中所有代码在Centos 6.2 X84 64位系统上经过测试。

一、下载软件包

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
wget http://mozbuildtools.googlecode.com/files/libiconv-1.13.1.tar.gz
wget http://acelnmp.googlecode.com/files/mhash-0.9.9.9.tar.gz
wget http://mysql.ntu.edu.tw/Downloads/MySQL-5.5/mysql-5.5.25a.tar.gz
wget http://sysoev.ru/nginx/nginx-0.8.46.tar.gz
wget http://www.php.net/get/php-5.2.14.tar.gz/from/this/mirror
wget http://php-fpm.org/downloads/php-5.2.14-fpm-0.5.14.diff.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 ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-8.10.tar.gz
wget http://bart.eaccelerator.net/source/0.9.6.1/eaccelerator-0.9.6.1.tar.bz2
wget http://pecl.php.net/get/PDO_MYSQL-1.0.2.tgz
wget http://blog.s135.com/soft/linux/nginx_php/imagick/ImageMagick.tar.gz
wget http://pecl.php.net/get/imagick-2.3.0.tgz
wget http://www.cmake.org/files/v2.8/cmake-2.8.4.tar.gz

二、安装依赖软件包

1
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 net-snmp net-snmp-devel nss_ldap openldap-clients openldap-servers libtidy libtidy-devel wget libc-client libc-client-devel pcre pcre-devel

三、安装MySQL

1、安装cmake

1
2
3
tar zxvf cmake-2.8.4.tar.gz
cd $src_dir/cmake-2.8.4
./configure && make && make install

2、安装mysql 5.5

1
2
3
4
tar zxvf mysql- 5.5 .25a.tar.gz
cd mysql- 5.5 .25a
cmake . -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DMYSQL_DATADIR=/usr/local/mysql/data -DSYSCONFDIR=/etc -DWITH_INNOBASE_STORAGE_ENGINE= 1  -DWITH_ARCHIVE_STORAGE_ENGINE= 1  -DWITH_BLACKHOLE_STORAGE_ENGINE= 1  -DWITH_FEDERATED_STORAGE_ENGINE= 1  -DWITH_PARTITION_STORAGE_ENGINE= 1  -DMYSQL_TCP_PORT= 3306  -DENABLED_LOCAL_INFILE= 1  -DWITH_SSL=yes  -DEXTRA_CHARSETS=all -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DWITH_READLINE=on
gmake && make install

3、创建MySQL数据库存放目录

1
2
3
4
mkdir -p /usr/local/mysql/data
mkdir -p /usr/local/mysql /binlog/
mkdir -p /usr/local/mysql /relaylog/
chown -R mysql:mysql /usr/local/mysql

5、创建mysql配置文件和启动脚本

1
2
3
/bin/cp support-files/my-small.cnf /etc/my.cnf
                                                 
/bin/cp support-files/mysql.server /etc/rc.d/init.d/mysqld

6mysql用户帐号的身份建立数据表:

1
/usr/local/mysql/scripts/mysql_install_db --basedir=/usr/local/mysql/ --datadir=/usr/local/mysql/data/ --user=mysql --defaults-file=/etc/my.cnf

四、安装PHP 5.3.16(php-fpm模式)

1、安装编译安装PHP 5.2.14所需的支持库:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
tar zxvf libiconv- 1.13 . 1 .tar.gz
cd libiconv- 1.13 . 1 /
./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
ln -s /usr/local/bin/libmcrypt-config /usr/bin/libmcrypt-config
                                        
tar zxvf mcrypt- 2.6 . 8 .tar.gz
cd mcrypt- 2.6 . 8 /
/sbin/ldconfig
./configure
make
make install
cd ../

2、编译安装PHP5

1
2
3
4
5
6
tar zxvf php-5.3.13.tar.gz
cd php-5.3.13
./configure --prefix=/usr/local/php --with-config-file-path=/usr/local/php/lib --with-mysql=/usr/local/mysql/bin/mysql_config --with-enable-sysvsem --enable-fpm --with-openssl --with-zlib --with-bz2 --with-curl --with-libxml-dir=/usr --with-gd --with-jpeg-dir --with-png-dir --with-zlib-dir --enable-gd-native-ttf --enable-gd-jis-conv --with-iconv=/use/local/libiconv --with-ldap --with-mcrypt=/usr/local/libmcypt --with-zlib-dir --with-snmp --enable-zip --with-curlwrappers --with-imap --with-kerberos --with-imap-ssl --with-freetype-dir --with-mysql=/usr/local/mysql
make && make install
cp php.ini-development /usr/local/php/lib/php.ini
cp /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf

3、编译安装PHP5扩展模块

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
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.1.tar.bz2
cd eaccelerator-0.9.6.1/
/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 ../

4、修改php.ini文件
手工修改:查找/usr/local /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文件类型错误解析漏洞。

5、配置eAccelerator加速PHP

mkdir -p /usr/local/webserver/eaccelerator_cache

vi /usr/local/webserver/php/etc/php.ini

  按shift+g键跳到配置文件的最末尾,加上以下配置信息:

引用

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
[eaccelerator]
zend_extension="/usr/local/php/lib/php/extensions/no-debug-non-zts-20060613/eaccelerator.so"
eaccelerator.shm_size="64"
accelerator.cache_dir="/usr/local/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"

五、安装Nginx 0.8.46


1、安装Nginx所需的pcre库:  yum -y install pcre pcre-devel


2、安装Nginx

1
2
3
4
5
tar zxvf nginx-0.8.46.tar.gz
cd nginx-0.8.46/
./configure --user=www --group=www --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module
make && make install
cd ../

4nginx配置文件模板

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
user  nobody; 
worker_processes  1;
            
pid        logs/nginx.pid;
worker_rlimit_nofile 65535;
            
events {
     worker_connections  65535;
}
http {
     include       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  logs/access.log  main;
            
     sendfile        on;
     tcp_nopush     on;
            
     #keepalive_timeout  0;
     keepalive_timeout  300;
     proxy_connect_timeout 300;
     proxy_read_timeout 600;
     proxy_send_timeout 600;
     proxy_buffer_size 64k;
     proxy_buffers 4 32k;
     proxy_busy_buffers_size 64k;
            
     gzip  on;
     gzip_min_length 1000;
     gzip_buffers        4 8k;
     gzip_comp_level     3;
     gzip_types text/plain text/css application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript;
              
       server
       {
         listen  80;
             server_name  status.chlinux.net;
            
          location / {
          stub_status on;
             access_log   off;
         }
       }
     server {
         listen       80;
         server_name  www.chlinux.net chlinux.net;
     root   html/;
             index  index.php index.html index.htm;
         location / {
             root   html/;
             index  index.php index.html index.htm;
         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 /nginx_status {
                  stub_status on;
                  access_log off;
               }
             }
         error_page   500 502 503 504  /50x.html;
         location = /50x.html {
             root   html;
         }
         location ~ \.php$ {
            root           html;
             fastcgi_pass   127.0.0.1:9000;
             fastcgi_index  index.php;
         fastcgi_param  SCRIPT_FILENAME  /usr/local/nginx/html$fastcgi_script_name;
             include        fastcgi.conf;
         }
     }

本文转自1594cqb 51CTO博客,原文链接:http://blog.51cto.com/wolfchen/1204773,如需转载请自行联系原作者

相关实践学习
基于CentOS快速搭建LAMP环境
本教程介绍如何搭建LAMP环境,其中LAMP分别代表Linux、Apache、MySQL和PHP。
全面了解阿里云能为你做什么
阿里云在全球各地部署高效节能的绿色数据中心,利用清洁计算为万物互联的新世界提供源源不断的能源动力,目前开服的区域包括中国(华北、华东、华南、香港)、新加坡、美国(美东、美西)、欧洲、中东、澳大利亚、日本。目前阿里云的产品涵盖弹性计算、数据库、存储与CDN、分析与搜索、云通信、网络、管理与监控、应用服务、互联网中间件、移动服务、视频服务等。通过本课程,来了解阿里云能够为你的业务带来哪些帮助     相关的阿里云产品:云服务器ECS 云服务器 ECS(Elastic Compute Service)是一种弹性可伸缩的计算服务,助您降低 IT 成本,提升运维效率,使您更专注于核心业务创新。产品详情: https://www.aliyun.com/product/ecs
相关文章
|
21小时前
|
缓存 监控 API
利用Python构建高性能的Web API后端服务
随着微服务架构的普及和RESTful API的广泛应用,构建高性能、可扩展的Web API后端服务变得尤为重要。本文将探讨如何利用Python这一强大且灵活的语言,结合现代Web框架和工具,构建高效、可靠的Web API后端服务。我们将分析Python在Web开发中的优势,介绍常用的Web框架,并通过实际案例展示如何设计并实现高性能的API服务。
|
1天前
|
前端开发 Java Go
从前端到后端:构建现代化Web应用的技术实践
本文将介绍如何通过前端和后端技术相结合,构建现代化Web应用的技术实践。我们将探讨前端开发、后端架构以及多种编程语言(如Java、Python、C、PHP、Go)在构建高效、可扩展的Web应用中的应用。
|
1天前
|
JavaScript 前端开发 API
Vue中的组件:构建现代Web应用的基石
Vue中的组件:构建现代Web应用的基石
|
1天前
|
前端开发 JavaScript 开发者
深入理解MVC和MVVM:构建现代Web应用的利器
深入理解MVC和MVVM:构建现代Web应用的利器
|
2天前
|
应用服务中间件 网络安全 Apache
构建高性能Web服务器:Nginx vs Apache
【5月更文挑战第16天】Nginx与Apache是两种主流Web服务器,各具优势。Nginx以其轻量级、高并发处理能力和反向代理功能见长,适合大型网站和高并发场景;而Apache以功能丰富、稳定性强闻名,适合企业网站和需要多种Web服务功能的场景。在性能上,Nginx处理高并发更优,Apache则可能在高负载时遭遇瓶颈。在选择时,应根据实际需求权衡。
|
2天前
|
JSON JavaScript API
使用 Node.js 开发一个简单的 web 服务器响应 HTTP post 请求
使用 Node.js 开发一个简单的 web 服务器响应 HTTP post 请求
9 1
|
2天前
|
JSON JavaScript 中间件
使用 Node.js 开发一个简单的 web 服务器响应 HTTP get 请求
使用 Node.js 开发一个简单的 web 服务器响应 HTTP get 请求
9 2
|
3天前
|
负载均衡 Go 调度
使用Go语言构建高性能的Web服务器:协程与Channel的深度解析
在追求高性能Web服务的今天,Go语言以其强大的并发性能和简洁的语法赢得了开发者的青睐。本文将深入探讨Go语言在构建高性能Web服务器方面的应用,特别是协程(goroutine)和通道(channel)这两个核心概念。我们将通过示例代码,展示如何利用协程处理并发请求,并通过通道实现协程间的通信和同步,从而构建出高效、稳定的Web服务器。
|
3天前
|
弹性计算 运维 监控
解密阿里云弹性计算:探索云服务器ECS的核心功能
阿里云ECS是核心计算服务,提供弹性云服务器资源,支持实例按需配置、集群管理和监控,集成安全防护,确保服务稳定、安全,助力高效业务运营。
80 0
|
1天前
|
弹性计算 运维 安全
阿里云ecs使用体验
整了台服务器部署项目上线