zoukankan      html  css  js  c++  java
  • Centos下lnmp编译安装详细过程 新风宇宙

    整理下lnmp安装步骤:

    相关软件用的lnmp一键安装的全包,懒得去到处找软件源

    完整版:http://soft.vpser.net/lnmp/lnmp0.7-full.tar.gz(66.64MB)                

    1.系统安装必要软件

    sudo -s   LANG=C   yum -y install gcc gcc-c++ autoconf libjpeg libjpeg-devel libpng libpng-devel freetype libevent libevent-devel freetype-devel libxml2 libxml2-devel zlib zlib-devel pam-devel glibc glibc-devel glib2 glib2-devel bzip2 bzip2-devel ncurses ncurses-devel curl curl-devel e2fsprogs e2fsprogs-devel krb5 krb5-devel libidn libidn-devel openssl openssl-devel openldap openldap-devel nss_ldap openldap-clients openldap-servers  

    2.安装一些类库

    libiconv

    tar zxvf libiconv-1.13.1.tar.gz   

    cd libiconv-1.13.1/   

    ./configure --prefix=/usr/local   

    make   

    make install   

    cd ../  

    libmcrypt

     tar zxvf libmcrypt-2.5.8.tar.gz    
        cd libmcrypt-2.5.8/   
        ./configure   
        make   
        make install   
        /sbin/ldconfig   
        cd libltdl/   
        ./configure --enable-ltdl-install   
        make   
        make install   
        cd http://www.cnblogs.com/ 

    mhash
        tar zxvf mhash-0.9.9.9.tar.gz   
        cd mhash-0.9.9.9/   
        ./configure   
        make   
        make install   
        cd ../ 


    mcrypt
        tar zxvf mcrypt-2.6.8.tar.gz   
        cd mcrypt-2.6.8/   
        /sbin/ldconfig   
        ./configure   
        make   
        make install   
        cd ../  

    链接地址
        ln -s /usr/local/lib/libmcrypt.la /usr/lib/libmcrypt.la   
        ln -s /usr/local/lib/libmcrypt.so /usr/lib/libmcrypt.so   
        ln -s /usr/local/lib/libmcrypt.so.4 /usr/lib/libmcrypt.so.4  
        ln -s /usr/local/lib/libmcrypt.so.4.4.8 /usr/lib/libmcrypt.so.4.4.8  
        ln -s /usr/local/lib/libmhash.a /usr/lib/libmhash.a   
        ln -s /usr/local/lib/libmhash.la /usr/lib/libmhash.la   
        ln -s /usr/local/lib/libmhash.so /usr/lib/libmhash.so   
        ln -s /usr/local/lib/libmhash.so.2 /usr/lib/libmhash.so.2  
        ln -s /usr/local/lib/libmhash.so.2.0.1 /usr/lib/libmhash.so.2.0.1  
        ln -s /usr/local/bin/libmcrypt-config /usr/bin/libmcrypt-config 

    安装Mysql
    添加mysql组和用户
        /usr/sbin/groupadd mysql   
        /usr/sbin/useradd -g mysql mysql  

    解压
        tar zxvf mysql-5.1.51.tar.gz   
        cd mysql-5.1.51   
        ./configure  --prefix=/usr/local/mysql --enable-assembler --with-extra-charsets=complex --enable-thread-safe-client --with-big-tables --with-readline --with-ssl --with-embedded-server --enable-local-infile --with-plugins=partition,innobase,myisammrg   
        make && make install  

    设置权限
        chmod +w /usr/local/mysql   
        chown -R mysql:mysql /usr/local/mysql  

    创建mysql使用目录
        mkdir -p /data/mysql/data/   
        mkdir -p /data/mysql/binlog/   
        mkdir -p /data/mysql/relaylog/   
        chown -R mysql:mysql /data/mysql/  

    初始化mysql库
        /usr/local/mysql/bin/mysql_install_db --basedir=/usr/local/mysql --datadir=/data/mysql/data --user=mysql   

    编辑mysql的配置
        vi /data/mysql/my.cnf  

    配置文件正文
        [client]   
        character-set-server = utf8   
        port    = 3306   
        socket  = /tmp/mysql.sock   
          
        [mysqld]   
        character-set-server = utf8   
        replicate-ignore-db = mysql   
        replicate-ignore-db = test   
        replicate-ignore-db = information_schema   
        user    = mysql   
        port    = 3306   
        socket  = /tmp/mysql.sock   
        basedir = /usr/local/mysql   
        datadir = /data/mysql/data   
        log-error = /data/mysql/mysql_error.log   
        pid-file = /data/mysql/mysql.pid   
        open_files_limit    = 10240   
        back_log = 600   
        max_connections = 5000   
        max_connect_errors = 6000   
        table_cache = 614   
        external-locking = FALSE   
        max_allowed_packet = 32M   
        sort_buffer_size = 1M   
        join_buffer_size = 1M   
        thread_cache_size = 300   
        #thread_concurrency = 8   
        query_cache_size = 512M   
        query_cache_limit = 2M   
        query_cache_min_res_unit = 2k   
        default-storage-engine = MyISAM   
        thread_stack = 192K   
        transaction_isolation = READ-COMMITTED   
        tmp_table_size = 246M   
        max_heap_table_size = 246M   
        long_query_time = 3   
        log-slave-updates   
        log-bin = /data/mysql/binlog/binlog   
        binlog_cache_size = 4M   
        binlog_format = MIXED   
        max_binlog_cache_size = 8M   
        max_binlog_size = 1G   
        relay-log-index = /data/mysql/relaylog/relaylog   
        relay-log-info-file = /data/mysql/relaylog/relaylog   
        relay-log = /data/mysql/relaylog/relaylog   
        expire_logs_days = 30   
        key_buffer_size = 256M   
        read_buffer_size = 1M   
        read_rnd_buffer_size = 16M   
        bulk_insert_buffer_size = 64M   
        myisam_sort_buffer_size = 128M   
        myisam_max_sort_file_size = 10G   
        myisam_repair_threads = 1   
        myisam_recover   
          
        interactive_timeout = 120   
        wait_timeout = 120   
          
        skip-name-resolve   
        #master-connect-retry = 10   
        slave-skip-errors = 1032,1062,126,1114,1146,1048,1396   
          
        #master-host     =   192.168.1.2   
        #master-user     =   username   
        #master-password =   password   
        #master-port     =  3306   
          
        server-id = 1   
          
        innodb_additional_mem_pool_size = 16M   
        innodb_buffer_pool_size = 512M   
        innodb_data_file_path = ibdata1:256M:autoextend   
        innodb_file_io_threads = 4   
        innodb_thread_concurrency = 8   
        innodb_flush_log_at_trx_commit = 2   
        innodb_log_buffer_size = 16M   
        innodb_log_file_size = 128M   
        innodb_log_files_in_group = 3   
        innodb_max_dirty_pages_pct = 90   
        innodb_lock_wait_timeout = 120   
        innodb_file_per_table = 0   
          
        #log-slow-queries = /data/mysql/slow.log   
        #long_query_time = 10   
          
        [mysqldump]   
        quick   
        max_allowed_packet = 32M   
          

    添加mysql操作
        vi /data/mysql/mysql  

    内容如下:
        #!/bin/sh   
          
        mysql_port=3306  
        mysql_username="admin"  
        mysql_password="12345678"  
          
        function_start_mysql()   
        {   
            printf "Starting MySQL...\n"  
            /bin/sh /usr/local/mysql/bin/mysqld_safe --defaults-file=/data/mysql/my.cnf 2>1 > /dev/null &   
        }   
          
        function_stop_mysql()   
        {   
            printf "Stoping MySQL...\n"  
            /usr/local/mysql/bin/mysqladmin -u ${mysql_username} -p${mysql_password} -S /tmp/mysql.sock shutdown   
        }   
          
        function_restart_mysql()   
        {   
            printf "Restarting MySQL...\n"  
            function_stop_mysql   
            sleep 5  
            function_start_mysql   
        }   
          
        function_kill_mysql()   
        {   
            kill -9 $(ps -ef 124; grep 'bin/mysqld_safe' 124; grep ${mysql_port} 124; awk '{printf $2}')   
            kill -9 $(ps -ef 124; grep 'libexec/mysqld' 124; grep ${mysql_port} 124; awk '{printf $2}')   
        }   
          
        if [ "$1" = "start" ]; then   
            function_start_mysql   
        elif [ "$1" = "stop" ]; then   
            function_stop_mysql   
        elif [ "$1" = "restart" ]; then   
        function_restart_mysql   
        elif [ "$1" = "kill" ]; then   
        function_kill_mysql   
        else  
            printf "Usage: /data/mysql/mysql {start|stop|restart|kill}\n"  
        fi   
          

    添加执行权限
        chmod +x /data/mysql/mysql  

    启动mysql
        /data/mysql/mysql start  

    netstat -an ,检查3306端口没有启动。

    通过命令行登录MySQL
     /usr/local/mysql/bin/mysql -u root -p 



    安装PHP
        /usr/sbin/useradd www   
        mkdir -p /data/htdocs   
        export PHP_AUTOCONF=/usr/local/autoconf-2.13/bin/autoconf
    export PHP_AUTOHEADER=/usr/local/autoconf-2.13/bin/autoheader
    tar zxvf php-5.2.17.tar.gz
    gzip -cd php-5.2.17-fpm-0.5.14.diff.gz | patch -d php-5.2.17 -p1
    cd php-5.2.17/
    ./buildconf --force
    ./configure --prefix=/usr/local/php --with-config-file-path=/usr/local/php/etc --with-mysql=/usr/local/mysql --with-mysqli=/usr/local/mysql/bin/mysql_config --with-iconv-dir --with-freetype-dir --with-jpeg-dir --with-png-dir --with-zlib --with-libxml-dir=/usr --enable-xml --disable-rpath --enable-discard-path --enable-magic-quotes --enable-safe-mode --enable-bcmath --enable-shmop --enable-sysvsem --enable-inline-optimization --with-curl --with-curlwrappers --enable-mbregex --enable-fastcgi --enable-fpm --enable-force-cgi-redirect --enable-mbstring --with-mcrypt --enable-ftp --with-gd --enable-gd-native-ttf --with-openssl --with-mhash --enable-pcntl --enable-sockets --with-xmlrpc --enable-zip --enable-soap --without-pear --with-gettext --with-mime-magic 
    make ZEND_EXTRA_LIBS='-liconv'
    make install

     mkdir /etc/php   
        cp php.ini-production /etc/php/php.ini   
        vi /etc/php/php.ini  

    配置php.ini

    cp php.ini-dist  /usr/local/php/php.ini

    修改扩展的目录
    extension_dir = "/usr/local/php/lib/php/extensions/no-debug-non-zts-200690613/" 

    设为0

    cgi.fix_pathinfo=0  

    配置php-fpm

     mv /usr/local/php/etc/php-fpm.conf /usr/local/php/etc/php-fpm.conf 

    在124行位置(大概这里)增加

      <value name="user">www</value>
    <value name="group">www</value>

    启动php

    ulimit -SHn 65535   
      /usr/local/php/sbin/php-fpm start

    安装MYSQL PDO 
    tar zxvf PDO_MYSQL-1.0.2.tgz   
        cd PDO_MYSQL-1.0.2/   
        /usr/local/php/bin/phpize   
        ./configure --with-php-config=/usr/local/php/bin/php-config --with-pdo-mysql=/usr/local/mysql   
        make   
        make install   
        cd ..  

    在php.ini里添加
    extension = "pdo_mysql.so"  

    安装nginx

    tar zxvf pcre-8.12.tar.gz
    cd pcre-8.12/
    ./configure
    make && make install
    cd ../

    tar zxvf nginx-0.8.54.tar.gz
    cd nginx-0.8.54/
    ./configure --user=www --group=www --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module --with-http_gzip_static_module --with-ipv6
    make && make install
    cd ../

     mkdir -p /data/logs   
        chmod +w /data/logs   
        chown -R www:www /data/logs  

        chmod +w /data/htdocs   
        chown -R www:www /data/htdocs  


    修改nginx的配置文件
    vi /usr/local/nginx/conf/nginx.conf  

    user  www www;

    worker_processes 8;

    error_log  /data/logs/nginx_error.log  crit;

    pid        /usr/local/nginx/nginx.pid;

    #Specifies the value for maximum file descriptors that can be opened by this process.
    worker_rlimit_nofile 65535;

    events
    {
      use epoll;
      worker_connections 65535;
    }

    http
    {
      include       mime.types;
      default_type  application/octet-stream;

      #charset  gb2312;
          
      server_names_hash_bucket_size 128;
      client_header_buffer_size 32k;
      large_client_header_buffers 4 32k;
      client_max_body_size 8m;
          
      sendfile on;
      tcp_nopush     on;

      keepalive_timeout 60;

      tcp_nodelay on;

      fastcgi_connect_timeout 300;
      fastcgi_send_timeout 300;
      fastcgi_read_timeout 300;
      fastcgi_buffer_size 64k;
      fastcgi_buffers 4 64k;
      fastcgi_busy_buffers_size 128k;
      fastcgi_temp_file_write_size 128k;

      gzip on;
      gzip_min_length  1k;
      gzip_buffers     4 16k;
      gzip_http_version 1.0;
      gzip_comp_level 2;
      gzip_types       text/plain application/x-javascript text/css application/xml;
      gzip_vary on;

      #limit_zone  crawler  $binary_remote_addr  10m;

      server
      {
        listen       80;
        server_name  localhost;
        index index.html index.htm index.php;
        root  /data/htdocs;

        #limit_conn   crawler  20;    
                                
        location ~ .*\.(php|php5)?$
        {      
          #fastcgi_pass  unix:/tmp/php-cgi.sock;
          fastcgi_pass  127.0.0.1:9000;
          fastcgi_index index.php;
          include fastcgi.conf;
        }
        
        location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
        {
          expires      30d;
        }

        location ~ .*\.(js|css)?$
        {
          expires      1h;
        }    

        log_format  access  '$remote_addr - $remote_user [$time_local] "$request" '
                  '$status $body_bytes_sent "$http_referer" '
                  '"$http_user_agent" $http_x_forwarded_for';
        access_log  /data/logs/access.log  access;
          }


    }

    然后在fastcgi.conf加上

     在fastcgi_param  SCRIPT_NAME        $fastcgi_script_name;

    前面加上:

    fastcgi_param  SCRIPT_FILENAME    $document_root$fastcgi_script_name;  

    启动nginx
    /usr/local/nginx/sbin/nginx   

    设置开机自启动
     vi /etc/rc.local  


     ulimit -SHn 65535   
     /usr/local/php/sbin/php-fpm start   
     /usr/local/nginx/sbin/nginx   
     /data/mysql/mysql start  

    至此,mysql, php, nginx 安装完成。

  • 相关阅读:
    网络性能测试工具iperf详解
    linux下的抓包工具tshark和 tcpdump用法
    linux下网络发包工具
    >/dev/null 2>&1 的作用
    linux screen 命令详解
    wget 命令操作实例
    Centos Linux release 7.2.15ll (core) yum 安装java环境
    日志监听
    java 身份证工具类
    java 生成微信的二维码 工具类
  • 原文地址:https://www.cnblogs.com/php5/p/2773576.html
Copyright © 2011-2022 走看看