本文作者:不许人间见白头

Lnmp架构(nginx1.9,mysql5.0,php54)centos6版本

不许人间见白头 2个月前 ( 12-15 ) 62

新建安装目录和下载目录

[root@ecs-base ~]# mkdir -p /www/server

[root@ecs-base ~]# mkdir -p /www/xiazai

进入安装目录,并下载包

[root@ecs-base ~]# cd /www/xiazai/

[root@ecs-base xiazai]# wget  http://mirrors.sohu.com/mysql/MySQL-5.0/mysql-5.0.95-linux-x86_64-glibc23.tar.gz

[root@ecs-base xiazai]# wget  http://mirrors.sohu.com/php/php-5.4.31.tar.gz

[root@ecs-base xiazai]# wget  http://mirrors.sohu.com/nginx/nginx-1.9.9.tar.gz

安装一些编译需要用到的组件

[root@ecs-base xiazai]#  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

开始编译安装lnmp

1、安装mysql

[root@ecs-base xiazai]# tar -zxvf mysql-5.0.95-linux-x86_64-glibc23.tar.gz

[root@ecs-base xiazai]# mv mysql-5.0.95-linux-x86_64-glibc23 /www/server/mysql

2、新建指定用户

[root@ecs-base xiazai]# useradd  -M -s /sbin/nologin mysql

[root@ecs-base xiazai]# cd /www/server/mysql/

3、新建数据库存放目录

[root@ecs-base mysql]# mkdir -p /www/data/mysqldata

[root@ecs-base mysql]# chown -R mysql:mysql /www/data/mysqldata

4、初始化数据库

[root@ecs-base mysql]#  ./scripts/mysql_install_db --user=mysql --datadir=/www/data/mysqldata --basedir=/www/server/mysql/

有显示两个OK表示初始化完毕,否则需要检查下是否历史遗留mysql

5、配置mysql

[root@ecs-base mysql]# cp support-files/my-large.cnf /etc/my.cnf

