设为首页 收藏本站
查看: 954|回复: 0

LNMP网站平台搭建

[复制链接]
累计签到:1 天
连续签到:1 天
发表于 2014-11-21 17:24:47 | 显示全部楼层 |阅读模式
一、搭建LNMP平台
案例需求:在ip地址 192.168.1.10的服务器上搭建LNMP平台

系统环境准备:
配置固定Ip地址、关闭 iptables     selinux     
配置yum源
安装开发库软件包组   和  开发工具软件包组
编译工具   gcc  gcc-c++   make
service   httpd stop;chkconfig  --level  35 httpd  off

LNMP简介
LNMP  是网站运行平台

L    Linux操作系统   (RHEL5   )
N   Nginx 网站服务
M  MySQL 数据库服务
P   PHP动态网站编程语言
注:PHP一定是安装再MYSQL之前

rpm包安装    rpm   -ivh   xxx.rpm
源码包安装     *

1、安装源码nginx
yum   -y  install   pcre-devel
[iyunv@www nginx-1.2.0]# useradd  -s/sbin/nologin  -M  www
[iyunv@localhost nginx-1.2.0]#  ./configure   \
>--prefix=/usr/local/nginx    \
>--pid-path=/usr/local/nginx/nginx.pid  \
>--user=www   --group=www \
>--with-http_ssl_module  --with-http_flv_module  \
>--with-http_stub_status_module \
>--with-http_gzip_static_module \
[iyunv@localhost nginx-1.2.0]#make   
[iyunv@localhost nginx-1.2.0]#make   install
[iyunv@www ~]# ls /usr/local/nginx/
conf  html logs  sbin

启动服务
[iyunv@www ~]# /usr/local/nginx/sbin/nginx

访问nginx服务
[iyunv@www ~]# elinks  --dump http://localhost
                               Welcome tonginx!

2、安装源码mysql
[iyunv@www ~]# rpm -qa | grep -i mysql-server
[iyunv@www ~]# mv  /etc/my.cnf  /etc/my.cnf.bak
[iyunv@www ~]# service mysqld  stop
[iyunv@www ~]# chkconfig  --level  35 mysqld  off
[iyunv@www ~]# grep mysql  /etc/passwd
[iyunv@www ~]# useradd -s /sbin/nologin  -M  mysql
[iyunv@www ~]#
2.1  安装编译工具 cmake
[iyunv@www cmake-2.8.10.2]#./bootstrap  --prefix=/usr/local/cmake
[iyunv@www cmake-2.8.10.2]# make
[iyunv@www cmake-2.8.10.2]# make install

[iyunv@www local]# /usr/local/cmake/bin/cmake -version
cmakeversion 2.8.10.2
[iyunv@www local]#

2.2 、安装源码mysql
[iyunv@localhost mysql-5.5.13]# /usr/local/cmake/bin/cmake   \
>-DCMAKE_INSTALL_PREFIX=/usr/local/mysql  \
>-DSYSCONFDIR=/etc  -DMYSQL_DATADIR=/usr/local/mysql/data \
>-DMYSQL_TCP_PORT=3306  \
>-DMYSQL_UNIX_ADDR=/tmp/mysqld.sock  \
>-DMYSQL_USER=mysql  -DEXTRA_CHARSETS=all  \
>-DWITH_READLINE=1  -DWITH_SSL=system  \
>-DWITH_EMBEDDED_SERVER=1  \
>-DENABLED_LOCAL_INFILE=1  \
>-DWITH_INNOBASE_STORAGE_ENGINE=1
[iyunv@localhost mysql-5.5.13]#make   &&  make install

[iyunv@www ~]# ls  /usr/local/mysql/
bin      docs            lib         README   sql-bench
COPYING  include         man         scripts  support-files
data     INSTALL-BINARY  mysql-test share
[iyunv@www ~]#

2.3 、配置源码mysql服务
[iyunv@www ~]# chown  mysql:mysql  -R /usr/local/mysql/

