首页 Linux基础正文

LNMP的配置

Jean Linux基础 2017-10-02 590 0 linuxlnmp

版本:Centos6.8 x86_64

nginx  1.6.2.tar.gz

mysql 5.5.32

php-5.3.27


一、安装nginx

  1. 安装前准备

yum install pcre pcre-devel openssl openssl-devel -y

2.安装nginx

创建一个nginx用户

useradd -s /sbin/nologin -M nginx
id nginx

下载nginx-1.6.2.tar.gz到指定的目录,如/home/shnne/tool

tar xf nginx-1.6.2.tar.gz
cd nginx-1.6.2

编译

./configure \
--user=nginx \
--group=nginx \
--prefix=/application/nginx1.6.2 \
--with-http_stub_status_module \
--with-http_ssl_module
 
make && make install
ln -s /application/nginx1.6.2/ /application/nginx
ll /application/nginx

3.启动nginx

/application/nginx/sbin/nginx -t  #检查语法
/application/nginx/sbin/nginx  #直接启动

检查网站

curl 192.168.1.101

Window下浏览器也要打开测试下

4.修改nginx.conf配置文件

egrep -v "#|^$" nginx.conf.default > nginx.conf
vim nginx.conf
 
worker_processes  1;
events {
    worker_connections  1024;
}
http {
    include       mime.types;
    default_type  application/octet-stream;
    sendfile        on;
    keepalive_timeout  65;
    server {
        listen       80;
        server_name  pc.shnne.com;
            root   html/pc;
            index  index.html index.htm;
    }
 
    server {
        listen       80;
        server_name  blog.shnne.com;
            root   html/blog;
            index  index.html index.htm;
    }
 
    server {
        listen       80;
        server_name  bbs.shnne.com;
            root   html/bbs;
            index  index.html index.htm;
    }
 
}

检测状态的:
    server {
        listen       80;
        server_name  status.shnne.com;
stub_status on;
access_log off;
    }
    
nginx 别名
    server {
        listen       80;
        server_name  bbs.shnne.com    #添加别名 
            root   html/bbs;
            index  index.html index.htm;
    }
 
 
nginx 301重定向放在http配置文件第一位,可以防止IP访问  
    server {
        listen       80;
        server_name  shnne.com;
        rewrite ^(.*) http://www.shnne.com$1 permanent;
}
   放在http配置文件第一位,让ip访问出现 403 forbbden
    server {
        listen       80;
        location / {
deny all;
}
    }
日志功能
  log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
            '$status $body_bytes_sent "$http_referer" '
            '"$http_user_agent" "$http_x_forwarded_for"';
日志切割
mkdir /server/scripts/ -p
touch /server/scripts/cut_nginx_log.sh
vi /server/scripts/cut_nginx_log.sh
cd /application/nginx/logs/ && \
for n in pc bbs blog
do
        /bin/mv ${n}_access.log ${n}_access_$(date +%F -d -1day).log
done
/application/nginx/sbin/nginx -s reload
/bin/sh /server/scripts/cut_nginx_log.sh
 
[root@study logs]# crontab -e
no crontab for root - using an empty one
#cut_nginx_log by shnne at 2017-09-30 23:25
00 00 * * * /bin/sh /server/scripts/cut_nginx_log.sh >/dev/null 2>&1
crontab -l    #检查下

extra 配置
mkdir extra
[root@study conf]# vim nginx.conf
worker_processes  1;
events {
    worker_connections  1024;
}
http {
    include       mime.types;
    default_type  application/octet-stream;
    sendfile        on;
    keepalive_timeout  65;
 
    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for"';
 
        include extra/pc.conf;
        include extra/bbs.conf;
        include extra/blog.conf;
 
}

二、mysql 5.5.32安装 

1.通过cmake编译安装

2.二进制包解压初始化

上传mysql 5.5.32二进制包并解压

groupadd mysql
useradd -g mysql -s /sbin/nologin -M mysql
cd /home/shnne/tools/
tar xf mysql-5.5.32-linux2.6-x86_64.tar.gz 
mv mysql-5.5.32-linux2.6-x86_64 /application/mysql5.5.32
ln -s mysql5.5.32/ /application/mysql
ll /application/mysql
chown -R mysql.mysql /application/mysql/data/
ll /application/mysql/data/ 
初始化数据库
/application/mysql/scripts/mysql_install_db --user=mysql --basedir=/application/mysql --datadir=/application/mysql/data/

cd /application/mysql/support-files
cp my-small.cnf /etc/my.cnf
cp mysql.server /etc/init.d/mysqld
vim /etc/init.d/mysqld
添加(大概46行)
basedir=/application/mysql
datadir=/application/mysql/data
 
chmod +x /etc/init.d/mysqld #cp过来本身有x权限,没有不用设置
/etc/init.d/mysqld start
 
在检查端口和服务
ps -ef|grep mysqld
netstat -antup|grep mysqld
lsof -i :3306

三、nginx下的php安装

rpm -qa zlib libxml libjpeg freetype libpng gd curl libiconv zlib-devel libxml2-devel libjpeg-devel freetype-devel libpng-devel gd-devel curl-devel gcc gcc-c++

