CentOS6.5 编译搭建类似淘宝大型交互网站 LTMP 详细步

9年前 ( 12-08 ) 4187阅读 0评论
这篇文章最后更新于3398天前,您需要注意相关的内容是否还可用,如有疑问请联系作者!

QQ截图20141208003028.jpg

L:linux

T:tengine

M:mysql

P:php

第一步:安装系统环境需要的软件


yum install -y gcc gcc-c++ autoconf libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel libxml2 libxml2-devel zlib zlib-devel glibc glibc-devel glib2 glib2-devel bzip2 bzip2-devel ncurses ncurses-devel curl curl-devel e2fsprogs e2fsprogs-devel krb5-libs krb5-devel krb5-server libidn libidn-devel openssl openssl-devel openldap openldap-devel nss_ldap openldap-clients openldap-servers

第二步:编译安装PHP所需要的库

mkdir -p /data/soft
mkdir -p /data/src
 
cd /data/src
wget http://lcmp.googlecode.com/files/libiconv-1.13.1.tar.gz
tar zxvf libiconv-1.13.1.tar.gz
cd libiconv-1.13.1
./configure --prefix=/usr/local
make && make install
 
cd ..
wget http://sourceforge.net/projects/mcrypt/files/Libmcrypt/2.5.8/libmcrypt-2.5.8.tar.gz/download
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 ../../
wget http://sourceforge.net/projects/mhash/files/mhash/0.9.9.9/mhash-0.9.9.9.tar.bz2/download
tar jxvf mhash-0.9.9.9.tar.bz2
cd mhash-0.9.9.9
./configure
make && make install
 
echo "/usr/local/lib" >>/etc/ld.so.conf
/sbin/ldconfig
 
cd ..
wget http://vps.googlecode.com/files/mcrypt-2.6.8.tar.gz
tar zxvf mcrypt-2.6.8.tar.gz
cd mcrypt-2.6.8
/sbin/ldconfig
./configure
make && make install

第三步:编译安装mysql

cd /data/src
wget http://dev.mysql.com/get/Downloads/MySQL-5.1/mysql-5.1.72.tar.gz/from/http://cdn.mysql.com/
tar zxvf mysql-5.1.72.tar.gz
cd mysql-5.1.72
/usr/sbin/groupadd mysql
/usr/sbin/useradd -g mysql mysql
./configure --prefix=/data/soft/mysql --enable-assembler --with-extra-charsets=complex --enable-thread-safe-client --with-big-tables --with-readline --with-ssl --with-embedded-server --enable-local-infile
make && make install
 
chown -R mysql:mysql /data/soft/mysql
chmod u+w /data/soft/mysql
mkdir -p /data/database
chown -R mysql:mysql /data/database
以mysql用户帐号的身份建立数据表:
/data/soft/mysql/bin/mysql_install_db --basedir=/data/soft/mysql --datadir=/data/database --user=mysql
创建mysql配置文件
rm -rf /data/soft/mysql/my.cnf
vi /data/soft/mysql/my.cnf

内容如下:
01 [client]
02 port = 3306
03 socket = /tmp/mysql.sock
04 [mysql]
05 no-auto-rehash
06 [mysqld]
07 user = mysql
08 port = 3306
09 socket = /tmp/mysql.sock
10 basedir = /data/soft/mysql
11 datadir = /data/database
12 skip-name-resolve
13 open_files_limit = 600
14 back_log = 20
15 max_connections = 1000
16 max_connect_errors = 200
17 table_cache = 60
18 external-locking = FALSE
19 max_allowed_packet = 16M
20 sort_buffer_size = 128K
21 join_buffer_size = 128K
22 thread_cache_size = 10
23 thread_concurrency = 8
24 query_cache_size = 2M
25 query_cache_limit = 2M
26 query_cache_min_res_unit = 2k
27 default_table_type = MyISAM
28 thread_stack = 192K
29 transaction_isolation = READ-UNCOMMITTED
30 tmp_table_size = 512K
31 max_heap_table_size = 32M
32 long_query_time = 1
33 log_long_format
34 server-id = 1
35 #log-bin = /data/soft/mysql/binlog
36 binlog_cache_size = 2M
37 max_binlog_cache_size = 4M
38 max_binlog_size = 512M
39 expire_logs_days = 7
40 key_buffer_size = 4M
41 read_buffer_size = 1M
42 read_rnd_buffer_size = 2M
43 bulk_insert_buffer_size = 2M
44 myisam_sort_buffer_size = 4M
45 myisam_max_sort_file_size = 10G
46 myisam_max_extra_sort_file_size = 10G
47 myisam_repair_threads = 1
48 myisam_recover
49 [mysqldump]
50 quick
51 max_allowed_packet = 16M