初始化授权库
[iyunv@www ~]# ls /usr/local/mysql/data/mysql/
[iyunv@www ~]#
[iyunv@www mysql]# pwd
/usr/local/mysql
[iyunv@www mysql]# ./scripts/mysql_install_db --user=mysql

创建mysql数据库服务主配置文件 /etc/my.cnf
[iyunv@www~]#  cd  mysql-5.5.13/support-files
[iyunv@wwwsupport-files]# cp my-medium.cnf   /etc/my.cnf

启动源码mysql数据库服务
netstat   -utnalp |   grep  :3306

/usr/local/mysql/bin/mysqld_safe  --user=mysql  &

停止源码mysql数据库服务
[iyunv@www support-files]# pkill -9 mysqld

把源码mysql数据库服务添加为系统服务能用下面的方式做停 启 操作
(service  mysqldd start|stop|status)
[iyunv@www ~]#  cd  mysql-5.5.13/support-files

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

[iyunv@www support-files]# ll /etc/init.d/mysqld
-rw-r--r--1 root root 10650 08-21 10:53 /etc/init.d/mysqldd

[iyunv@www support-files]# chmod +x /etc/init.d/mysqld

[iyunv@www support-files]# chkconfig --add mysqld

[iyunv@www support-files]# chkconfig --list mysqld
mysqldd         0:关闭  1:关闭  2:启用  3:启用  4:启用  5:启用  6:关闭
[iyunv@www support-files]#

[iyunv@www support-files]# service mysqld start
StartingMySQL                                             [确定]
[iyunv@www support-files]# service mysqld status
MySQLrunning (31962)                                      [确定]
[iyunv@www support-files]# service mysqld stop
Shuttingdown MySQL.                                       [确定]

[iyunv@www support-files]# service mysqld start
StartingMySQL..                                           [确定]
[iyunv@www support-files]#
把源码mysql命令的路径添加到PATH变量里
export   PATH=/usr/local/mysql/bin:$PATH
vim  /etc/profile
export   PATH=/usr/local/mysql/bin:$PATH
:wq

2.4、使用数据库管理员在数据库服务器本机登录
mysql  -hlocalhost  -uroot   -p
password:回车
mysql>grant   all on *.* to jim@"%"  identifiedby "123";
mysql>quit;

2.5、设置数据库管理员从数据库服务器本机登录的密码
[iyunv@www ~]# mysqladmin -hlocalhost -uroot password "888"
[iyunv@www ~]# service  mysqldd  restart
[iyunv@www ~]#mysql  -hlocalhost   -uroot  -p888
mysql>

3、安装源码php
3.1  安装php的扩展功能包
tar  -zxvf mhash-0.9.9.9.tar.gz       哈希函数库
cdmhash-0.9.9.9
./configure  &&  make    &&  make install

tar-zxvf libiconv-1.13.tar.gz         字符编码转换
cdlibiconv-1.13
./configure  &&  make    && make install

tarzxf libmcrypt-2.5.8.tar.gz
cdlibmcrypt-2.5.8
./configure  &&  make    &&  make install
ldconfig   -v
cd    libltdl
./configure  --with-gmetad --enable-gexec --enable-ltdl-install
make  && make  install

3.2  安装源码php
ln -sv/usr/local/lib/libmcrypt*     /usr/lib/
ln -sv/usr/local/lib/libmhash.*    /usr/lib/
ldconfig  -v

