Rhel6-lanmp架构配置文档

理论基础:

l--操作系统:windows  linux  unix  mac OS

a--网页发布软件:apache nginx iis

m--数据库:mysql  pgsql  oracle...

p--网页语言:php  jsp  xml

 

配置:

系统环境: rhel6 x86_64 iptables and selinux disabled

主机: 192.168.122.185 server85.example.com

相关网址:wiki.nginx.org rpm.pbone.net

 

所需的包:mysql-5.6.10.tar.gz nginx-1.2.7.tar.gz libiconv-1.13.1.tar.gz libmcrypt-2.5.8.tar.bz2 mhash-0.9.9.9.tar.bz2 mcrypt-2.6.8.tar.gz php-5.4.12.tar.bz2


1.安装mysql

[root@server85 kernel]# tar zxf mysql-5.6.10.tar.gz

[root@server85 kernel]# cd mysql-5.6.10

[root@server85 mysql-5.6.10]# cmake -DCMAKE_INSTALL_PREFIX=/usr/local/lnmp/mysql \ (安装目录)

> -DMYSQL_DATADIR=/usr/local/lnmp/mysql/data \ (数据库存放目录)

> -DMYSQL_UNIX_ADDR=/usr/local/lnmp/mysql/data/mysql.sock \ (Unix socket 文件路径)

> -DWITH_MYISAM_STORAGE_ENGINE=1 \ (安装myisam存储引擎)

> -DDEFAULT_CHARSET=utf8 \ (使用utf8字符)

> -DDEFAULT_COLLATION=utf8_general_ci \ (校验字符)

> -DEXTRA_CHARSETS=all \ (安装所有扩展字符集)

此时会出现如下问题:

(1)-bash: cmake: command not found

(2)CMake Error: CMAKE_C_COMPILER not set, after EnableLanguage

CMake Error: CMAKE_CXX_COMPILER not set, after EnableLanguage

(3)emove CMakeCache.txt and rerun cmake.On Debian/Ubuntu, package name is libncurses5-dev, on Redhat and derivates it is ncurses-devel.

(4)Warning: Bison executable not found in PATH

 

解决方法如下:

(1)[root@server85 mysql-5.6.10]# yum install cmake -y

(2)[root@server85 mysql-5.6.10]# yum install gcc gcc-c++ -y

(3)[root@server85 mysql-5.6.10]# yum install ncurses-devel -y

(4)[root@server85 mysql-5.6.10]# yum install bison -y


[root@server85 mysql-5.6.10]# make && make install


重新编译时,需要清除旧的对象文件和缓存信息:

[root@server85 mysql-5.6.10]# yum install make -y

[root@server85 mysql-5.6.10]# make clean

[root@server85 mysql-5.6.10]# rm -rf CMakeCache.txt

 

[root@server85 mysql-5.6.10]# useradd -u 27 -d /usr/local/lnmp/mysql/ -M mysql

[root@server85 mysql-5.6.10]# groupmod -g 27 mysql

[root@server85 mysql-5.6.10]# chown mysql.mysql -R /usr/local/lnmp/mysql/

[root@server85 mysql-5.6.10]# cp /usr/local/lnmp/mysql/support-files/my-default.cnf /etc/my.cnf

[root@server85 mysql-5.6.10]# vim /etc/my.cnf

basedir = /usr/local/lnmp/mysql

datadir = /usr/local/lnmp/mysql/data

port = 3306

server_id = 1

socket = /usr/local/lnmp/mysql/data/mysql.sock

[root@server85 mysql-5.6.10]# cd /usr/local/lnmp/mysql/

[root@server85 mysql]# scripts/mysql_install_db --user=mysql--basedir=/usr/local/lnmp/mysql/ --datadir=/usr/local/lnmp/mysql/data/

[root@server85 mysql]# cp support-files/mysql.server /etc/init.d/mysqld

[root@server85 mysql]# chown root -R /usr/local/lnmp/mysql/

[root@server85 mysql]# chown mysql -R /usr/local/lnmp/mysql/data/

[root@server85 mysql]# /etc/init.d/mysqld start

 

Starting MySQL. SUCCESS! (看到此提示说明mysql启动成功)


[root@server85 mysql]# vim ~/.bash_profile

PATH=$PATH:$HOME/bin:$PATH:/usr/local/lnmp/mysql/bin

[root@server85 mysql]# source ~/.bash_profile

 

至此mysql安装完成!!!


2.安装及配置nginx

(1)安装:

[root@server85 kernel]# tar zxf nginx-1.2.7.tar.gz

[root@server85 kernel]# cd nginx-1.2.7

[root@server85 nginx-1.2.7]# vim src/core/nginx.h

#define NGINX_VER "nginx" (编译后外界无法获取程序的版本号)

[root@server85 nginx-1.2.7]# vim auto/cc/gcc

#CFLAGS="$CFLAGS -g"(去掉debug模式编译,编译以后程序只有几百k

[root@server85 nginx-1.2.7]# ./configure --prefix=/usr/local/lnmp/nginx --with-http_ssl_module --with-http_stub_status_module

此时会出现如下错误:

(1)./configure: error: the HTTP rewrite module requires the PCRE library.

(2)./configure: error: SSL modules require the OpenSSL library.


解决方法如下:

(1)[root@server85 nginx-1.2.7]# yum install pcre-devel -y

(2)[root@server85 nginx-1.2.7]# yum install openssl-devel -y


[root@server85 nginx-1.2.7]# make && make install

[root@server85 nginx-1.2.7]# cd /usr/local/lnmp/nginx/conf/

[root@server85 conf]# vim nginx.conf

events {

use epoll;

worker_connections 1024;

}

 

[root@server85 conf]# vim ~/.bash_profile

PATH=$PATH:$HOME/bin:$PATH:/usr/local/lnmp/mysql/bin: $PATH:/usr/local/lnmp/nginx/sbin

[root@server85 conf]# source ~/.bash_profile

 

[root@server85 conf]# nginx (启动nginx)

[root@server85 conf]# nginx -t ( 检测语法)

[root@server85 conf]# nginx -s reload (重载主配置文件)

[root@server85 conf]# nginx -s stop (关闭nginx)


访问server85.example.com能出现以下页面说明nginx安装并启动成功:

Rhel6-lanmp架构配置文档_第1张图片

 

(2)配置(/etc/hosts下:192.168.122.185 server85.example.com)

[root@server85 ~]# useradd nginx

[root@server85 ~]# vim /usr/local/lnmp/nginx/conf/nginx.conf

user nginx nginx;

worker_processes 4;

[root@server85 ~]# nginx -t

nginx: the configuration file /usr/local/lnmp/nginx/conf/nginx.conf syntax is ok

nginx: configuration file /usr/local/lnmp/nginx/conf/nginx.conf test is successful

[root@server85 ~]# nginx -s reload

[root@server85 ~]# ps ax

5922 ? Ss 0:00 nginx: master process nginx

5942 ? S 0:00 nginx: worker process

5943 ? S 0:00 nginx: worker process

5944 ? S 0:00 nginx: worker process

5945 ? S 0:00 nginx: worker process (进程数与配置的数目对应)

 


[root@server85 ~]# vim /usr/local/lnmp/nginx/conf/nginx.conf

location /status {

stub_status on;

access_log off;

}

[root@server85 ~]# nginx -s reload

访问server85.example.com/status出现以下页面说明配置成功:

Rhel6-lanmp架构配置文档_第2张图片

 

HTTPS加密访问


[root@server85 ~]# vim /usr/local/lnmp/nginx/conf/nginx.conf

server {

listen 443;

server_name server85.example.com;


ssl on;

ssl_certificate nginx.pem;

ssl_certificate_key nginx.pem;


ssl_session_timeout 5m;


ssl_protocols SSLv2 SSLv3 TLSv1;

ssl_ciphers HIGH:!aNULL:!MD5;

ssl_prefer_server_ciphers on;


location / {

root html;

index index.html index.htm;

}

}

[root@server85 ~]# cd /etc/pki/tls/certs/

[root@server85 certs]# make nginx.pem

Country Name (2 letter code) [XX]:CN

State or Province Name (full name) []:shannxi

Locality Name (eg, city) [Default City]:xi'an

Organization Name (eg, company) [Default Company Ltd]:westos

Organizational Unit Name (eg, section) []:linux