修改mysqld脚本
cp /data/soft/mysql/share/mysql/mysql.server /etc/init.d/mysqld
vi /etc/init.d/mysqld
修改
basedir=/data/soft/mysql
datadir=/data/database
ln -s /data/soft/mysql/my.cnf /etc/my.cnf
启动mysql
service mysqld start
lsof -i:3306
netstat -ntupl |grep 3306
测试登录mysql
/data/soft/mysql/bin/mysql -u root -p
mysql> createdatabase hello;
chkconfig --add mysqld
chkconfig mysqld on
chkconfig --list |grep mysqld
service mysqld restart

第四步:编译安装PHP(FastCGI)
1、安装php-5.2.17
cd /data/src
wget http://cn2.php.net/get/php-5.2.17.tar.gz/from/this/mirror
wget http://php-fpm.org/downloads/php-5.2.17-fpm-0.5.14.diff.gz
wget http://www.92csz.com/downloads/php-5.2.17-max-input-vars.patch
tar zxvf 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
cd php-5.2.17
patch -p1 < ../php-5.2.17-max-input-vars.patch
sed -i "s/\!png_check_sig (sig, 8)/png_sig_cmp (sig, 0, 8)/" ext/gd/libgd/gd_png.c
cp ../fopen_wrappers.c main/ 此处参考FreeBSD下php修改源代码解决nginx虚拟主机防webshell跨目录
./configure --prefix=/data/soft/php --with-config-file-path=/data/soft/php/etc --with-mysql=/data/soft/mysql --with-mysqli=/data/soft/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-ldap --with-ldap-sasl --with-xmlrpc --enable-zip --enable-soap
make ZEND_EXTRA_LIBS='-liconv'
make install
cp php.ini-dist /data/soft/php/etc/php.ini
cd ..
2、编译安装PHP5扩展模块
wget http://pecl.php.net/get/memcache-2.2.6.tgz
tar zxvf memcache-2.2.6.tgz
cd memcache-2.2.6/
/data/soft/php/bin/phpize
./configure --with-php-config=/data/soft/php/bin/php-config
make && make install
cd ..
wget http://lcmp.googlecode.com/files/eaccelerator-0.9.6.1.tar.bz2
tar jxvf eaccelerator-0.9.6.1.tar.bz2
cd eaccelerator-0.9.6.1/
/data/soft/php/bin/phpize
./configure --enable-eaccelerator=shared --with-php-config=/data/soft/php/bin/php-config --without-eaccelerator-use-inode
make && make install
cd ..
wget http://pecl.php.net/get/PDO_MYSQL-1.0.2.tgz
tar zxvf PDO_MYSQL-1.0.2.tgz
cd PDO_MYSQL-1.0.2
/data/soft/php/bin/phpize
./configure --with-php-config=/data/soft/php/bin/php-config --with-pdo-mysql=/data/soft/mysql
make && make install
cd ..
wget http://launchpadlibrarian.net/73608965/ImageMagick-6.7.0-8.tar.gz
tar zxvf ImageMagick-6.7.0-8.tar.gz
cd ImageMagick-6.7.0-8
./configure
make && make install
cd ..
wget http://pecl.php.net/get/imagick-3.0.1.tgz
tar zxvf imagick-3.0.1.tgz
cd imagick-3.0.1
/data/soft/php/bin/phpize
./configure --with-php-config=/data/soft/php/bin/php-config
make && make install
cd ..
3、修改php.ini文件
sed -i "s/output_buffering = Off/output_buffering = On/" /data/soft/php/etc/php.ini
sed -i "s/extension_dir =/; extension_dir =/" /data/soft/php/etc/php.ini
sed -i "s/; cgi.fix_pathinfo=0/cgi.fix_pathinfo=0/" /data/soft/php/etc/php.ini
sed -i 's%;open_basedir =%open_basedir ="/tmp/:/data/www/"%' /data/soft/php/etc/php.ini
sed -i "s/disable_functions =/disable_functions = popen,pentl_exec,passthru,exec,system,scandir,chgrp,chown,shell_exec,proc_open,proc_get_status,ini_alter,ini_alter,ini_restore,dl,pfsockopen,openlog,syslog,readlink,symlink,popepassthru,stream_socket_server,show_source,escapeshellcmd,escapeshellarg,curl_exec,curl_multi_exec,parse_ini_file,assert/" /data/soft/php/etc/php.ini
sed -i "s/expose_php = On/expose_php = Off/" /data/soft/php/etc/php.ini
sed -i "s/display_errors = On/display_errors = Off/" /data/soft/php/etc/php.ini
sed -i "s/log_errors = Off/log_errors = On/" /data/soft/php/etc/php.ini
在php.ini最后添加如下:
extension_dir = "/data/soft/php/lib/php/extensions/no-debug-non-zts-20060613/"
extension = "memcache.so"
extension = "pdo_mysql.so"
extension = "imagick.so"
[eaccelerator]
zend_extension="/data/soft/php/lib/php/extensions/no-debug-non-zts-20060613/eaccelerator.so"
eaccelerator.shm_size="1"
eaccelerator.cache_dir="/data/soft/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"