[iyunv@www db1]# vim   /etc/ld.so.conf
includeld.so.conf.d/*.conf
/usr/local/mysql/lib/
/usr/local/mysql/include/
:wq

[iyunv@www ~ ]#  ldconfig   -v
[iyunv@www php-5.4.9]# ./configure --prefix=/usr/local/php5nginx--with-config-file-path=/usr/local/php5nginx/etc  --with-mysql=/usr/local/mysql  --with-mysqli=/usr/local/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-bcmath --enable-shmop  --enable-sysvsem--enable-inline-optimization --with-curl   --with-curlwrappers--enable-mbregex   --enable-fpm  --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

[iyunv@www php-5.4.9]#   make      ZEND_EXTRA_LIBS='-liconv'

[iyunv@www php-5.4.9]#   make    install  

[iyunv@www php5nginx]# ls /usr/local/php5nginx/
bin  etc include  lib  php sbin  var
[iyunv@www php5nginx]#

3.2  创建php主配置文件 php.ini
[iyunv@www  ~ ] # cd  php-5.4.9
[iyunv@www php-5.4.9]# cp  php.ini-production  /usr/local/php5nginx/etc/php.ini
[iyunv@www php-5.4.9]#
             nginx
http://localhost/test.php

4、nginx +  fast-cgi  (让nginx能够解释php页面)
4.1、启动fast-cgi   
[iyunv@www mysql]# cd /usr/local/php5nginx/etc
[iyunv@www etc]# cp php-fpm.conf.default  php-fpm.conf

4.2、把fpm添加为系统服务
[iyunv@www ~]#  cd  php-5.4.9/sapi/fpm/
[iyunv@www fpm]# cp init.d.php-fpm /etc/rc.d/init.d/php-fpm
[iyunv@www fpm]# chmod +x  /etc/rc.d/init.d/php-fpm
[iyunv@www fpm]# chkconfig --add php-fpm
[iyunv@www fpm]# chkconfig --list php-fpm
php-fpm         0:关闭  1:关闭  2:启用  3:启用  4:启用  5:启用6:关闭
[iyunv@www fpm]# netstat -untlap | grep :9000
[iyunv@www fpm]#
[iyunv@www fpm]# service php-fpm start
Startingphp-fpm  done
[iyunv@www fpm]# netstat -untlap | grep :9000
tcp        0     0 127.0.0.1:9000             0.0.0.0:*                   LISTEN      30117/php-fpm      
[iyunv@www fpm]#

4.3、让nginx 把接收到访问.php文件的请求,转给本机的9000端口
                                          /usr/local/nginx/html
http://nginx_ip_address/test.php
http://nginx_ip_address/one/1.html
[iyunv@www ~]# vim /usr/local/nginx/conf/nginx.conf
65        location ~ \.php$ {
66               root           html;
67               fastcgi_pass   127.0.0.1:9000;
68               fastcgi_index  index.php;
69               fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
70               include        fastcgi_params;
71        }
:wq
[iyunv@www conf]# vim /usr/local/nginx/conf/fastcgi_params
fastcgi_param  SCRIPT_FILENAME    $document_root$fastcgi_script_name;
:wq
[iyunv@www ~]# /usr/local/nginx/sbin/nginx  -t
nginx:the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
nginx:configuration file /usr/local/nginx/conf/nginx.conf test is successful
[iyunv@www ~]# /usr/local/nginx/sbin/nginx  -s stop
[iyunv@www ~]# /usr/local/nginx/sbin/nginx
[iyunv@www ~]#

访问php 文件
elinks  --dump  http://localhost/test.php
                             hello   wrold

测试php能否连接mysql数据库服务器?
[iyunv@www html]# service mysqldd status
MySQLrunning (658)                                        [确定]
[iyunv@www html]#
[iyunv@www html]# mysql -hlocalhost -uroot -p999
mysql>grant  all on   webdb.*  to  webuser@"localhost" identified by  "123";
mysql>quit;

[iyunv@www html]# mysql -hlocalhost -uwebuser -p123
mysql>quit;

[iyunv@www html]# cat /usr/local/nginx/html/linkdb.php
<?php
$linkdb=mysql_connect("localhost","webuser","123");
if($linkdb){
   echo "linkdb  ok!!!";
}else{
   echo "linkdb no!!!";
}
?>

[iyunv@www html]#elinks   --dump  http://localhost/linkdb.php
                                            



运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-32578-1-1.html 上篇帖子: LAMP网站平台搭建 下篇帖子: 搭建LNMP发布ecshop系统及压测启用opcache缓存与否的情况 网站
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表