• centos6.8下安装部署LNMP(备注:nginx1.8.0+php5.6.10+mysql5.6.12)


    在平时运维工作中,经常需要用到LNMP应用框架。
    以下对LNMP环境部署记录下:

    1)前期准备:为了安装顺利,建议先使用yum安装依赖库
    [root@opd ~]#yum install -y make cmake gcc gcc-c++ autoconf automake libpng-devel libjpeg-devel zlib libxml2-devel ncurses-devel bison libtool-ltdl-devel libiconv libmcrypt mhash mcrypt libmcrypt-devel pcre-devel openssl-devel freetype-devel libcurl-devel

    2)安装nginx
    [root@opd ~]#cd /opt/src
    [root@src ~]#wget http://nginx.org/download/nginx-1.8.0.tar.gz
    [root@src ~]#tar -zxvf nginx-1.8.0.tar.gz
    [root@src ~]#cd nginx-1.8.0
    添加www用户,其中-M参数表示不添加用户家目录,-s参数表示指定shell类型
    [root@nginx-1.8.0 ~]#useradd www -M -s /sbin/nologin
    [root@nginx-1.8.0 ~]#vim auto/cc/gcc
    将这句注释掉取消Debug编译模式 大概在179行
    #CFLAGS="$CFLAGS -g"

    我们再配置下nginx编译参数
    [root@nginx-1.8.0 ~]#./configure --prefix=/opt/nginx --user=www --group=www --with-http_stub_status_module --with-http_ssl_module
    [root@nginx-1.8.0 ~]#make
    [root@nginx-1.8.0 ~]#make install clean
    添加开机自启动
    [root@nginx-1.8.0 ~]#vim /etc/rc.local
    在这个文件里面添加:/opt/nginx/sbin/nginx
    [root@nginx-1.8.0 ~]#/opt/nginx/sbin/nginx

    ----------------------------------顺便说下:Centos7采用yum方式安装nginx-----------------------------------
    centos7系统库中默认是没有nginx的rpm包的,所以我们自己需要先更新下rpm依赖库
    1)使用yum安装nginx需要包括Nginx的库,安装Nginx的库
    # rpm -Uvh http://nginx.org/packages/centos/7/noarch/RPMS/nginx-release-centos-7-0.el7.ngx.noarch.rpm

    2)使用下面命令安装nginx
    # yum install nginx

    3)启动Nginx
    # service nginx start

    # systemctl start nginx.service
    ---------------------------------------------------------------------------------------------------------

    3)安装PHP
    由于PHP需要这些类库的支撑
    先下载PHP
    [root@opd ~]#cd /opt/src/
    [root@src ~]#wget http://cn2.php.net/distributions/php-5.6.10.tar.gz
    [root@src ~]#tar -zxvf php-5.6.10.tar.gz
    [root@src ~]#cd php-5.6.10
    我们先配置下PHP的编译参数
    [root@php-5.6.10 ~]#./configure --prefix=/opt/php --with-mysql --with-mysqli --with-iconv-dir --with-zlib --with-libxml-dir --enable-xml --with-curl --enable-fpm --enable-mbstring --with-gd --with-openssl --with-mhash --enable-sockets --with-xmlrpc --enable-zip --enable-soap --with-libdir=/usr/lib64 --with-jpeg-dir=/usr/lib64 --with-freetype-dir=/usr/lib64 --with-png-dir=/usr/lib64
    [root@php-5.6.10 ~]#make
    [root@php-5.6.10 ~]#make install clean
    复制php.ini
    [root@php-5.6.10 ~]#cp php.ini-development /opt/php/lib/php.ini
    [root@php-5.6.10 ~]#cd /opt/php/etc/
    [root@php-5.6.10 ~]#cp php-fpm.conf.default php-fpm.conf        //在php-fpm.conf文件中可以定义php的服务端口、进程启动的用户和组权限(最好和nginx服务启动权限一直)等。
    使用PHP-FPM管理脚本,在编译包里面已经配置好了,只需要复制到/etc/init.d/中即可
    [root@php-5.6.10 ~]#cd /opt/src/php-5.6.10/sapi/fpm/
    [root@php-5.6.10 ~]#cp init.d.php-fpm /etc/init.d/php-fpm
    [root@php-5.6.10 ~]#chmod +x /etc/init.d/php-fpm
    启动php-fpm
    [root@php-5.6.10 ~]#service php-fpm start   or   /etc/init.d/php-fpm restart
    加入开机启动策略
    [root@php-5.6.10 ~]#chkconfig --add php-fpm
    [root@php-5.6.10 ~]#chkconfig php-fpm on

    ---------------------------------------------------------------------------------------------------------

    安装mysql5.6.36

    #!/bin/bash
    #卸载系统自带的Mysql
    /bin/rpm -e $(/bin/rpm -qa | grep mysql|xargs) --nodeps
    /bin/rm -f /etc/my.cnf
     
    #安装编译代码需要的包
    /usr/bin/yum -y install make gcc-c++ cmake bison-devel ncurses-devel
     
    #编译安装mysql5.6
    /usr/sbin/groupadd mysql
    /usr/sbin/useradd -g mysql mysql -M -s /sbin/nologin
     
    cd /usr/local/src
    wget -c http://ftp.ntu.edu.tw/MySQL/Downloads/MySQL-5.6/mysql-5.6.36.tar.gz
    /bin/tar -zxvf mysql-5.6.36.tar.gz
    cd mysql-5.6.36/
    /usr/bin/cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DMYSQL_DATADIR=/data/mysql/data -DSYSCONFDIR=/etc -DWITH_MYISAM_STORAGE_ENGINE=1 -DWITH_INNOBASE_STORAGE_ENGINE=1 -DWITH_MEMORY_STORAGE_ENGINE=1 -DWITH_READLINE=1 -DMYSQL_UNIX_ADDR=/var/lib/mysql/mysql.sock -DMYSQL_TCP_PORT=3306 -DENABLED_LOCAL_INFILE=1 -DWITH_PARTITION_STORAGE_ENGINE=1 -DEXTRA_CHARSETS=all -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci
    make && make install
     
    #修改/usr/local/mysql权限
    mkdir -p /data/mysql/data
    /bin/chown -R mysql:mysql /usr/local/mysql
    /bin/chown -R mysql:mysql /data/mysql/data
     
    #执行初始化配置脚本,创建系统自带的数据库和表
    /usr/local/mysql/scripts/mysql_install_db --basedir=/usr/local/mysql --datadir=/data/mysql/data --user=mysql
     
    #配置my.cnf
    cat > /usr/local/mysql/my.cnf << EOF
    [client]
    port = 3306
    socket = /usr/local/mysql/var/mysql.sock
     
    [mysqld]
    port = 3306
    socket = /usr/local/mysql/var/mysql.sock
     
    basedir = /usr/local/mysql/
    datadir = /data/mysql/data
    pid-file = /data/mysql/data/mysql.pid
    user = mysql
    bind-address = 0.0.0.0
    server-id = 1
    sync_binlog=1
    log_bin = mysql-bin
     
    skip-name-resolve
    #skip-networking
    back_log = 600
     
    max_connections = 3000
    max_connect_errors = 3000
    ##open_files_limit = 65535
    table_open_cache = 512
    max_allowed_packet = 16M
    binlog_cache_size = 16M
    max_heap_table_size = 16M
    tmp_table_size = 256M
     
    read_buffer_size = 1024M
    read_rnd_buffer_size = 1024M
    sort_buffer_size = 1024M
    join_buffer_size = 1024M
    key_buffer_size = 8192M
     
    thread_cache_size = 8
     
    query_cache_size = 512M
    query_cache_limit = 1024M
     
    ft_min_word_len = 4
     
    binlog_format = mixed
    expire_logs_days = 30
     
    log_error = /data/mysql/data/mysql-error.log
    slow_query_log = 1
    long_query_time = 1
    slow_query_log_file = /data/mysql/data/mysql-slow.log
     
    performance_schema = 0
    explicit_defaults_for_timestamp
     
    ##lower_case_table_names = 1
     
    skip-external-locking
     
    default_storage_engine = InnoDB
    ##default-storage-engine = MyISAM
    innodb_file_per_table = 1
    innodb_open_files = 500
    innodb_buffer_pool_size = 1024M
    innodb_write_io_threads = 1000
    innodb_read_io_threads = 1000
    innodb_thread_concurrency = 8
    innodb_purge_threads = 1
    innodb_flush_log_at_trx_commit = 2
    innodb_log_buffer_size = 4M
    innodb_log_file_size = 32M
    innodb_log_files_in_group = 3
    innodb_max_dirty_pages_pct = 90
    innodb_lock_wait_timeout = 120
     
    bulk_insert_buffer_size = 8M
    myisam_sort_buffer_size = 8M
    myisam_max_sort_file_size = 10G
    myisam_repair_threads = 1
     
    interactive_timeout = 28800
    wait_timeout = 28800
     
    [mysqldump]
    quick
    max_allowed_packet = 16M
     
    [myisamchk]
    key_buffer_size = 8M
    sort_buffer_size = 8M
    read_buffer = 4M
    write_buffer = 4M
     
    sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
    port = 3306
    EOF
     
    #启动mysql服务
    cd /usr/local/mysql
    /bin/mkdir var
    /bin/chown -R mysql.mysql var
    cp support-files/mysql.server /etc/init.d/mysql
    /sbin/chkconfig mysql on
    service mysql start
     
    #设置环境变量
    echo "export PATH=$PATH:/usr/local/mysql/bin" >> /etc/profile
    source /etc/profile
     
    #设置mysql登陆密码,初始密码为123456
    /bin/mkdir -p /var/lib/mysql
    ln -s /usr/local/mysql/var/mysql.sock /var/lib/mysql/mysql.sock
    mysql -e "SET PASSWORD = PASSWORD('123456');"
    mysql -p123456 -e "GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'password' WITH GRANT OPTION;"
    mysql -p123456 -e "FLUSH PRIVILEGES;"
    

      

  • 相关阅读:
    32位IP地址
    我们必须知道,我们终将知道。
    【Java 小白菜入门笔记 2.1】面向对象相关
    【Java 小白菜入门笔记 1.3】流程控制、数组和输入输出
    【Java 小白菜入门笔记 1.2】运算符、方法和语句
    【Java 小白菜入门笔记 1.1】常量和变量
    【论文笔记】PyTorch-BigGraph: A Large-scale Graph Embedding Framework(大规模图嵌入)
    【Java 小白菜入门笔记 1.0】简介与HelloWorld
    【NLP模型笔记】GloVe模型简介
    Python中的defaultdict函数
  • 原文地址:https://www.cnblogs.com/nulige/p/9318862.html
Copyright © 2020-2023  润新知