• 连接数过多

SHOW PROCESSLIST;

修改最大连接数,但是这不是一劳永逸的方法,应该要让它自动杀死那些sleep的进程。
SHOW VARIABLES LIKE "max_connections";
SET GLOBAL max_connections=1000;

这个数值指的是mysql在关闭一个非交互的连接之前要等待的秒数,默认是28800s
SHOW GLOBAL VARIABLES LIKE 'wait_timeout';
SET GLOBAL wait_timeout=300;
  • 修改my.cnf配置注意事项
[mysqld]
max_connections=1000 # 一定要放在 [mysqld] 下面
  • 异常连接杀进程
杀进程
SELECT *,CONCAT('KILL ',id,';') FROM information_schema.processlist WHERE USER='root' AND `TIME`>60;

SELECT *,MD5(INFO) AS md5_info FROM information_schema.processlist WHERE INFO IS NOT NULL 
AND COMMAND!='Sleep' AND TIME>0 AND INFO NOT LIKE '%information_schema.processlist%'
ORDER BY TIME DESC

SELECT CONCAT('kill ',ID,';') AS '杀进程' FROM information_schema.processlist WHERE INFO IS NOT NULL 
AND COMMAND!='Sleep' AND TIME>5 AND INFO NOT LIKE '%information_schema.processlist%'
ORDER BY TIME DESC

注意点

1. 每次安装完服务器都记得重启下查询服务器是否开机自启动了
2. 

常用命令

# 重置密码
echo abc123 | passwd --stdin root

Nginx

安装nginx

yum install nginx -y
nginx
# 添加到服务中
systemctl enable nginx.service
# 设置开机自启动
chkconfig nginx on

# 通过服务的方式启动nginx
systemctl start nginx.service

# 查看自定服务开机启动状态
systemctl status nginx

# 结束所有的nginx进程
kill -9 $(ps aux |grep nginx|grep -v grep| awk '{print $2}')


返回数据中, nginx.service; 后面的状态为是否开机自启动的呈现
nginx.service - The nginx HTTP and reverse proxy server
   Loaded: loaded (/usr/lib/systemd/system/nginx.service; enabled; vendor preset: disabled)
   Active: active (running) since Mon 2021-10-11 17:00:38 CST; 11min ago

配置反向代理

一般用于给网站做代理, https需要有网站的证书, 需要网站域名解析过去,且需要配置该域名的实际目标的host才行,以及配置对应的域名证书
↓↓↓↓↓ ssl代理配置 ↓↓↓↓↓

server {
    listen 443 ssl;   #SSL协议访问端口号为443。此处如未添加ssl,可能会造成Nginx无法启动。
    server_name api.wuloves.test;  #将localhost修改为您证书绑定的域名,例如:www.example.com。
    ssl_certificate key/api.wuloves.test.pem;   #将domain name.pem替换成您证书的文件名。
    ssl_certificate_key key/api.wuloves.test.key;   #将domain name.key替换成您证书的密钥文件名。
    # ssl_client_certificate key/ca.crt;
    ssl_session_timeout 30m;
    ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:ECDHE:ECDH:AES:HIGH:!NULL:!aNULL:!MD5:!ADH:!RC4;  #使用此加密套件。
    ssl_protocols TLSv1 TLSv1.1 TLSv1.2;   #使用该协议进行配置。
    ssl_prefer_server_ciphers on; 
    ssl_verify_client      off;

    location / {
        proxy_pass https://api.wuloves.test/;
        # proxy_ssl_certificate key/api.wuloves.test.pem;
        # proxy_ssl_certificate_key key/api.wuloves.test.key;

        # proxy_ssl_protocols           TLSv1 TLSv1.1 TLSv1.2;
        # proxy_ssl_ciphers             HIGH:!aNULL:!MD5;
        # proxy_ssl_trusted_certificate key/ca.crt;

        # proxy_ssl_verify        off;
        # proxy_ssl_verify_depth  2;
        # proxy_ssl_session_reuse on;
    }
    access_log logs/$server_name.success.ssl.log;
    error_log logs/api.wuloves.test.error.ssl.log; # 错误日志路径中不允许使用变量
}

配置正向代理(测试未通过)

↓↓↓↓↓ 正向代理配置 ↓↓↓↓↓

server {
    listen 18081;
    server_name _;
    location / {
    resolver 8.8.8.8;
    proxy_pass $scheme://$host$request_uri;
    }
}

Nginx变量列表

$args #这个变量等于请求行中的参数。
$content_length #请求头中的Content-length字段。
$content_type #请求头中的Content-Type字段。
$document_root #当前请求在root指令中指定的值。
$host #请求主机头字段,否则为服务器名称。
$http_user_agent #客户端agent信息
$http_cookie #客户端cookie信息
$limit_rate #这个变量可以限制连接速率。
$request_body_file #客户端请求主体信息的临时文件名。
$request_method #客户端请求的动作,通常为GET或POST。
$remote_addr #客户端的IP地址。
$remote_port #客户端的端口。
$remote_user #已经经过Auth Basic Module验证的用户名。
$request_filename #当前请求的文件路径,由root或alias指令与URI请求生成。
$query_string #与$args相同。
$scheme #HTTP方法(如http,https)。
$server_protocol #请求使用的协议,通常是HTTP/1.0或HTTP/1.1。
$server_addr #服务器地址,在完成一次系统调用后可以确定这个值。
$server_name #服务器名称。
$server_port #请求到达服务器的端口号。
$request_uri #包含请求参数的原始URI,不包含主机名,如:”/foo/bar.php?arg=baz”。
$uri #不带请求参数的当前URI,$uri不包含主机名,如”/foo/bar.html”。
$document_uri #与$uri相同。