cp: overwrite `/etc/my.cnf'? y  你可以先把原来的my.cnf改名不然拷贝过去就会提示是否覆盖

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

[root@ecs-base mysql]# chmod 755 /etc/init.d/mysqld

[root@ecs-base mysql]# vi /etc/init.d/mysqld

basedir=/www/server/mysql
datadir=/www/data/mysqldata

设置mysql安装路径和数据库库存放路径

6、加入开启启动,并启动mysql

[root@ecs-base mysql]# chkconfig --add mysqld 

[root@ecs-base mysql]# chkconfig mysqld on

[root@ecs-base mysql]# /etc/init.d/mysqld start

Starting MySQL.                                            [  OK  ]      

7、设置mysql管理员密码,并加入变量中

[root@ecs-base mysql]# /www/server/mysql/bin/mysqladmin -u root password 你的密码

[root@ecs-base mysql]# echo "PATH=$PATH:/www/server/mysql/bin" >> /etc/profile

[root@ecs-base mysql]# source /etc/profile

安装php

1、安装jpeg组件

[root@ecs-base mysql]# cd /www/xiazai/

[root@ecs-base xiazai]# wget http://mirrors.ahaoyw.com/autoconf/lin/PHP/extension/jpegsrc.v6b.tar.gz

[root@ecs-base xiazai]# tar -zxvf jpegsrc.v8b.tar.gz

[root@ecs-base xiazai]# cd jpeg-8b/

[root@ecs-base jpeg-8b]# ./configure --prefix=/usr/local/jpeg --enable-shared --enable-static

[root@ecs-base jpeg-8b]# make && make install

2、安装libmcrypt组件

[root@ecs-base jpeg-8b]# cd /www/xiazai/

[root@ecs-base xiazai]# wget http://mirrors.ahaoyw.com/autoconf/lin/PHP/extension/libmcrypt-2.5.8.tar.gz

[root@ecs-base xiazai]# tar -zxvf libmcrypt-2.5.8.tar.gz

[root@ecs-base xiazai]# cd libmcrypt-2.5.8

[root@ecs-base libmcrypt-2.5.8]# ./configure --prefix=/usr/local/libmcrypt

[root@ecs-base libmcrypt-2.5.8]# make && make install

#安装freetype

[root@ecs-base ~]# cd /www/xiazai/

[root@ecs-base xiazai]# wget  http://mirrors.ahaoyw.com/autoconf/lin/PHP/extension/freetype-2.1.10.tar.gz

[root@ecs-base xiazai]# tar zxvf freetype-2.1.10.tar.gz

[root@ecs-base xiazai]# cd freetype-2.1.10

[root@ecs-base freetype-2.1.10]# ./configure --prefix=/usr/local/freetype.2.1.10

[root@ecs-base freetype-2.1.10]# make && make install

[root@ecs-base freetype-2.1.10]# cd /www/xiazai/

[root@ecs-base xiazai]# wget http://mirrors.ahaoyw.com/autoconf/lin/PHP/extension/libpng-1.2.50.tar.gz

[root@ecs-base xiazai]# tar -zxvf libpng-1.2.50.tar.gz

[root@ecs-base xiazai]# cd libpng-1.2.50

[root@ecs-base libpng-1.2.50]# ./configure --prefix=/usr/local/libpng.1.2.50

[root@ecs-base libpng-1.2.50]# make && make install

#安装php

[root@ecs-base libpng-1.2.50]# cd /www/xiazai/

[root@ecs-base xiazai]# tar -zxvf php-5.4.31.tar.gz

[root@ecs-base xiazai]# cd php-5.4.31

#新建php运行账号

[root@ecs-base php-5.4.31]# useradd -s /sbin/nologin -M php-fpm

#编译php

# ./configure --prefix=/www/server/php --with-config-file-path=/www/server/php/etc --enable-fpm --with-fpm-user=php-fpm --with-fpm-group=php-fpm --with-mysql=/www/server/mysql --with-mysql-sock=/tmp/mysql.sock --with-libxml-dir --with-gd --with-jpeg-dir=/usr/local/jpeg --with-png-dir=/usr/local/libpng.1.2.50 --with-freetype-dir=/usr/local/freetype.2.1.10 --with-iconv-dir --with-zlib-dir --with-mcrypt=/usr/local/libmcrypt --enable-soap --enable-gd-native-ttf --enable-ftp --enable-mbstring --enable-exif --enable-zend-multibyte --disable-ipv6 --with-pear --with-curl --with-openssl

[root@ecs-base php-5.4.31]# make   

[root@ecs-base php-5.4.31]# make install

#拷贝配置文件

[root@ecs-base php-5.4.31]# cp php.ini-production /www/server/php/etc/php.ini

[root@ecs-base php-5.4.31]# cp sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm

[root@ecs-base php-5.4.31]# chmod 755 /etc/init.d/php-fpm

[root@ecs-base php-5.4.31]# chkconfig --add php-fpm

[root@ecs-base php-5.4.31]# chkconfig php-fpm on

编辑配置文件

[root@ecs-base php-5.4.31]# vi /www/server/php/etc/php-fpm.conf 

多版本php建议用监听sock文件

[global]
pid = /www/server/php/var/run/php-fpm.pid
error_log = /www/server/php/var/log/php-fpm.log
[www]
#listen = /tmp/php-fcgi.sock
listen = 127.0.0.1:9000
user = php-fpm
group = php-fpm
listen.owner = nobody
listen.group = nobody
pm = dynamic
pm.max_children = 50
pm.start_servers = 20
pm.min_spare_servers = 5
pm.max_spare_servers = 35
pm.max_requests = 500
rlimit_files = 1024

效验配置文件是否正确,并启动

[root@ecs-base php-5.4.31]# /www/server/php/sbin/php-fpm -t 

[root@ecs-base php-5.4.31]# /etc/init.d/php-fpm start

Starting php-fpm  done

 ##安装nginx

[root@ecs-base php-5.4.31]# cd /www/xiazai/

[root@ecs-base xiazai]# wget http://mirrors.ahaoyw.com/autoconf/lin/Nginx/nginx-1.9.9.tar.gz

[root@ecs-base xiazai]# tar -zxvf nginx-1.9.9.tar.gz

[root@ecs-base xiazai]# cd nginx-1.9.9

[root@ecs-base nginx-1.9.9]# yum install pcre* -y

[root@ahlinux nginx-1.9.9]# ./configure --prefix=/www/server/nginx --with-http_realip_module --with-http_sub_module --with-http_gzip_static_module --with-http_stub_status_module  --with-pcre


[root@ahlinux nginx-1.9.9]# make &&make install

编辑启动脚本

[root@ahlinux nginx-1.9.9]# vi /etc/init.d/nginxd

#!/bin/bash
# chkconfig: - 30 21
# description: http service.
# Source Function Library. /etc/init.d/functions
# Nginx SettingsNGINX_SBIN="/www/server/nginx/sbin/nginx"
NGINX_CONF="/www/server/nginx/conf/nginx.conf"
NGINX_PID="/www/server/nginx/logs/nginx.pid"RETVAL=0
prog="Nginx"start() {
        echo -n $"Starting $prog: "
        mkdir -p /dev/shm/nginx_temp
        daemon $NGINX_SBIN -c $NGINX_CONF
        RETVAL=$?
        echo
        return $RETVAL}stop() {
        echo -n $"Stopping $prog: "
        killproc -p $NGINX_PID $NGINX_SBIN -TERM        rm -rf /dev/shm/nginx_temp
        RETVAL=$?
        echo
        return $RETVAL}reload(){
        echo -n $"Reloading $prog: "
        killproc -p $NGINX_PID $NGINX_SBIN -HUP
        RETVAL=$?
        echo
        return $RETVAL}restart(){
        stop
        start}configtest(){
    $NGINX_SBIN -c $NGINX_CONF -t    return 0}case "$1" in
  start)
        start        ;;
  stop)
        stop        ;;
  reload)
        reload        ;;
  restart)
        restart        ;;
  configtest)
        configtest        ;;
  *)
        echo $"Usage: $0 {start|stop|reload|restart|configtest}"
        RETVAL=1
esacexit $RETVAL

##配置nginx

[root@ahlinux nginx-1.9.9]# cd /www/server/nginx/conf/

[root@ahlinux conf]# cp nginx.conf nginx.conf.bak

编辑配置文件

[root@ahlinux conf]# vi nginx.conf
user nobody nobody;
worker_processes 2;
error_log /www/server/nginx/logs/nginx_error.log crit;
pid /www/server/nginx/logs/nginx.pid;
worker_rlimit_nofile 51200;events{
    use epoll;
    worker_connections 6000;}http{
    include mime.types;
    default_type application/octet-stream;
    server_names_hash_bucket_size 3526;
    server_names_hash_max_size 4096;
    log_format combined_realip '$remote_addr $http_x_forwarded_for [$time_local]'
    '$host "$request_uri" $status'
    '"$http_referer" "$http_user_agent"';
    sendfile on;
    tcp_nopush on;
    keepalive_timeout 30;
    client_header_timeout 3m;
    client_body_timeout 3m;
    send_timeout 3m;
    connection_pool_size 256;
    client_header_buffer_size 1k;
    large_client_header_buffers 8 4k;
    request_pool_size 4k;
    output_buffers 4 32k;
    postpone_output 1460;
    client_max_body_size 10m;
    client_body_buffer_size 256k;
    client_body_temp_path /www/server/nginx/client_body_temp;
    proxy_temp_path /www/server/nginx/proxy_temp;
    fastcgi_temp_path /www/server/nginx/fastcgi_temp;
    fastcgi_intercept_errors on;
    tcp_nodelay on;
    gzip on;
    gzip_min_length 1k;
    gzip_buffers 4 8k;
    gzip_comp_level 5;
    gzip_http_version 1.1;
    gzip_types text/plain application/x-javascript text/css text/htm application/xml;
    include /www/server/nginx/conf/vhosts/*; }

新建单独站点配置文件存放目录

[root@ahlinux conf]# mkdir vhosts
[root@ahlinux vhosts]# vi localost.conf
server{
    listen 80;
    server_name localhost;
    index index.html index.htm index.php;
    root /www/data/default;

    location ~ \.php$ {
        include fastcgi_params;
        fastcgi_pass 127.0.0.1:9000    ;
        fastcgi_index index.php;
        fastcgi_param SCRIPT_FILENAME /www/data/default$fastcgi_script_name;
    }}
[root@ahlinux vhosts]# mkdir -p /www/data/default
[root@ahlinux vhosts]# echo "<?php phpinfo();?>" >/www/data/default/phpinfo.php
  #启动nginx+php 然后测试页面
  [root@ahlinux vhosts]# chmod 755 /etc/init.d/nginxd
  [root@ahlinux vhosts]# chkconfig --a nginxd


文章版权及转载声明

作者:不许人间见白头本文地址:https://www.ahaoyw.com/article/175.html发布于 2个月前 ( 12-15 )
文章转载或复制请以超链接形式并注明出处阿豪运维笔记

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

微信扫一扫打赏