• OS + CentOS 8.2 / MySQL 8.0.31 + phpmyadmin5.12 + Nginx1.14.1


    s

    CentOS8 Nginx配置php-fpm

    https://wiki.miyond.com/?p=316

    nginx 中 fastcgi_pass配置为unix:/tmp/php-fpm.sock与127.0.0.1:9000区别

    https://blog.csdn.net/resilient/article/details/109850729

    nginx中的 fastcgi_pass为什么有时候是unix:/tmp/php-fpm.sock,有时候是127.0.0.1:9000
    
    这牵扯到了nginx和php的通信模式,上面所列的就是这两种,一种是利用系统本身socket的,一种是利用tcp协议的
    
    两种协议有区别,
    
    UNIX Domain Socket不经过网络,只是在系统内部进行通信,适用于php和nginx都装在同一台linux服务器上
    
    tcp通信协议的也就是fastcgi_pass模式的既适用于php和nginx都装在同一台linux服务器上,同时又适用于不在同一台服务器上的,一般在同一个局域网中,也就是127.0.0.1的意义了
    
    当然我们在真正的php搭建服务器环境的时候,具体用那种,就要看php-fpm.conf中使用的是哪种了
    
    tcp方式:
    php-fpm.conf: listen = 127.0.0.1:9000
    nginx.conf: fastcgi_pass 127.0.0.1:9000;
    UNIX Domain Socket方式:
    php-fpm.conf: listen = /tmp/php-fpm.sock
    nginx.conf: fastcgi_pass unix:/tmp/php-fpm.sock;
    
    在我们真正实例中多数都是装在同一台服务器上,所以选择UNIX Domain Socket是比较合适的选择,因为这样可以避免数据传输经过tcp层造成导致TIME_WAIT连接过多的问题。
    
    具体两个传输方式的流程如下
    
    1.1 TCP Socket(本地回环127.0.0.1)方式的数据传输:
    Nginx <=> socket <=> TCP/IP <=> socket <=> PHP-FPM
    1.2 TCP Socket(Nginx和PHP-FPM位于不同服务器)的数据传输:
    Nginx <=> socket <=> TCP/IP <=> 物理层 <=> 路由器 <=> 物理层 <=> TCP/IP <=> socket <=> PHP-FPM
    
    2 UNIX Domain Socket方式的数据传输:
    Nginx <=> socket <=> PHP-FPM
    ————————————————

    如何让tomcat支持PHP运行

    http://blog.iis7.com/article/18350.html

    centos8安装mysql与mysql的配置文件

    https://www.cnblogs.com/jiyuchen1/p/16452651.html

    CentOS7上优雅地重置MySQL8.0数据库密码

    https://blog.csdn.net/xinpengfei521/article/details/80400142

    方案一,centos8.5 yum install  mysql-server.x86_64 , 本地yum源方式安装mysql 8.0.26

    [root@scts08t ~]# yum list mysql-server.x86_64

    [root@scts08t ~]# yum list mysql-server
    Last metadata expiration check: 2:23:54 ago on Wed 23 Nov 2022 09:46:37 AM PST.
    Installed Packages
    mysql-server.x86_64                 8.0.26-1.module_el8.4.0+915+de215114                  @media-appstream

    [root@scts08t ~]# yum install mysql-server.x86_64

    [root@scts08t ~]# yum install mysql.x86_64

    [root@scts08t ~]# vim /var/log/mysql/mysqld.log

    [root@scts08t ~]# vim /var/log/mysql/mysqld.log 
    2022-11-23T19:47:36.638628Z 0 [System] [MY-013169] [Server] /usr/libexec/mysqld (mysqld 8.0.26) initializing of server in progress as process 7230
    2022-11-23T19:47:36.647063Z 1 [System] [MY-013576] [InnoDB] InnoDB initialization has started.
    2022-11-23T19:47:36.949404Z 1 [System] [MY-013577] [InnoDB] InnoDB initialization has ended.
    2022-11-23T19:47:38.026356Z 0 [Warning] [MY-013746] [Server] A deprecated TLS version TLSv1 is enabled for channel mysql_main
    2022-11-23T19:47:38.026688Z 0 [Warning] [MY-013746] [Server] A deprecated TLS version TLSv1.1 is enabled for channel mysql_main
    2022-11-23T19:47:38.137786Z 6 [Warning] [MY-010453] [Server] root@localhost is created with an empty password ! Please consider switching off the --initialize-insecure option.
    2022-11-23T19:47:41.063855Z 0 [System] [MY-010116] [Server] /usr/libexec/mysqld (mysqld 8.0.26) starting as process 7278
    2022-11-23T19:47:41.075079Z 1 [System] [MY-013576] [InnoDB] InnoDB initialization has started.
    2022-11-23T19:47:41.235618Z 1 [System] [MY-013577] [InnoDB] InnoDB initialization has ended.
    2022-11-23T19:47:41.612351Z 0 [Warning] [MY-013746] [Server] A deprecated TLS version TLSv1 is enabled for channel mysql_main
    2022-11-23T19:47:41.612628Z 0 [Warning] [MY-013746] [Server] A deprecated TLS version TLSv1.1 is enabled for channel mysql_main
    2022-11-23T19:47:41.614989Z 0 [Warning] [MY-010068] [Server] CA certificate ca.pem is self signed.
    2022-11-23T19:47:41.615361Z 0 [System] [MY-013602] [Server] Channel mysql_main configured to support TLS. Encrypted connections are now supported for this channel.
    2022-11-23T19:47:41.651953Z 0 [System] [MY-011323] [Server] X Plugin ready for connections. Bind-address: '::' port: 33060, socket: /var/lib/mysql/mysqlx.sock
    2022-11-23T19:47:41.652089Z 0 [System] [MY-010931] [Server] /usr/libexec/mysqld: ready for connections. Version: '8.0.26'  socket: '/var/lib/mysql/mysql.sock'  port: 3306  Source distribution.

    空密码登录,更新root密码,更新可以外部连接,flush 权限。

    [root@scts08t ~]# mysql -uroot -p -hlocalhost

    mysql> show databases;

    mysql> use mysql;

    mysql> alter user user() identified by "ar=vW0cgAyu_8888";

    mysql> update mysql.user set host='%' where user='root';

    mysql> flush privileges;

    方案二,mysql-8.0.31-1.el8.x86_64.rpm-bundle.tar下载解压

    https://cdn.mysql.com//Downloads/MySQL-8.0/mysql-8.0.31-1.el8.x86_64.rpm-bundle.tar

    mysql-community-client-8.0.31-1.el8.x86_64.rpm
    mysql-community-client-debuginfo-8.0.31-1.el8.x86_64.rpm
    mysql-community-client-plugins-8.0.31-1.el8.x86_64.rpm
    mysql-community-client-plugins-debuginfo-8.0.31-1.el8.x86_64.rpm
    mysql-community-common-8.0.31-1.el8.x86_64.rpm
    mysql-community-debuginfo-8.0.31-1.el8.x86_64.rpm
    mysql-community-debugsource-8.0.31-1.el8.x86_64.rpm
    mysql-community-devel-8.0.31-1.el8.x86_64.rpm
    mysql-community-icu-data-files-8.0.31-1.el8.x86_64.rpm
    mysql-community-libs-8.0.31-1.el8.x86_64.rpm
    mysql-community-libs-debuginfo-8.0.31-1.el8.x86_64.rpm
    mysql-community-server-8.0.31-1.el8.x86_64.rpm
    mysql-community-server-debug-8.0.31-1.el8.x86_64.rpm
    mysql-community-server-debug-debuginfo-8.0.31-1.el8.x86_64.rpm
    mysql-community-server-debuginfo-8.0.31-1.el8.x86_64.rpm
    mysql-community-test-8.0.31-1.el8.x86_64.rpm
    mysql-community-test-debuginfo-8.0.31-1.el8.x86_64.rpm

    方法一, 修改mysql 8.0 root 密码

    1、centos8.2环境下,按顺序如下安装mysql文件包

    [root@centos82-scts08t opt]# more setup.sh 

    #/bin/bash
    rpm -ivh /opt/mysql-community-client-plugins-8.0.31-1.el8.x86_64.rpm
    rpm -ivh /opt/mysql-community-common-8.0.31-1.el8.x86_64.rpm
    rpm -ivh /opt/mysql-community-libs-8.0.31-1.el8.x86_64.rpm
    rpm -ivh /opt/mysql-community-client-8.0.31-1.el8.x86_64.rpm
    rpm -ivh /opt/mysql-community-icu-data-files-8.0.31-1.el8.x86_64.rpm
    rpm -ivh /opt/mysql-community-server-8.0.31-1.el8.x86_64.rpm
    tar -zxvf /opt/apache-tomcat-10.0.27.tar.gz -C /opt
    tar -zxvf /opt/nginx-1.23.2.tar.gz -C /opt
    unzip /opt/phpMyAdmin-5.2.0-all-languages.zip -d /opt
    systemctl stop firewalld.service
    systemctl disable firewalld.service

    2、安装后检查mysql清单

    [root@centos82-scts08t opt]# rpm -qa |grep mysql
    mysql-community-client-8.0.31-1.el8.x86_64
    mysql-community-client-plugins-8.0.31-1.el8.x86_64
    mysql-community-icu-data-files-8.0.31-1.el8.x86_64
    mysql-community-common-8.0.31-1.el8.x86_64
    mysql-community-server-8.0.31-1.el8.x86_64
    mysql-community-libs-8.0.31-1.el8.x86_64

    3、重启mysql server

     [root@centos82-scts08t ~]# systemctl restart mysqld.service

    4、查找密码,新版本密码方式改变了,shit mysql installation,fuck Larry Ellison

    [root@centos82-scts08t ~]# grep password /var/log/mysqld.log

    2022-11-01T11:46:27.017354Z 6 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: ar=vW0cgAyu_

    5、[root@centos82-scts08t ~]# mysql -uroot -p密码 -hlocalhost

    mysql> show databases;
    ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement.

    意思首先得强制改密码,还得复杂,草泥马。

    mysql> alter user user() identified by "caonima";
    ERROR 1819 (HY000): Your password does not satisfy the current policy requirements

    mysql> alter user user() identified by "ar=vW0cgAyu_8888";

    6、设置允许远程连接MySQL 8,并立即生效

    mysql> use mysql;

    mysql> update mysql.user set host='%' where user='root';

    mysql> flush privileges;
    7、

    方法二, 修改mysql 8.0 root 密码

    1、centos8.2环境下,按顺序如下安装mysql文件包(同上)

    2、 mysql 8.0.26 修改/etc/my.cnf文件,加入skip-grant-tables后重启mysql

    [root@centos82-scts08t ~]# echo "skip-grant-tables"  >> /etc/my.cnf

    3、mysql重启

    [root@centos82-scts08t ~]# systemctl restart mysqld.service 

    4、mysql无密码进入,直接回车

    [root@centos82-scts08t ~]# mysql -uroot -p -h127.0.0.1

    RROR 2003 (HY000): Can't connect to MySQL server on '127.0.0.1:3306'

    [root@centos82-scts08t ~]# mysql

    5、mysql修改密码,https://download.csdn.net/download/weixin_38501206/12824626

    mysql> select host,user,authentication_string,plugin from user;       --查询root的authentication_string密码

    mysql> update user set authentication_string='' where user='root';  --先强制置空这个B养的加密密码

    mysql> select host,user,authentication_string,plugin from user;

    6、然后注释/etc/my.cnf 中 skip-grant-tables行

    [mysqld]
    datadir=/var/lib/mysql
    socket=/var/lib/mysql/mysql.sock
    log-error=/var/log/mysqld.log
    pid-file=/var/run/mysqld/mysqld.pid
    #skip-grant-tables

    7、再重启mysql进入修改成新root密码。

    [root@centos85 ~]# systemctl restart mysqld.service

    8、再无密码进入修改密码,至少8位数,又是他妈的烦神。

    mysql> alter user user() identified by "caonima.com";

    mysql> alter user 'root' identified by "caonima.com";

    mysql> flush privileges;

    9、创建远程用户,再授权

    mysql> create user 'root'@'%' identified by '密码';
    mysql> grant all privileges on *.* to 'root'@'%' with grant option;
    mysql> flush privileges;

    10、检查ok,远程连接验证ok。

    mysql> select User,Host from user;

    centos8.5 部署nginx 1.14.1 + php环境配置

    1、安装nginx

    [root@scts08t ~]# yum install -y nginx.x86_64

    [root@scts08t ~]# nginx -v
    nginx version: nginx/1.14.1

    2、安装php相关环境

    [root@scts08t ~]# yum install php php-fpm php-json php-mysqlnd  php-mbstring.x86_64 -y

    [root@scts08t ~]# php -v
    PHP 7.2.24 (cli) (built: Oct 22 2019 08:28:36) ( NTS )
    Copyright (c) 1997-2018 The PHP Group
    Zend Engine v3.2.0, Copyright (c) 1998-2018 Zend Technologies
    [root@scts08t ~]# php-fpm -v
    PHP 7.2.24 (fpm-fcgi) (built: Oct 22 2019 08:28:36)
    Copyright (c) 1997-2018 The PHP Group
    Zend Engine v3.2.0, Copyright (c) 1998-2018 Zend Technologies

    [root@scts08t ~]#  /usr/sbin/php-fpm -t   #检测/etc/php-fpm.conf 配置文件

    3、配置nginx

    [root@scts08t ~]# vim /etc/nginx/nginx.conf  #配置nginx + php结合

    # For more information on configuration, see:
    #   * Official English Documentation: http://nginx.org/en/docs/
    
    user nginx;
    worker_processes auto;
    error_log /var/log/nginx/error.log;
    pid /run/nginx.pid;
    
    # Load dynamic modules. See /usr/share/doc/nginx/README.dynamic.
    include /usr/share/nginx/modules/*.conf;
    
    events {
        worker_connections 1024;
    }
    
    http {
        log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                          '$status $body_bytes_sent "$http_referer" '
                          '"$http_user_agent" "$http_x_forwarded_for"';
        access_log          /var/log/nginx/access.log  main;
        sendfile            on;
        tcp_nopush          on;
        tcp_nodelay         on;
        keepalive_timeout   65;
        types_hash_max_size 2048;
        include             /etc/nginx/mime.types;
        default_type        application/octet-stream;
        include             /etc/nginx/conf.d/php-fpm-upstream.conf; #自定义文件并新增内容,见下面文件,文件位必须放这里
        #include       /etc/nginx/conf.d/php-fpm.conf
        server {
            listen       80 default_server;
            listen       [::]:80 default_server;
            server_name  _;
            root         /opt/phpmyadmin;
            # Load configuration files for the default server block.
            include /etc/nginx/default.d/php-location.conf; #自定义文件并新增内容,见下面文件,文件位必须放这里
            location / {
            #index index.html index.php;
            }
    
            error_page 404 /404.html;
                location = /40x.html {
            }
    
            error_page 500 502 503 504 /50x.html;
                location = /50x.html {
            }
        }
    }

    [root@scts08t ~]# vim /etc/nginx/conf.d/php-fpm-upstream.conf  #配置PHP-FPM Server

    或者

    [root@scts08t ~]# vim /etc/nginx/conf.d/php-fpm.conf  #配置PHP-FPM Server

    # PHP-FPM FastCGI server
    # network or unix domain socket configuration
    
    upstream php-fpm {
            server unix:/run/php-fpm/www.sock;
    }

    [root@scts08t ~]# vim /etc/nginx/default.d/php-location.conf  #配置php环境解析

    location ~ \.php$ {
            root           /opt/phpmyadmin;
            include        fastcgi_params;
            fastcgi_pass   php-fpm; #关联/etc/nginx/conf.d/php-fpm-upstream.conf调度,或php-fpm.conf
            fastcgi_index  index.php;
            fastcgi_param  SCRIPT_FILENAME $document_root$fastcgi_script_name;
            #fastcgi_param SCRIPT_FILENAME  /scripts$fastcgi_script_name;
    }

    centos8.5 部署phpmyadmin 5.12

    1、下载文件

    [root@scts08t ~]# wget -c https://files.phpmyadmin.net/phpMyAdmin/5.2.0/phpMyAdmin-5.2.0-all-languages.zip -P /opt

    2、释放目录

    [root@scts08t ~]# unzip -t /opt/phpMyAdmin-5.2.0-all-languages.zip

    [root@scts08t ~]# unzip /opt/phpMyAdmin-5.2.0-all-languages.zip -d /opt/phpmyadmin

    3、

    查看nginx、php-fpm进程并查看log

    [root@centos82-scts08t ~]#   ps -ef |grep nginx; ps -ef |grep php;tail -f /var/log/nginx/*.log;tail -f /var/log/php-fpm/error.log 

     temp nginx.conf

    end 

    centos82
  • 相关阅读:
    关于工作中Git相关的总结
    浅谈MySQL的优化
    由内搜推送思考Kafka 的原理
    SOA和微服务架构
    Centos7.2 搭建Lamp服务器以及迁移WordPress个人博客详细过程
    MyISAM和InnoDB索引实现区别
    图解高内聚与低耦合
    图解Java常用数据结构(一)
    Java源码安全审查
    Java高并发之锁优化
  • 原文地址:https://www.cnblogs.com/lindows/p/16845514.html
Copyright © 2020-2023  润新知