4、创建eAccelerator缓存目录
mkdir -p /data/soft/eaccelerator_cache

5、创建php-fpm.conf文件
rm /data/soft/php/etc/php-fpm.conf
vi /data/soft/php/etc/php-fpm.conf
内容如下:
001 <?xml version="1.0" ?>  
002 <configuration>  
003    
004   All relative paths in this config are relative to php's install prefix  
005    
006   <section name="global_options">  
007    
008     Pid file  
009     <value name="pid_file">/data/soft/php/logs/php-fpm.pid</value>  
010    
011     Error log file  
012     <value name="error_log">/data/soft/php/logs/php-fpm.log</value>  
013    
014     Log level  
015     <value name="log_level">notice</value>  
016    
017     When this amount of php processes exited with SIGSEGV or SIGBUS ...  
018     <value name="emergency_restart_threshold">10</value>  
019    
020     ... in a less than this interval of time, a graceful restart will be initiated.  
021     Useful to work around accidental curruptions in accelerator's shared memory.  
022     <value name="emergency_restart_interval">1m</value>  
023    
024     Time limit on waiting child's reaction on signals from master  
025     <value name="process_control_timeout">5s</value>  
026    
027     Set to 'no' to debug fpm  
028     <value name="daemonize">yes</value>  
029    
030   </section>  
031    
032   <workers>  
033    
034     <section name="pool">  
035    
036       Name of pool. Used in logs and stats.  
037       <value name="name">default</value>  
038    
039       Address to accept fastcgi requests on.  
040       Valid syntax is 'ip.ad.re.ss:port' or just 'port' or '/path/to/unix/socket'  
041       <value name="listen_address">127.0.0.1:9000</value>  
042    
043       <value name="listen_options">  
044    
045         Set listen(2) backlog  
046         <value name="backlog">-1</value>  
047    
048         Set permissions for unix socket, if one used.  
049         In linux read/write permissions must be set in order to allow connections from web server.  
050         Many BSD-derrived systems allow connections regardless of permissions.  
051         <value name="owner"></value>  
052         <value name="group"></value>  
053         <value name="mode">0666</value>  
054       </value>  
055    
056       Additional php.ini defines, specific to this pool of workers.  
057       <value name="php_defines">  
058         <value name="sendmail_path">/usr/sbin/sendmail -t -i</value>  
059         <value name="display_errors">1</value>  
060       </value>  
061    
062       Unix user of processes  
063       <value name="user">www</value>  
064    
065       Unix group of processes  
066       <value name="group">www</value>  
067    
068       Process manager settings  
069       <value name="pm">  
070    
071         Sets style of controling worker process count.  
072         Valid values are 'static' and 'apache-like'  
073         <value name="style">static</value>  
074    
075         Sets the limit on the number of simultaneous requests that will be served.  
076         Equivalent to Apache MaxClients directive.  
077         Equivalent to PHP_FCGI_CHILDREN environment in original php.fcgi  
078         Used with any pm_style.  
079         <value name="max_children">8</value>  
080    
081         Settings group for 'apache-like' pm style  
082         <value name="apache_like">  
083    
084           Sets the number of server processes created on startup.  
085           Used only when 'apache-like' pm_style is selected  
086           <value name="StartServers">20</value>  
087    
088           Sets the desired minimum number of idle server processes.  
089           Used only when 'apache-like' pm_style is selected  
090           <value name="MinSpareServers">5</value>  
091    
092           Sets the desired maximum number of idle server processes.  
093           Used only when 'apache-like' pm_style is selected  
094           <value name="MaxSpareServers">35</value>  
095    
096         </value>  
097    
098       </value>  
099    
100       The timeout (in seconds) for serving a single request after which the worker process will be terminated  
101       Should be used when 'max_execution_time' ini option does not stop script execution for some reason  
102       '0s' means 'off'  
103       <value name="request_terminate_timeout">0s</value>  
104    
105       The timeout (in seconds) for serving of single request after which a php backtrace will be dumped to slow.log file  
106       '0s' means 'off'  
107       <value name="request_slowlog_timeout">0s</value>  
108    
109       The log file for slow requests  
110       <value name="slowlog">logs/slow.log</value>  
111    
112       Set open file desc rlimit  
113       <value name="rlimit_files">65535</value>  
114    
115       Set max core size rlimit  
116       <value name="rlimit_core">0</value>  
117    
118       Chroot to this directory at the start, absolute path  
119       <value name="chroot"></value>  
120    
121       Chdir to this directory at the start, absolute path  
122       <value name="chdir"></value>  
123    
124       Redirect workers' stdout and stderr into main error log.  
125       If not set, they will be redirected to /dev/null, according to FastCGI specs  
126       <value name="catch_workers_output">yes</value>  
127    
128       How much requests each process should execute before respawn.  
129       Useful to work around memory leaks in 3rd party libraries.  
130       For endless request processing please specify 0  
131       Equivalent to PHP_FCGI_MAX_REQUESTS  
132       <value name="max_requests">1024</value>  
133    
134       Comma separated list of ipv4 addresses of FastCGI clients that allowed to connect.  
135       Equivalent to FCGI_WEB_SERVER_ADDRS environment in original php.fcgi (5.2.2+)  
136       Makes sense only with AF_INET listening socket.  
137       <value name="allowed_clients">127.0.0.1</value>  
138    
139       Pass environment variables like LD_LIBRARY_PATH  
140       <value name="environment">  
141         <value name="PATH">/usr/local/bin:/usr/bin:/bin</value>  
142         <value name="TMP">/tmp</value>  
143         <value name="TMPDIR">/tmp</value>  
144         <value name="TEMP">/tmp</value>  
145         <value name="OSTYPE">$OSTYPE</value>  
146         <value name="MACHTYPE">$MACHTYPE</value>  
147         <value name="MALLOC_CHECK_">2</value>  
148       </value>  
149    
150     </section>  
151    
152   </workers>  
153    
154 </configuration>

