部署Nginx+Apache动静分离
----------LAMP----------Nginx----------Client---------
| | |
192.168.1.2 192.168.1.1 192.168.1.10
一、(192.168.1.2)安装apache
[root@localhost ~]#rpm -q httpd
[root@localhost ~]#rpm -e httpd --nodeps
[root@localhost ~]#tar -zxvf httpd-2.2.17.tar.gz -C /usr/src/
[root@localhost ~]#cd /usr/src/httpd-2.2.17/
[root@localhost httpd-2.2.17]# ./configure --prefix=/usr/local/httpd --enable-so --enable
rewrite --enable-charset-lite --enable-cgi --enable-sockets
[root@localhost httpd-2.2.17]# make && make install
[root@localhost ~]#/usr/local/httpd/bin/apachectl -t
[root@localhost ~]#/usr/local/httpd/bin/apachectl start
[root@localhost ~]#netstat -anpt | grep 80
[root@localhost ~]#firefox http://192.168.1.1/ &
二、(192.168.1.2)安装mysql
1、编译安装cmake
[root@localhost ]#tar -zxvf cmake-2.8.6.tar.gz -C /usr/src/
[root@localhost ]#cd /usr/src/cmake-2.8.6/
[root@localhost cmake-2.8.6]# ./configure
[root@localhost cmake-2.8.6]#gmake
[root@localhost cmake-2.8.6]#gmake install
2、编译安装mysql
[root@localhost ]# useradd -M -u 27 -s /sbin/nologin mysql
注意:如果原来有MySQL用户,那么就要删除,然后在新建MySQL用户
[root@localhost ]#tar -zxvf mysql-5.5.22.tar.gz -C /usr/src/
[root@localhost ]#cd /usr/src/mysql-5.5.22/
[root@localhost mysql-5.5.22]#
cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DSYSCONFDIR=/etc -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DWITH_EXTRA_CHARSETS=all
[root@localhost mysql-5.5.22]#make
[root@localhost mysql-5.5.22]#make install
[root@localhost ~]# chown -R mysql:mysql /usr/local/mysql/
[root@localhost ~]# cp /usr/src/mysql-5.5.22/support-files/my-medium.cnf /etc/my.cnf
[root@localhost ~]# /usr/local/mysql/scripts/mysql_install_db --user=mysql -
basedir=/usr/local/mysql/ --datadir=/usr/local/mysql/data/
[root@localhost ~]# ln -s /usr/local/mysql/bin/* /usr/local/bin/
[root@localhost ~]# cp support-files/mysql.server /etc/init.d/mysqld
[root@localhost ~]# chmod +x /etc/rc.d/init.d/mysqld
[root@localhost ~]# chkconfig --add mysqld
[root@localhost ~]# chkconfig mysqld on
[root@localhost ~]# service mysqld restart
[root@localhost ~]# netstat -anpt | grep 3306
[root@localhost ~]# mysqladmin -u root password '123.com'
[root@localhost ~]# mysql -u root -p123.com
三、(192.168.1.2)安装php
一、安装PHP
[root@localhost ~]#yum install -y gcc gcc-c++ autoconf libjpeg libjpeg-devel libpng libpng
devel freetype freetype-devel libpng libpng-devel libxml2 libxml2-devel zlib zlib-devel glibc
glibc-devel glib2 glib2-devel bzip2 bzip2-devel ncurses curl openssl-devel gdbm-devel db4
devel libXpm-devel libX11-devel gd-devel gmp-devel readline-devel libxslt-devel expat-devel
xmlrpc-c xmlrpc-c-devel php-gd
[root@localhost ~]# tar -zxvf libmcrypt-2.5.8.tar.gz -C /usr/src/
[root@localhost ~]# cd /usr/src/libmcrypt-2.5.8/
[root@localhost ~]# ./configure && make && make install
[root@localhost ~]# ln -s /usr/local/lib/libmcrypt.* /usr/lib/
[root@localhost ~]# tar -zxvf mhash-0.9.9.9.tar.gz -C /usr/src/
[root@localhost ~]# cd /usr/src/mhash-0.9.9.9/
[root@localhost ~]# ./configure && make && make install
[root@localhost ~]# ln -s /usr/local/lib/libmhash* /usr/lib/
[root@localhost ~]# tar -zxvf mcrypt-2.6.8.tar.gz -C /usr/src/
[root@localhost ~]# cd /usr/src/mcrypt-2.6.8/
[root@localhost ~]# ./configure(如果报错,请执行下面的命令)
[root@localhost ~]# export LD_LIBRARY_PATH=/usr/local/lib:$LD_LIBRARY_PATH
[root@localhost ~]# ./configure && make && make install
[root@localhost ~]# tar -zxvf php-5.3.28.tar.gz -C /usr/src/
[root@localhost ~]# cd /usr/src/php-5.3.28/
[root@localhost ~]#
./configure --prefix=/usr/local/php --with-config-file path=/usr/local/php/ --with-mysql=/usr/local/mysql/ --with-apxs2=/usr/local/httpd/bin/apxs - with-iconv-dir=/usr/local --with-jpeg-dir --with-png-dir --with-zlib --with-libxml-dir=/usr --enable-xml --with-mcrypt --with-gd --enable-gd-native-ttf --enable-sockets --with-zlib - enable-mbstring
[root@localhost ~]#cp /usr/src/php-5.3.28/php.ini-development /usr/local/php/php.ini
[root@localhost ~]#vim /usr/local/php/php.ini
修改:
default_charset = "utf-8” (修改)
short_open_tag = On (修改)
extension=php_gd2.dll (去掉注释)
[root@localhost ~]#tar -zxvf ZendGuardLoader-php-5.3-linux-glibc23-x86_64.tar.gz -C /usr/src/
[root@localhost ~]#cp /usr/src/ZendGuardLoader-php-5.3-linux-glibc23-x86_64/php
5.3.x/ZendGuardLoader.so /usr/local/php/lib/php/
[root@localhost ~]#vim /usr/local/php/php.ini
添加:
zend_extension=/usr/local/php/lib/php/ZendGuardLoader.so
zend_loader.enable=1
[root@localhost ~]#vim /usr/local/httpd/conf/httpd.conf
修改:
LoadModule php5_module modules/libphp5.so(查看)
AddType application/x-httpd-php .php(添加)
DirectoryIndex index.php index.html(修改)
[root@localhost ~]#/usr/local/httpd/bin/apachectl -t
[root@localhost ~]#/usr/local/httpd/bin/apachectl start
[root@localhost ~]#netstat -anpt |grep httpd
验证:
[root@localhost ~]#cd /usr/local/httpd/htdocs/
[root@localhost htdocs]#mv index.html index.html_back
1、验证PHP与Apache连接:
[root@localhost htdocs]#vim index.php
添加:
<?php phpinfo( ); ?>
[root@localhost htdocs]#firefox http://192.168.1.1/ &
1、验证PHP与MySQL连接:
[root@localhost htdocs]#mv index.php index.php_back
[root@localhost htdocs]#vim index.php
添加:
<?php $link=mysql_connect('localhost','root','123456'); if($link) echo "我觉得OK"; mysql_close(); ?>
[root@localhost htdocs]#firefox http://192.168.1.1/ &
四、(192.168.1.2)部署SKYUC(电影)
1、设置SKYUC网站
[root@localhost ~]#yum -y install unzip
[root@localhost ~]#unzip SKYUC.v3.4.2.SOURCE.zip
[root@localhost ~]# cp -r SKYUC.v3.4.2.SOURCE/wwwroot/ /usr/local/nginx/html/skyuc
[root@localhost ~]# chown -R daemon:daemon /usr/local/httpd/htdocs/skyuc/upload/
[root@localhost ~]# chown -R daemon:daemon /usr/local/httpd/htdocs/skyuc/templates/
[root@localhost ~]# chown -R daemon:daemon /usr/local/httpd/htdocs/skyuc/admincp/
[root@localhost ~]# chown -R daemon:daemon /usr/local/httpd/htdocs/skyuc/data/
[root@localhost ~]#
2、创建数据库
[root@localhost ~]# mysql -u root -p123.com
mysql> create database skyucdb;
mysql> grant all on skyucdb.* to 'admin'@'192.168.1.%' identified by '123.com';
五、(192.168.1.1)安装Nginx
1、编译安装Nginx
[root@localhost ~]# yum -y install pcre-devel zlib-devel
[root@localhost ~]# useradd -M -s /sbin/nologin nginx
[root@localhost ~]# tar -zxvf nginx-1.6.0.tar.gz -C /usr/src/
[root@localhost ~]# cd /usr/src/nginx-1.6.0/
[root@localhost nginx-1.6.0]# ./configure --prefix=/usr/local/nginx --user=nginx -
group=nginx --with-http_stub_status_module
[root@localhost nginx-1.6.0]# make && make install
[root@localhost ~]# ln -s /usr/local/nginx/sbin/* /usr/local/sbin/
[root@localhost ~]# vim /usr/local/nginx/conf/nginx.conf
添加:
location ~.*.(gif| jpg | jpeg |)$ { (支持图形格式) root html; } location ~ .php$ { proxy_pass http://192.168.1.1:80; (指向apache服务器) }
[root@localhost ~]# nginx -t
[root@localhost ~]# nginx
[root@localhost ~]# netstat -anpt | grep 80
2、设置SKYUC网站
[root@localhost ~]#unzip SKYUC.v3.4.2.SOURCE.zip
[root@localhost ~]# cp -r SKYUC.v3.4.2.SOURCE/wwwroot/ /usr/local/nginx/html/skyuc
六、验证:
1、安装skyuc:
[root@localhost ~]# firefox http://192.168.1.1/skyuc/install/index.php &
2、使用skyuc:
[root@localhost ~]# firefox http://192.168.1.1/skyuc/
3、skyuc后台管理
http://192.168.1.1/SKYUC/admincp/index.php