二、 源码构建LNMP环境
2.1、 源码安装nginx:
#这里我将下载的软件存放到/ lnmp目录下
[root@shuiyong ~]# cd /lnmp
[root@shuiyong lnmp]# ls
cmake-2.8.5.tar.gz MySQL-5.0.75.tar.gz
libevent-2.0.18-stable.tar.gz nginx-1.1.18.tar.gz
libiconv-1.13.1.tar.gz nginx-1.2.0.tar.gz
libmcrypt-2.5.8.tar.bz2 pcre-8.21.tar.gz
mcrypt-2.6.8.tar.gz php-5.3.13.tar.bz2
mhash-0.9.9.9.tar.bz2 php-5.4.0.tar.bz2
#查看libevent的版本,发现版本过低,现在安装新的libevent
[root@shuiyong ~]# ldconfig -v |grep libevent
libevent-1.1a.so.1 -> libevent-1.1a.so.1.0.2
#解压libevent的程序文件,使用tar –zxvf,并使用-C指定解压目录,参数,z代表
#gzip(也就是后面的.gz文件)x代表解压,v表示显示详细信息,-f使用档案文件或设备
#(必选参数)(说明:一般一些额外的软件安装时经常将其放到/usr/src/目录下)
[root@shuiyong ~]#tar -zxvf libevent-2.0.18-stable.tar.gz -C /usr/src/
[root@shuiyong ~]#cd /usr/src/
[root@shuiyong ~]#ll
#预编译(执行源码包下的configure),编译(make),编译安装(make install)
[root@shuiyong ~]#cd libevent-2.0.18-stable/
[root@shuiyong libevent-2.0.18-stable]# ls
[root@shuiyong libevent-2.0.18-stable]# ./configure
[root@shuiyong libevent-2.0.18-stable]# make
[root@shuiyong libevent-2.0.18-stable]# make install
[root@shuiyong libevent-2.0.18-stable]# vim /etc/ld.so.conf.d/libevent.conf
/usr/local/lib
[root@shuiyong libevent-2.0.18-stable]# ldconfig -v |grep libevent
libevent_pthreads-2.0.so.5 -> libevent_pthreads.so
libevent-2.0.so.5 -> libevent.so
libevent_extra-2.0.so.5 -> libevent_extra.so
libevent_openssl-2.0.so.5 -> libevent_openssl.so
libevent_core-2.0.so.5 -> libevent_core.so
libevent-1.1a.so.1 -> libevent-1.1a.so.1.0.2
2.1.1、 安装nginx:
#首先解压源码包:
[root@shuiyong libevent-2.0.18-stable]# cd /lnmp
[root@shuiyong lnmp]# tar -zxvf nginx-1.1.18.tar.gz -C /usr/src/
#进入源码包目录:
[root@shuiyong lnmp]# cd /usr/src/nginx-1.1.18/
[root@shuiyong nginx-1.1.18]# ll
#添加nginx系统组和用户
[root@shuiyong nginx-1.1.18]# groupadd -r nginx
[root@shuiyong nginx-1.1.18]# useradd -r -g nginx -s /bin/false -M nginx
#进行预编译(配置):(各项配置说明略)
[root@shuiyong nginx-1.1.18]# ./configure --prefix=/usr --sbin-path=/usr/sbin/nginx --conf-path=/etc/nginx/nginx.conf --error-log-path=/var/log/nginx/error.log --http-log-path=/var/log/nginx/access.log --pid-path=/var/run/nginx/nginx.pid --lock-path=/var/lock/nginx.lock --user=nginx --group=nginx --with-http_ssl_module --with-http_flv_module --with-http_stub_status_module --with-http_gzip_static_module --http-client-body-temp-path=/var/tmp/nginx/client/ --http-proxy-temp-path=/var/tmp/nginx/proxy/ --http-fastcgi-temp-path=/var/tmp/nginx/fcgi/ --http-uwsgi-temp-path=/var/tmp/nginx/uwsgi --http-scgi-temp-path=/var/tmp/nginx/scgi --with-pcre
#预编译完成后就可以进行编译和安装:
[root@shuiyong nginx-1.1.18]# make
[root@shuiyong nginx-1.1.18]# make install
#启动测试,发现失败,按下面方法创建目录,再次启动,查看运行端口信息,#nginx占用TCP的80端口
##pkill -9 nignx #关闭nginx
##/usr/sbin/nginx #启动nginx
[root@shuiyong nginx-1.1.18]# nginx
nginx: [emerg] mkdir() "/var/tmp/nginx/client/" failed (2: No such file or directory)
[root@shuiyong nginx-1.1.18]# mkdir -pv /var/tmp/nginx/client
mkdir: created directory `/var/tmp/nginx'
mkdir: created directory `/var/tmp/nginx/client'
[root@shuiyong nginx-1.1.18]# netstat -tcpln |grep nginx
tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 14917/nginx: master
#为nginx提供一个启动服务的脚本(请下载附件)
[root@shuiyong nginx-1.1.18]# vim /etc/rc.d/init.d/nginx
[root@shuiyong nginx-1.1.18]# chmod +x /etc/rc.d/init.d/nginx
[root@shuiyong nginx-1.1.18]# chkconfig --add nginx
[root@shuiyong nginx-1.1.18]# chkconfig nginx on
[root@shuiyong nginx-1.1.18]# chkconfig --list nginx
nginx 0:off 1:off 2:on 3:on 4:on 5:on 6:off
[root@shuiyong nginx-1.1.18]#
#启动nginx服务,查看nginx端口
[root@shuiyong nginx-1.1.18]# service nginx stop
Stopping nginx: [ OK ]
[root@shuiyong nginx-1.1.18]# service nginx start
Starting nginx: [ OK ]
[root@shuiyong nginx-1.1.18]# service nginx restart
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful
Stopping nginx: [ OK ]
Starting nginx: [ OK ]
#配置nginx网页文件,编辑网页
[root@shuiyong nginx-1.1.18]# ls /usr/html/
50x.html index.html
[root@shuiyong nginx-1.1.18]# vim /usr/html/index.html
1 <html>
2 <head>
3 <title>Welcome to nginx!</title>
4 </head>
5 <body bgcolor="white" text="black">
6 <center><h1>Welcome to my nginx!</h1></center>
7 --xiamen huangshuiyong
8 --2012/10/16
9 </body>
10 </html>
#用浏览器可以访问--客户端测试显示如下信息--正常
2.1.2、 源码安装mysql
#解压mysql的主程序文件,使用tar –zxvf,并使用-C指定解压目录
[root@shuiyong ~]# cd /lnmp/
[root@shuiyong lnmp]# tar zxvf mysql-5.0.75.tar.gz -C /usr/src/
#切换至/usr/src/的目录下,并创建软连接,便于访问mysql文件
[root@shuiyong src]# ls
kernels libevent-2.0.18-stable mysql-5.0.75 nginx-1.1.18 RedHat
[root@shuiyong src]# ln -s mysql-5.0.75/ mysql
[root@shuiyong src]# cd mysql
#安装mysql之前先做一些准备工作,安装依赖包:显示已经安装了
[root@shuiyong ~]# yum -y install ncurses-devel
#创建MySQL用户,-M不创建home目录,-s指定shell为不登录
[root@shuiyong ~]# useradd -M -s /sbin/nologin mysql
#进行预编译(配置):(各项配置说明略)
[root@shuiyong mysql]# pwd
/usr/src/mysql
[root@shuiyong mysql]# ls
[root@shuiyong mysql]# ./configure --prefix=/usr/local/mysql --without-debug --with-extra-charsets=utf8,gbk --enable-assembler --with-mysqld-ldflags=-all-static --with-client-ldflags=-all-static --with-unix-socket-path=/tmp/mysql.sock --with-ssl
#预编译完成后就可以进行编译和安装:
[root@shuiyong mysql]# make && make install
#安装完成后复制配置文件和启动脚本,再给启动脚本执行权限:
[root@shuiyong mysql]# cp support-files/my-medium.cnf /etc/my.cnf
[root@shuiyong mysql]# cp support-files/mysql.server /etc/init.d/mysqld
[root@shuiyong mysql]# chmod +x /etc/init.d/mysqld
#为所有的二进制可执行文件和动态链接库文件做一个软连接
[root@shuiyong mysql]# ln -s /usr/local/mysql/bin/* /usr/local/bin/
[root@shuiyong mysql]# ln -s /usr/local/mysql/lib/mysql/lib* /usr/lib/
#初始化数据库,更改MySQL安装目录和MySQL的数据库目录的属主和属组
[root@shuiyong mysql]# mysql_install_db --user=mysql
[root@shuiyong mysql]# chown -R root.mysql /usr/local/mysql/
[root@shuiyong mysql]# chown -R mysql.mysql /usr/local/mysql/var/
#启动mysql,查看MySQL是否启动成功,MySQL占用TCP的3306端口
[root@shuiyong mysql]# service mysqld start
Starting MySQL. [ OK ]
[root@shuiyong mysql]# netstat -nltp |grep 3306
tcp 0 0 0.0.0.0:3306 0.0.0.0:* LISTEN 6427/mysqld
#通过mysql命令来连接mysql,测试mysql是否正常安装,可以看出已安装:
[root@shuiyong mysql]# mysql
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 1
Server version: 5.0.75-log Source distribution
Type 'help;' or '\h' for help. Type '\c' to clear the buffer.
mysql>
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| test |
+--------------------+
3 rows in set (0.00 sec)
mysql> quit
Bye