6、创建www用户及启动php-fpm并加入启动脚本
/usr/sbin/groupadd www
/usr/sbin/useradd -g www www
mkdir -p /data/www
chown -R www:www /data/www
chmod +w /data/www
ulimit -SHn 65535
/data/soft/php/sbin/php-fpm start
echo "ulimit -SHn 65535" >> /etc/rc.local
echo "/data/soft/php/sbin/php-fpm start" >> /etc/rc.local

第五步、编译安装Tengine
安装pcre #支持Tengine伪静态
cd /usr/local/src
wget ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-8.33.tar.gz
tar zxvf pcre-8.33.tar.gz
mkdir /usr/local/pcre   #创建安装目录
cd pcre-8.33
./configure --prefix=/usr/local/pcre   #配置
make
make install

安装openssl

cd /usr/local/src
wget http://www.openssl.org/source/openssl-1.0.1e.tar.gz
tar zxvf openssl-1.0.1e cd openssl-1* ./configure make &&make install 安装 tengine
cd /usr/local/src
wget http://tengine.taobao.org/download/tengine-1.4.6.tar.gz
tar zxvf tengine-1.4.6.tar.gz
cd tengine-1.4.6
./configure --prefix=/usr/local/nginx --with-http_stub_status_module --with-openssl=/usr/local/src/openssl-1.0.1e --with-pcre=/usr/local/src/pcre-8.33