PS

windows本地启动php-cgi
php-cgi.exe -b 127.0.0.1:9000 -c D:/server/web/server/php/php.ini

Windows Registry Editor Version 5.00

[HKEY_LOCAL_MACHINE\SOFTWARE\Classes\Directory\background\shell\cmd_here]
@="cmd"
"Icon"="cmd.exe"
[HKEY_LOCAL_MACHINE\SOFTWARE\Classes\Directory\background\shell\cmd_here\command]
@="\"C:\\Windows\\System32\\cmd.exe\""
[HKEY_LOCAL_MACHINE\SOFTWARE\Classes\Folder\shell\cmdPrompt]
@="cmd"
[HKEY_LOCAL_MACHINE\SOFTWARE\Classes\Folder\shell\cmdPrompt\command]
@="\"C:\\Windows\\System32\\cmd.exe\" \"cd %1\""
[HKEY_LOCAL_MACHINE\SOFTWARE\Classes\Directory\shell\cmd_here]
@="cmd"
"Icon"="cmd.exe"
[HKEY_LOCAL_MACHINE\SOFTWARE\Classes\Directory\shell\cmd_here\command]
@="\"C:\\Windows\\System32\\cmd.exe\""

[HKEY_CLASSES_ROOT\Directory\shell\runas]
@="cmd administrator"
"HasLUAShield"=""
[HKEY_CLASSES_ROOT\Directory\shell\runas\command]
@="cmd.exe /s /k pushd \"%V\""
[-HKEY_CLASSES_ROOT\Directory\Background\shell\runas]
[HKEY_CLASSES_ROOT\Directory\Background\shell\runas]
@="cmd administrator"
"HasLUAShield"=""
[HKEY_CLASSES_ROOT\Directory\Background\shell\runas\command]
@="cmd.exe /s /k pushd \"%V\""
[-HKEY_CLASSES_ROOT\Drive\shell\runas]
[HKEY_CLASSES_ROOT\Drive\shell\runas]
@="cmd administrator"
"HasLUAShield"=""
[HKEY_CLASSES_ROOT\Drive\shell\runas\command]
<span>@="cmd.exe /s /k pushd \"%V\""</span>

elasticsearch 安装

一、安装jdk

ElasticSearch是基于lucence开发的,也就是运行需要java jdk支持。所以要先安装JAVA环境。

由于ElasticSearch 5.x 往后依赖于JDK 1.8的,所以现在我们下载JDK 1.8或者更高版本。
下载JDK1.8,下载完成后安装。

二、安装ElasticSearch

1.ElasticSearch下载地址:
https://www.elastic.co/downloads/elasticsearch

2.下载安装包后解压
https://www.elastic.co/cn/downloads/elasticsearch

3.进入bin目录下,双击执行elasticsearch.bat

4.稍等一会儿浏览器能正常打开下面地址表示启动成功

http://localhost:9200

{
    "name": "DESKTOP-FH5900V",
    "cluster_name": "elasticsearch",
    "cluster_uuid": "MMGRFWOrSOGUflKQAPHJRw",
    "version": {
        "number": "7.15.1",
        "build_flavor": "default",
        "build_type": "zip",
        "build_hash": "83c34f456ae29d60e94d886e455e6a3409bba9ed",
        "build_date": "2021-10-07T21:56:19.031608185Z",
        "build_snapshot": false,
        "lucene_version": "8.9.0",
        "minimum_wire_compatibility_version": "6.8.0",
        "minimum_index_compatibility_version": "6.0.0-beta1"
    },
    "tagline": "You Know, for Search"
}

5.修改es使用的参数.编辑D:\elasticsearch\elasticsearch-7.15.1\config\elasticsearch.yml文件

# 增加新的参数,这样head插件可以访问es
http.cors.enabled: true 
http.cors.allow-origin: "*"
@注意,设置参数的时候:后面要有空格!

6.修改完配置将es重启,浏览器访问 http://localhost:9100

三、安装ElasticSearch-head插件

1、安装node环境
网址:https://nodejs.org/en/download/ 下载Windows版msi的,下载完直接安装,一直确定

安装完后cmd查看版本node-v

2、安装grunt

grunt是一个很方便的构建工具,可以进行打包压缩、测试、执行等等的工作,5.x里之后的head插件就是通过grunt启动的。因此需要安装grunt.

npm install -g grunt-cli

查看版本号 grunt -version

3.下载head插件

1.网址:https://github.com/mobz/elasticsearch-head下载安装包

2.解压

3.进入head文件夹下,执行命令:npm install (此处是为安装进行安装pathomjs)

如果安装速度慢,设置成淘宝的镜像重新安装 npm config set registry https://registry.npm.taobao.org

如果报错, 考虑打开具有管理员权限的cmd窗口执行命令或重启试试

4.安装完成之后npm run start或grunt server,启动head插件

四、ElasticSearch安装为Windows服务

1.elasticsearch的bin目录下有一个elasticsearch-service.bat

2.cmd 进入bin目录下执行: elasticsearch-service.bat install

3.查看电脑服务es已经存在了

elasticsearch-service.bat后面还可以执行这些命令
install: 安装Elasticsearch服务
remove: 删除已安装的Elasticsearch服务(如果启动则停止服务)
start: 启动Elasticsearch服务(如果已安装)
stop: 停止服务(如果启动)
manager:启动GUI来管理已安装的服务