• LNMP环境


    准备工作:
    1)把所有的软件安装在/usr/local/,源码包放在/package/,数据:自定义,日志文件:自定义

    创建www所属组及用户
    /usr/sbin/groupadd www
    /usr/sbin/useradd -g www www


    设置系统资源限制
    ulimit -SHn 65535


    下载各源码包:
    cd /package
    wget ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-8.42.tar.gz
    wget http://www.zlib.net/zlib-1.2.11.tar.gz
    wget https://www.openssl.org/source/old/1.1.1/openssl-1.1.1.tar.gz
    wget http://www.zlib.net/zlib-1.2.11.tar.gz
    wget http://nginx.org/download/nginx-1.9.6.tar.gz
    wget https://www.php.net/distributions/php-7.1.19.tar.gz
    wget https://curl.haxx.se/download/curl-7.64.0.tar.gz


    安装依赖:
    yum -y install make zlib zlib-devel gcc gcc-c++ libtool openssl openssl-devel lrzsz autoconf automake pcre* gd gd-devel


    nginx安装:
    useradd -M -s /sbin/nologin nginx
    cd /package
    tar -zxvf pcre-8.42.tar.gz -C /usr/local/
    tar -zxvf openssl-1.1.1.tar.gz -C /usr/local/
    tar -zxvf zlib-1.2.11.tar.gz -C /usr/local/


    mkdir -p /var/tmp/nginx/{fcgi,uwsgi,scgi,proxy}

    mkdir /var/log/nginx
    touch /var/log/nginx/{access.log,error.log}

    mkdir /var/run/nginx
    touch /var/run/nginx/nginx.pid

    mkdir /var/lock/
    touch /var/lock/nginx.lock


    tar -zxvf nginx-1.9.6.tar.gz
    cd nginx-1.9.6
    ./configure --prefix=/usr/local/nginx/
    --with-pcre=/usr/local/pcre-8.42
    --user=nginx --group=nginx
    --with-zlib=/usr/local/zlib-1.2.11
    --http-fastcgi-temp-path=/var/tmp/nginx/fcgi/
    --http-uwsgi-temp-path=/var/tmp/nginx/uwsgi
    --http-scgi-temp-path=/var/tmp/nginx/scgi
    --http-proxy-temp-path=/var/tmp/nginx/proxy/
    --http-log-path=/var/log/nginx/access.log
    --error-log-path=/var/log/nginx/error.log
    --pid-path=/var/run/nginx/nginx.pid
    --lock-path=/var/lock/nginx.lock
    --with-pcre=/usr/local/pcre-8.42/
    --with-http_stub_status_module
    --with-http_ssl_module
    --with-http_gzip_static_module
    --with-http_realip_module
    --with-http_image_filter_module
    --with-http_flv_module
    --with-http_mp4_module
    --with-http_gunzip_module
    --without-http_autoindex_module


    make -j2 && make install

    ln -s /usr/local/nginx/sbin/nginx /usr/bin/


    修改nginx配置文件:
    vim /usr/local/nginx/conf/nginx.conf
    user nginx nginx;
    error_log /var/log/nginx/error.log;
    pid /var/run/nginx/nginx.pid;
    charset koi8-r;
    .........
    .........
    location / {
    root html;
    index index.php index.html index.htm;                #这里加上index.php
    }
    #error_page 404 /404.html;
    ........
    .........
    location ~ .php$ {
    root html;
    fastcgi_pass 127.0.0.1:9000;
    fastcgi_index index.php;
    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;               #改成$document_root
    include fastcgi_params;
    }


    启动nginx:
    nginx -c /usr/local/nginx/conf/nginx.conf

    配置启动脚本:(service nginx start)
    vim /etc/init.d/nginx
    #!/bin/bash
    #chkconfig: 2345 99 20
    #description: nginx-server
    nginx=/usr/local/nginx/sbin/nginx

    case $1 in
    start)
      netstat -anptu | grep nginx
      if [ $? -eq 0 ];then
        echo "nginx service is already running"
      else
        echo "nginx Service started successfully "
        $nginx
      fi
    ;;
    stop)
      $nginx -s stop
      if [ $? -eq 0 ];then
        echo "nginx service closed successfully"
      else
        echo "nginx server stop fail,try again"
      fi
    ;;
    status)
        netstat -anlpt | grep nginx
        if [ $? -eq 0 ];then
          echo "nginx server is running"
        else
          echo "nginx service not started "
        fi
    ;;
    restart)
      $nginx -s reload
      if [ $? -eq 0 ];then
        echo "nginx service restart successfully "
      else
        echo "nginx server restart failed"
      fi
    ;;
    *)
      echo "please enter {start restart status stop}"
    ;;
    esac


    chmod +x /etc/init.d/nginx
    chkconfig --add nginx
    chkconfig nginx on


    配置nginx以守护进程方式启动:(systemctl start nginx)
    vim /lib/systemd/system/nginxd.service
    [Unit]
    Description=The Nginx HTTP Server
    After=network.target remote-fs.target nss-lookup.target

    [Service]
    Type=forking
    EnvironmentFile=/usr/local/nginx/conf/nginx.conf
    ExecStart=/usr/local/nginx/sbin/nginx
    ExecReload=/usr/local/nginx/sbin/nginx -s reload
    ExecStop=/usr/local/nginx/sbin/nginx -s stop
    KillSignal=SIGCONT
    PrivateTmp=true
    [Install]
    WantedBy=multi-user.target

    PHP安装:
    cd /package
    wget https://curl.haxx.se/download/curl-7.64.0.tar.gz
    tar -zxvf curl-7.64.0.tar.gz -C /usr/local/

    cd /usr/local/curl-7.64.0
    ./configure && make && make install

    yum -y install libxml2-devel libpng-devel libjpeg*
    cp -rp /usr/lib64/libpng* /usr/lib
    tar -zxvf php-7.1.19.tar.gz
    cd php-7.1.19
    ./configure --prefix=/usr/local/php7
    --with-gd
    --with-zlib
    --with-config-file-path=/usr/local/php7
    --enable-mbstring
    --enable-fpm
    --with-curl=/usr/local/curl-7.64.0    (如果没有源码安装curl就只写等号左边部分)


    make -j2 && make install


    配置PHP:
    cp /package/php-7.1.19/php.ini-production   /usr/local/php7/etc/php.ini
    cp /usr/local/php7/etc/php-fpm.conf.default   /usr/local/php7/etc/php-fpm.conf
    cp /usr/local/php7/etc/php-fpm.d/www.conf.default   /usr/local/php7/etc/php-fpm.d/www.conf
    ln -s /usr/local/php7/bin/*   /usr/local/bin/
    ln -s /usr/local/php7/sbin/*   /usr/local/sbin/


    配置php-fpm:
    cp /package/php-7.1.19/sapi/fpm/init.d.php-fpm  /etc/init.d/php-fpm
    chmod 755 /etc/init.d/php-fpm
    chkconfig --add php-fpm
    chkconfig php-fpm --level 2345 on
    vim /usr/local/php7/etc/php.ini
    date.timezone = PRC
    expose_php = Off
    short_open_tag = On
    opcache.enable_cli=0
    echo "zend_extension=opcache.so" >> /usr/local/php7/etc/php.ini


    让fpm随nginx一起启动,重启:
    vim /etc/init.d/nginx
    start)
           netstat -anptu | grep nginx
      if [ $? -eq 0 ];then
        /usr/local/php7/sbin/php-fpm >> /dev/null       #添加该句
        echo "nginx service is already running"
      else
        /usr/local/php7/sbin/php-fpm >> /dev/null      #添加该句
        echo "nginx Service started successfully "
    ....... 省略中间部分 .......
    stop)
      $nginx -s stop
      if [ $? -eq 0 ];then
      kill -s QUIT `cat /usr/local/php7/var/run/php-fpm.pid`>>/dev/null               #添加该句

    .......省略中间部分 .......

    restart)
      $nginx -s reload
      if [ $? -eq 0 ];then
        kill -s QUIT `cat /usr/local/php7/var/run/php-fpm.pid` >> /dev/null      #添加该句
        /usr/local/php7/sbin/php-fpm #添加该句
        echo "nginx service restart successfully "
      else
      echo -e "33[35mNginx is not started,nginx server restart failed33[0m"         #修改该句

    MYSQL安装:

    Centox7已经不支持mysql,因为一部分原因(比如收费)所以内部集成了mariadb,而安装mysql的话会和mariadb的文件冲突,所以必须先卸载掉mariadb

    for i in `rpm -qa|grep mariadb`;do rpm -e --nodeps $i;done

    for i in `rpm -qa|grep mysql`;do rpm -e --nodeps $i;done

    useradd mysql -s /sbin/nologin
    cd /package
    yum -y install cmake bison ncurses ncurses-devel wget gcc gcc-c++ (是接上面的,要是单独安装mysql需把上面yum的东西都装上)
    wget https://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-boost-5.7.25.tar.gz
    tar -zxvf mysql-boost-5.7.25.tar.gz
    cd mysql-5.7.25/

    cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql
    -DMYSQL_DATADIR=/usr/local/mysql/data
    -DDOWNLOAD_BOOST=1
    -DWITH_BOOST=/package/mysql-5.7.25/boost/boost_1_59_0
    -DSYSCONFDIR=/etc
    -DWITH_MYISAM_STORAGE_ENGINE=1
    -DWITH_INNOBASE_STORAGE_ENGINE=1
    -DWITH_ARCHIVE_STORAGE_ENGINE=1
    -DWITH_FEDERATED_STORAGE_ENGINE=1
    -DWITH_BLACKHOLE_STORAGE_ENGINE=1
    -DWITH_PARTITION_STORAGE_ENGINE=1
    -DWITH_READLINE=1
    -DMYSQL_UNIX_ADDR=/usr/local/mysql/mysql.sock
    -DMYSQL_TCP_PORT=3306
    -DENABLED_LOCAL_INFILE=1
    -DENABLE_DTRACE=0
    -DEXTRA_CHARSETS=all
    -DDEFAULT_CHARSET=utf8
    -DDEFAULT_COLLATION=utf8_general_ci
    -DMYSQL_USER=mysql


    make -j4 && make install

    创建数据存储目录
    mkdir -p /usr/local/mysql/data 
    chown -R mysql.mysql /usr/local/mysql/

    配置my.cnf文件
    vim /etc/my.cnf
    [mysqld]
    basedir=/usr/local/mysql
    datadir=/usr/local/mysql/data
    port=3306
    socket=/usr/local/mysql/mysql.sock
    character-set-server=utf8
    pid-file=/usr/local/mysql/mysqld.pid
    log-error=/var/log/mysqld.log

    explicit_defaults_for_timestamp=true


    配置MySQL启动脚本
    cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld
    chkconfig --add mysqld
    chkconfig mysqld on

    修改路径:
    vim /etc/init.d/mysqld
    basedir=/usr/local/mysql
    datadir=/usr/local/mysql/data


    配置环境变量(追加)
    vim /etc/profile
    export PATH=/usr/local/mysql/bin:$PATH
    source /etc/profile


    配置MySQL启动脚本,这个和上面的二选一都可以
    vim /lib/systemd/system/mysqld.service
    [Unit]
    Description=MySQL DBMS

    [Service]
    LimitNOFILE=10000
    Type=simple
    User=mysql
    Group=mysql
    PIDFile=/usr/local/mysql/mysqld.pid
    ExecStart=/usr/local/mysql/bin/mysqld_safe --datadir=/usr/local/mysql/data
    ExecStop=/bin/kill -9 $MAINPID

    [Install]
    WantedBy=multi-user.target

    chmod +x /lib/systemd/system/mysqld.service
    systemctl enable mysqld.service             #设置开机启动


    touch /var/log/mysqld.log
    chown -R mysql.mysql /var/log/mysqld.log
    mkdir /var/log/mariadb
    touch /var/log/mariadb/mariadb.log
    chown -R mysql.mysql /var/log/mariadb/


    初始数据库:
    /usr/local/mysql/bin/mysqld --initialize --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data
    注1:这一步执行完后会在最后一行的最后生成一个mysql的root登录密码,需注意
    注2:如果要想初始化之后分配临时密码,可以将--initialize写成--initialize-insecure 部分去掉,初始化之后,可以分配到一个临时密码。
    注3:密码在/var/log/mysqld.log中的最后,我的是 Aq&wBPyzP1ri,每次会不同

    启动数据库:
    /etc/init.d/mysqld start
    mysql -uroot -p              #这里的密码是在 /var/log/mysqld.log中的最后那个密码

    ALTER USER USER() IDENTIFIED BY '123456';          #必须先alter一下才行
    grant all privileges on *.* to 'root'@'localhost' identified by '<passworld>';
    grant all privileges on *.* to 'root'@'%' identified by '<passworld>';

    Linux下PHP安装curl扩展:
    cd /package
    wget https://curl.haxx.se/download/curl-7.64.0.tar.gz
    tar -zxvf curl-7.64.0.tar.gz
    cd curl-7.64.0
    ./configure --prefix=/usr/local/curl
    make -j2 && make install

    cd /package/php-7.1.19
    ./configure --prefix=/usr/local/php7
    --with-gd
    --with-zlib
    --with-config-file-path=/usr/local/php7
    --enable-mbstring
    --enable-fpm
    --with-curl=/usr/local/curl

    make -j2 && make install

    重启php生效
    service nginx start {stop}

  • 相关阅读:
    无语的index hint:手工分配哈希区,5小时不出结果,优化后20分钟
    EL 表达式中自己定义函数
    关于SetCapture() 和 ReleaseCapture()的使用方法
    MySql的like语句中的通配符:百分号、下划线和escape
    字符串匹配之horspool算法(简化的BM算法)
    strcmp函数和strcpy函数
    ehci符合USB2.0,uhci,ohci,
    软件发布版本区别介绍-Alpha,Beta,RC,Release
    Wi-Fi定位,AP定位
    CentOS 启动提示unexpected inconsistency;RUN fsck MANUALLY, ntfs的input/output Error,InPageError c000009c使用chkdsk修复磁盘,12款Linux系统恢复工具
  • 原文地址:https://www.cnblogs.com/smlile-you-me/p/10610154.html
Copyright © 2020-2023  润新知