Common Name (eg, your name or your server's hostname) []:server85.example.com

Email Address []:[email protected]

[root@server85 certs]# mv nginx.pem /usr/local/lnmp/nginx/conf/

[root@server85 certs]# nginx -s reload

Rhel6-lanmp架构配置文档_第3张图片

访问https://server85.example.com时需要先下载证书说明配置成功。

 

 

 

虚拟主机

 

[root@server85 ~]# vim /usr/local/lnmp/nginx/conf/nginx.conf

 

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

 

'$status $body_bytes_sent "$http_referer" '

 

'"$http_user_agent" "$http_x_forwarded_for"';

 

server {

 

listen 80;

 

server_name www.linux.com;

 

access_log logs/linux.com.access.log main;

 

location / {

 

index index.html;

 

root /usr/local/lnmp/nginx/virtualhosts/linux;

 

}

 

}

 

server {

 

listen 80;

 

server_name www.westos.com;

 

access_log logs/westos.com.access.log main;

 

location / {

 

index index.html;

 

root /usr/local/lnmp/nginx/virtualhosts/westos;

 

}

 

}

 

[root@server85 ~]# cd /usr/local/lnmp/nginx/

 

[root@server85 nginx]# mkdir -p virtualhosts/linux

 

[root@server85 nginx]# mkdir -p virtualhosts/westos

 

[root@server85 nginx]# echo www.linux.com > virtualhosts/linux/index.html

 

[root@server85 nginx]# echo www.westos.com > virtualhosts/westos/index.html

 

[root@server85 nginx]# nginx -s reload

 

[root@server85 nginx]# vim /etc/hosts

 

192.168.122.185 www.linux.com www.westos.com

 

 

 

分别访问www.linux.comwww.westos.com能访问到不同的网页说明配置成功。

 


 

负载均衡

 

[root@server85 ~]# vim /usr/local/lnmp/nginx/conf/nginx.conf

 

http {

 

upstream koen{

 

server 192.168.122.117:80;

 

server 192.168.122.1:80 ;

 

}

 

server {

 

listen 80;

 

server_name server85.example.com;

 

location / {

 

# root html;

 

# index index.html index.htm;

 

proxy_pass http://koen ;

 

}

 

}

 

[root@server85 ~]# nginx -s reload

 


 

访问server85.example.com, 刷新页面,两台机子上的页面循环出现说明配置成功.

 


 

至此nginx的安装及配置完毕!!!

 

 

 

3.安装php

 

libiconv (加强系统对支持字符编码转换的功能)

 

[root@server85 kernel]# tar zxf libiconv-1.13.1.tar.gz

 

[root@server85 kernel]# cd libiconv-1.13.1

 

[root@server85 libiconv-1.13.1]# ./configure –libdir=/usr/local/lib64/

 

[root@server85 libiconv-1.13.1]# make && make install

 

 

 

libmcrypt (php的加密算法扩展库)

 

[root@server85 kernel]# tar jxf libmcrypt-2.5.8.tar.bz2

 

[root@server85 kernel]# cd libmcrypt-2.5.8

 

[root@server85 libmcrypt-2.5.8]# ./configure –libdir=/usr/local/lib64/

 

[root@server85 libmcrypt-2.5.8]# make && make install

 


 

mhash (php的加密算法扩展库)

 

[root@server85 kernel]# tar jxf mhash-0.9.9.9.tar.bz2

 

[root@server85 kernel]# cd mhash-0.9.9.9

 

[root@server85 mhash-0.9.9.9]# ./configure –libdir=/usr/local/lib64/

 

[root@server85 mhash-0.9.9.9]# make && make install

 


 

mcrypt

 

[root@server85 kernel]# tar zxf mcrypt-2.6.8.tar.gz

 

[root@server85 kernel]# cd mcrypt-2.6.8

 

[root@server85 mcrypt-2.6.8]# ./configure –libdir=/usr/local/lib64/

 

此时会出现如下错误:

 

configure: error: *** libmcrypt was not found

 

 

 

解决方法如下:

 

[root@server85 mcrypt-2.6.8]# vim /etc/ld.so.conf

 

include ld.so.conf.d/*.conf

 

/usr/local/lib64

 

[root@server85 mcrypt-2.6.8]# ldconfig

 


 

[root@server85 mcrypt-2.6.8]# make && make install

 


 

./configure时可能会报错:/bin/rm:cannot remove 'libtoolT':No Such file or directory直接忽略.

 


 

php

 

[root@server85 kernel]# tar jxf php-5.4.12.tar.bz2

 

[root@server85 kernel]# cd php-5.4.12

 

[root@server85 php-5.4.12]# yum install net-snmp-devel curl-devel libxml2-devel libpng-devel libjpeg-devel freetype-devel gmp-devel -y

 

[root@server85 php-5.4.12]# ./configure --prefix=/usr/local/lnmp/php --with-config-file-path=/usr/local/lnmp/php/etc --with-mysql=/usr/local/lnmp/mysql/ --with-openssl --with-snmp --with-gd --with-zlib --with-curl --with-libxml-dir --with-png-dir --with-jpeg-dir --with-freetype-dir --with-pear --with-gettext --with-gmp --enable-inline-optimization --enable-soap --enable-ftp --enable-sockets --enable-mbstring --with-mysqli=/usr/local/lnmp/mysql/bin/mysql_config --enable-fpm --with-fpm-user=nginx --with-fpm-group=nginx --with-libdir=lib64 --with-mcrypt –with-mhash

 

此时会出现以下错误:

 

checking for MySQL support... yes

 

checking for specified location of the MySQL UNIX socket... no

 

configure: error: Cannot find libmysqlclient under /usr/local/lnmp/mysql/.

 

Note that the MySQL client library is not bundled anymore!

 

 

 

解决方法如下:

 

[root@server85 php-5.4.12]# cd /usr/local/lnmp/mysql/

 

[root@server85 mysql]# ln -s lib/ lib64

 

 

 

[root@server85 php-5.4.12]# make ZEND_EXTRA_LIBS='-liconv'

 

[root@server85 php-5.4.12]# make install

 

[root@server85 kernel]# cd php-5.4.12/sapi/fpm/

 

[root@server85 fpm]# cp init.d.php-fpm /etc/init.d/php-fpm

 

[root@server85 ~]# chmod +x /etc/init.d/php-fpm

 

[root@server85 ~]# cd /usr/local/lnmp/php/etc/

 

[root@server85 etc]# cp php-fpm.conf.default php-fpm.conf

 

[root@server85 etc]# vim php-fpm.conf

 

pid = run/php-fpm.pid

 

[root@server85 etc]# /etc/init.d/php-fpm start

 

[root@server85 etc]# ps ax

 

29876 ? Ss 0:00 php-fpm: master process (/usr/local/lnmp/php/etc/php-

 

29877 ? S 0:00 php-fpm: pool www

 

29878 ? S 0:00 php-fpm: pool www

 

[root@server85 etc]# vim /usr/local/lnmp/nginx/conf/nginx.conf

 

location ~ \.php$ {

 

root html;

 

fastcgi_pass 127.0.0.1:9000;

 

fastcgi_index index.php;

 

# fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;

 

include fastcgi.conf;

 

}

 

[root@server85 etc]# cd /usr/local/lnmp/nginx/html/

 

[root@server85 html]# vim index.php

 

<?php

 

phpinfo()

 

?>

 

[root@server85 html]# cd /root/kernel/php-5.4.12

 

[root@server85 php-5.4.12]# cp php.ini-production /usr/local/lnmp/php/etc/php.ini

 

[root@server85 php-5.4.12]# vim /usr/local/lnmp/php/etc/php.ini

 

date.timezone = Asia/Shanghai

 

[root@server85 php-5.4.12]# /etc/init.d/php-fpm restart

 

[root@server85 php-5.4.12]# nginx -s reload

 

 

 

访问server85.example.com/index.php可以看到以下页面说明配置成功:

Rhel6-lanmp架构配置文档_第4张图片

至此php安装完毕!!!

 

 

 

4.发布Discuz论坛

 

[root@server85 kernel]# yum install unzip

 

[root@server85 kernel]# unzip Discuz_X2.5_SC_UTF8.zip -d /usr/local/lnmp/nginx/html/

 

[root@server85 kernel]# cd /usr/local/lnmp/nginx/html/

 

[root@server85 html]# rm -rf readme/ utility/

 

[root@server85 html]# mv upload/ bbs

 

[root@server85 html]# vim /usr/local/lnmp/nginx/conf/nginx.conf

 

location / {

 

root html;

 

index index.php index.html index.htm;

 

}

 

[root@server85 html]# nginx -s reload

 

访问server85.example.com/bbs出现以下画面,按“我同意”:

Rhel6-lanmp架构配置文档_第5张图片

此时文件权限不满足要求:

Rhel6-lanmp架构配置文档_第6张图片

 

解决方法如下:

[root@server85 bbs]# chown nginx -R /usr/local/lnmp/nginx/html/bbs/

Rhel6-lanmp架构配置文档_第7张图片

Rhel6-lanmp架构配置文档_第8张图片

Rhel6-lanmp架构配置文档_第9张图片

Rhel6-lanmp架构配置文档_第10张图片

Rhel6-lanmp架构配置文档_第11张图片

Rhel6-lanmp架构配置文档_第12张图片

至此Discuz论坛发布成功!!!

 

 

 

 

你可能感兴趣的:(Rhel6-lanmp架构配置文档)