yum install zlib libxml libjpeg freetype libpng gd curl libiconv zlib-devel libxml2-devel libjpeg-devel freetype-devel libpng-devel gd-devel curl-devel gcc gcc-c++ -y
安装字符集转换库相关,是一个命令; 注:必须存在devel 
tar zxf libiconv-1.14.tar.gz
cd libiconv-1.14
./configure --prefix=/usr/local/libiconv
make
make install
cd ../
 
添加一个加密相关的库 
wget "http://downloads.sourceforge.net/mcrypt/libmcrypt-2.5.8.tar.gz"
tar zxf libmcrypt-2.5.8.tar.gz 
cd libmcrypt-2.5.8
./configure
make
make install
sleep 2
/sbin/ldconfig
cd libltdl/
./configure --enable-ltdl-install
make
make install
cd ../../
 
安装mhash加密扩展库 
wget "http://downloads.sourceforge.net/mhash/mhash-0.9.9.9.tar.gz"
tar zxf mhash-0.9.9.9.tar.gz
cd mhash-0.9.9.9/
./configure
make
make install
sleep 2
cd ../
 
#下面做的软连接,经过自己测试,发现在此系统版本,默认安装在/usr/local/lib/下,并没有
 安装在/usr/local/lib64/下,其他系统办没有测试。
rm -f /usr/lib64/libmcrypt.*
rm -f /usr/lib64/libmhash*
ln -s /usr/local/lib/libmcrypt.la /usr/lib64/libmcrypt.la
ln -s /usr/local/lib/libmcrypt.so /usr/lib64/libmcrypt.so
ln -s /usr/local/lib/libmcrypt.so.4 /usr/lib64/libmcrypt.so.4
ln -s /usr/local/lib/libmcrypt.so.4.4.8 /usr/lib64/libmcrypt.so.4.4.8
ln -s /usr/local/lib/libmhash.a /usr/lib64/libmhash.a
ln -s /usr/local/lib/libmhash.la /usr/lib64/libmhash.la
ln -s /usr/local/lib/libmhash.so /usr/lib64/libmhash.so
ln -s /usr/local/lib/libmhash.so.2 /usr/lib64/libmhash.so.2
ln -s /usr/local/lib/libmhash.so.2.0.1 /usr/lib64/libmhash.so.2.0.1
ln -s /usr/local/bin/libmcrypt-config /usr/bin/libmcrypt-config
 
 
另一个加密库 
wget "http://downloads.sourceforge.net/mcrypt/mcrypt-2.6.8.tar.gz"
tar zxf mcrypt-2.6.8.tar.gz
cd mcrypt-2.6.8/
/sbin/ldconfig
./configure LD_LIBRARY_PATH=/usr/local/lib
make
make install
cd ../
sleep 2
 
yum install libxslt-devel -y 
 
解压php : 
tar xf php-5.3.27.tar.gz
cd php-5.3.27
配合nginx编译:
./configure \
--prefix=/application/php5.3.27 \
--with-mysql=/application/mysql \   #未安装mysql数据库用 --with-mysql=mysqlnd \
--with-iconv-dir=/usr/local/libiconv \
--with-freetype-dir \
--with-jpeg-dir \
--with-png-dir \
--with-zlib \
--with-libxml-dir=/usr \
--enable-xml \
--disable-rpath \
--enable-safe-mode \
--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-xmlrpc \
--enable-zip \
--enable-soap \
--enable-short-tags \
--enable-zend-multibyte \
--enable-static \
--with-xsl \
--with-fpm-user=nginx \
--with-fpm-group=nginx \
--enable-ftp
 
ln -s /application/mysql/lib/libmysqlclient.so.18  /usr/lib64/
make
make install
在php-5.3.27目录下
cp php.ini-production /application/php/lib/php.ini
cd /application/php/etc
修改php-fpm.conf

/application/php/sbin/php-fpm -t  #检查语法
mkdir -p /app/logs/
/application/php/sbin/php-fpm   #启动服务
 
vim /etc/rc.local
添加启动服务
#nginx+php-fpm by shnne at 2017-10-2
/etc/init.d/mysqld start
/application/php/sbin/php-fpm
/application/nginx/sbin/nginx
php整合NGINX
 
vim /application/nginx/conf/nginx.conf
events {
    worker_connections  1024;
}
http {
    include       mime.types;
    default_type  application/octet-stream;
    sendfile        on;
    keepalive_timeout  65;
    include extra/www.conf;
    include extra/bbs.conf;
    include extra/blog.conf;
    }

mkdir /application/nginx/conf/extra/ -p
mkdir /application/nginx/html/{www,bbs,blog} -p
touch /application/nginx/conf/extra/{www,bbs,blog}.conf

vim /application/nginx/conf/extra/www.conf 
server {
        listen       80;
        server_name  www.shnne.com;
        root   html/www;
        index  index.php index.html index.htm;
      location ~ .*\.(php|php5)?$
       {
        fastcgi_pass  127.0.0.1:9000;
        fastcgi_index index.php;
        include fastcgi.conf;
       }
}
/application/nginx/sbin/nginx -t                #检查语法
/application/nginx/sbin/nginx -s reload    #重新加载nginx服务
添加测试页测试php和mysql



评论