make
make install
/usr/local/nginx/sbin/nginx   #启动
chown nobody.nobody -R /usr/local/nginx/html
chmod 700 -R /usr/local/nginx/html

设置tengine开启启动

vi /etc/rc.d/init.d/nginx  #编辑启动文件添加下面内容

01 #!/bin/bash
02 # nginx Startup script for the Nginx HTTP Server
03 # it is v.0.0.2 version.
04 # chkconfig: - 85 15
05 # description: Nginx is a high-performance web and proxy server.
06 # It has a lot of features, but it's not for everyone.
07 # processname: nginx
08 # pidfile: /var/run/nginx.pid
09 # config: /usr/local/nginx/conf/nginx.conf
10 nginxd=/usr/local/nginx/sbin/nginx
11 nginx_config=/usr/local/nginx/conf/nginx.conf
12 nginx_pid=/usr/local/nginx/logs/nginx.pid
13 RETVAL=0
14 prog="nginx"
15 # Source function library.
16 . /etc/rc.d/init.d/functions
17 # Source networking configuration.
18 . /etc/sysconfig/network
19 # Check that networking is up.
20 [ ${NETWORKING} = "no" ] && exit 0
21 [ -x $nginxd ] || exit 0
22 # Start nginx daemons functions.
23 start() {
24 if [ -e $nginx_pid ];then
25 echo "nginx already running...."
26 exit 1
27 fi
28 echo -n $"Starting $prog: "
29 daemon $nginxd -c ${nginx_config}
30 RETVAL=$?
31 echo
32 [ $RETVAL = 0 ] && touch /var/lock/subsys/nginx
33 return $RETVAL
34 }
35 # Stop nginx daemons functions.
36 stop() {
37 echo -n $"Stopping $prog: "
38 killproc $nginxd
39 RETVAL=$?
40 echo
41 [ $RETVAL = 0 ] && rm -f /var/lock/subsys/nginx /usr/local/nginx/logs/nginx.pid
42 }
43 reload() {
44 echo -n $"Reloading $prog: "
45 #kill -HUP `cat ${nginx_pid}`
46 killproc $nginxd -HUP
47 RETVAL=$?
48 echo
49 }
50 # See how we were called.
51 case "$1" in
52 start)
53 start
54 ;;
55 stop)
56 stop
57 ;;
58 reload)
59 reload
60 ;;
61 restart)
62 stop
63 start
64 ;;
65  
66 status)
67 status $prog
68 RETVAL=$?
69 ;;
70 *)
71 echo $"Usage: $prog {start|stop|restart|reload|status|help}"
72 exit 1
73 esac
74 exit $RETVAL
 
保存退出

chmod 775 /etc/rc.d/init.d/nginx   #赋予文件执行权限
chkconfig nginx on   #设置开机启动
/etc/rc.d/init.d/nginx restart
service nginx restart

至此 功能强大的 WEB服务器就配置好了。
文章版权声明:除非注明,否则均为IT技术交流分享 IDC管理计费系统 私有云管理系统 PVE管理系统 私有云系统原创文章,转载或复制请以超链接形式并注明出处。
取消
支付宝二维码
支付宝二维码
微信二维码