{ "version": "https://jsonfeed.org/version/1", "title": "涛声依旧", "subtitle": "天下事有难易乎?为之,则难者亦易矣", "icon": "https://blog.jingxiyuan.cn/images/favicon.ico", "description": "天生我材必有用", "home_page_url": "https://blog.jingxiyuan.cn", "items": [ { "id": "https://blog.jingxiyuan.cn/2022/11/08/Nginx%E9%85%8D%E7%BD%AE-%E5%8F%8D%E5%90%91%E4%BB%A3%E7%90%86/", "url": "https://blog.jingxiyuan.cn/2022/11/08/Nginx%E9%85%8D%E7%BD%AE-%E5%8F%8D%E5%90%91%E4%BB%A3%E7%90%86/", "title": "Nginx配置-反向代理", "date_published": "2022-11-08T02:05:00.000Z", "content_html": "

# 引言

\n\n

# 何为反向代理

\n\n

__正向代理:__如果把局域网外的 Internet 想象成一个巨大的资源库,则局域网中的客户端要访问 Internet,则需要通过代理服务器来访问,这种代理服务就称为正向代理,下面是正向代理的原理图。
\n\"991a203be1ec82b36e1f326376617d40.png\"
\n__反向代理:__看下面原理图,就一目了然。其实客户端对代理是无感知的,因为客户端不需要任何配置就可以访问,我们只需要将请求发送到反向代理服务器,由反向代理服务器去选择目标服务器获取数据后,在返回给客户端,此时反向代理服务器和目标服务器对外就是一个服务器,暴露的是代理服务器地址,隐藏了真实服务器 IP 地址。
\n\"1c87e386a0ce624a3949bda443cf346d.png\"

\n
\n

正向代理和反向代理的区别,一句话就是:如果我们客户端自己用,就是正向代理。如果是在服务器用,用户无感知,就是反向代理。

\n
\n

# Nginx 配置文件

\n\n
# 主进程叫master,负责管理子进程,子进程叫worker\n# worker_processes配置项表示开启几个业务进程,一般和cpu核数有关\nworker_processes  1;\n\nevents {\n    worker_connections  1024;\n}\n\nhttp {\n\t# include表示可以引入其他文件,此处表示引入http mime类型\n    include       mime.types;\n    default_type  application/octet-stream;\n    sendfile        on;\n    keepalive_timeout  65;\n\n\t# 虚拟主机,可以配置多个\n    server {\n        listen       80;\n        server_name  localhost;\n\n        location / {\n        \t# 路径匹配之后,哪个目录下去匹配相应的网页,html是相对路径\n            root   html;\n            index  index.html index.htm;\n        }\n\n        error_page   500 502 503 504  /50x.html;\n        location = /50x.html {\n            root   html;\n        }\n\t}\n}\n
\n

去掉注释信息后,可以将 nginx.conf 配置文件分为三部分:

\n
    \n
  1. 全局块
  2. \n
\n
worker_processes  1;\n
\n

从配置文件开始到 events 块之间的内容,主要会设置一些影响 Nginx 服务器整体运行的配置指令,主要包括:配置运行 Nginx 服务器的用户(组)、允许生成的 worker process 数,进程 PID 存放路径、日志存放路径和类型以及配置文件的引入等。

\n

上面这行 worker_processes 配置,是 Nginx 服务器并发处理服务的关键配置,该值越大,可以支持的并发处理量也越多,但是会受到硬件、软件等设备的约束。

\n
    \n
  1. events 块
  2. \n
\n
events {\n\tworker_connections  1024;\n}\n
\n

events 块涉及的指令主要影响 Nginx 服务器与用户的网络连接,常用的设置包括:是否开启对多 work process 下的网络连接进行序列化,是否允许同时接收多个网络连接,选取哪种事件驱动模型来处理连接请求,每个 work process 可以同时支持的最大连接数等

\n

上述例子就表示每个 work process 支持的最大连接数为 1024。这部分的配置对 Nginx 的性能影响较大,在实际中应该灵活配置。

\n
    \n
  1. http 块
  2. \n
\n
http {\n    include       mime.types;\n    default_type  application/octet-stream;\n    sendfile        on;\n    keepalive_timeout  65;\n\n    server {\n        listen       80;\n        server_name  localhost;\n\n        location / {\n            root   html;\n            index  index.html index.htm;\n        }\n\n        error_page   500 502 503 504  /50x.html;\n        location = /50x.html {\n            root   html;\n    }\n}\n
\n

这部分是 Nginx 服务器配置中最频繁的部分,代理、缓存和日志定义等绝大多数功能和第三方模块的配置都在这里。需要注意的是:http 块也可以包括 http 全局块、server 块。下面的反向代理、动静分离、负载均衡都是在这部分中配置

\n

__http 全局块:__http 全局块配置的指令包括:文件引入、MIME-TYPE 定义、日志自定义、连接超时时间、单链接请求数上限等。

\n

__server 块:__这块和虚拟主机有密切关系,从用户角度看,虚拟主机和一台独立的硬件主机是完全一样的,该技术的产生是为了节省互联网服务器硬件成本。

\n

__location 块:__这块的主要作用是:基于 Nginx 服务器接收到的请求字符串(例如 server_name/uri-string),对虚拟主机名称(也可以是 IP 别名)之外的字符串(例如 前面的 /uri-string)进行匹配,对特定的请求进行处理。地址定向、数据缓存和应答控制等功能,还有许多第三方模块的配置也在这里进行。

\n

每个 http 块可以包括多个 server 块,而每个 server 块就相当于一个虚拟主机。而每个 server 块也分为全局 server 块,以及可以同时包含多个 locaton 块。(☆☆☆☆☆)

\n

# 反向代理配置

\n
    \n
  1. location 配置规则
  2. \n
\n
location [ = | ~ | ~* | ^~ | @ ] /uri {\n\n}\n\n=    :用于不含正则表达式的 uri 前,要求请求字符串与 uri 严格匹配,如果匹配成功,就停止继续向下搜索并立即处理该请求。\n~    :用于表示 uri 包含正则表达式,并且区分大小写。\n~*   :用于表示 uri 包含正则表达式,并且不区分大小写。\n^~   :用于不含正则表达式的 uri 前,要求 Nginx 服务器找到标识 uri 和请求字符串匹配度最高的location后,立即使用此 location 处理请求,而不再使用 location 块中的正则 uri 和请求字符串做匹配。\n@    : "@" 定义一个命名的 location,使用在内部定向时,例如 error_page\n/uri  :不带任何修饰符,也表示前缀匹配,但是在正则匹配之后,如果没有正则命中,命中最长的规则\n/    :通用匹配,任何未匹配到其它location的请求都会匹配到,相当于switch中的default\n\n☆☆☆☆☆ uri没有“/”结尾时,location /abc/def可以匹配/abc/defghi请求,也可以匹配/abc/def/ghi等。而有“/”结尾时,location /abc/def/不能匹配/abc/defghi请求,只能匹配/abc/def/anything这样的请求\n
\n
    \n
  1. proxy_pass 配置规则
  2. \n
\n
url结尾加上了/,相当于是绝对路径,则Nginx不会把location中匹配的路径部分加入代理uri。\nurl结尾不加/,Nginx则会把匹配的路径部分加入代理uri。\n\n情景1:\nproxy_pass后有/ \n访问地址:http://localhost:8081/WCP.Service/wcp/modeladapter/download/asc.shtml\n最终代理:http://10.194.171.7:13082/modeladapter/download/asc.shtml\nlocation /WCP.Service/wcp/modeladapter/download/ {\n\tproxy_pass   http://10.194.171.7:13082/modeladapter/download/;\n}\n访问地址:http://localhost:8081/model/asc.shtml\n最终代理:http://127.0.0.1:8082/model/asc.shtml\nlocation /model/ {\n\tproxy_pass   http://127.0.0.1:8082/model/;\n}\n\n情景2:\nproxy_pass后有/\n访问地址:http://localhost:8081/model/asc.shtml\n最终代理:http://127.0.0.1:8082/asc.shtml\nlocation /model/ {\n\tproxy_pass   http://127.0.0.1:8082/;\n}\n\n情景3:\nproxy_pass后没有/ \n访问地址:http://localhost:8081/model/asc.shtml\n最终代理:http://127.0.0.1:8082/model/asc.shtml\nlocation /model/ {\n\tproxy_pass   http://127.0.0.1:8082;\n}\n\n情景4\nproxy_pass后没有/ \n访问地址:http://localhost:8081/model/asc.shtml\n最终代理:http://127.0.0.1:8082/AAAmodel/asc.shtml\nlocation /model/ {\n\tproxy_pass   http://127.0.0.1:8082/AAA;\n}\n\n情景5\nproxy_pass后有/\n访问地址:http://localhost:8081/model/asc.shtml\n最终代理:http://127.0.0.1:8082/asc.shtml\nlocation /model {\n\tproxy_pass   http://127.0.0.1:8082/;\n}\n\n情景6\nproxy_pass后有/\n访问地址:http://localhost:8081/modelBBB/asc.shtml\n最终代理:http://127.0.0.1:8082/asc.shtml\nlocation /model {\n\tproxy_pass   http://127.0.0.1:8082/;\n}\n
\n

# Nginx 完整配置文件

\n
#user  nobody;\nworker_processes  1;\n\n#error_log  logs/error.log;\n#error_log  logs/error.log  notice;\n#error_log  logs/error.log  info;\n\n#pid        logs/nginx.pid;\n\nevents {\n    worker_connections  1024;\n}\n\nhttp {\n    include       mime.types;\n    default_type  application/octet-stream;\n\n    #log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '\n    #                  '$status $body_bytes_sent "$http_referer" '\n    #                  '"$http_user_agent" "$http_x_forwarded_for"';\n\n    #access_log  logs/access.log  main;\n\n    sendfile        on;\n    #tcp_nopush     on;\n\n    #keepalive_timeout  0;\n    keepalive_timeout  65;\n\n    #gzip  on;\n\n    server {\n        listen       80;\n        server_name  localhost;\n\n        #charset koi8-r;\n\n        #access_log  logs/host.access.log  main;\n\n        location / {\n            root   html;\n            index  index.html index.htm;\n        }\n\n        #error_page  404              /404.html;\n\n        # redirect server error pages to the static page /50x.html\n        #\n        error_page   500 502 503 504  /50x.html;\n        location = /50x.html {\n            root   html;\n        }\n\n        # proxy the PHP scripts to Apache listening on 127.0.0.1:80\n        #\n        #location ~ \\.php$ {\n        #    proxy_pass   http://127.0.0.1;\n        #}\n\n        # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000\n        #\n        #location ~ \\.php$ {\n        #    root           html;\n        #    fastcgi_pass   127.0.0.1:9000;\n        #    fastcgi_index  index.php;\n        #    fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;\n        #    include        fastcgi_params;\n        #}\n\n        # deny access to .htaccess files, if Apache's document root\n        # concurs with nginx's one\n        #\n        #location ~ /\\.ht {\n        #    deny  all;\n        #}\n    }\n    # another virtual host using mix of IP-, name-, and port-based configuration\n    #\n    #server {\n    #    listen       8000;\n    #    listen       somename:8080;\n    #    server_name  somename  alias  another.alias;\n    #    location / {\n    #        root   html;\n    #        index  index.html index.htm;\n    #    }\n    #}\n    # HTTPS server\n    #\n    #server {\n    #    listen       443 ssl;\n    #    server_name  localhost;\n    #    ssl_certificate      cert.pem;\n    #    ssl_certificate_key  cert.key;\n\n    #    ssl_session_cache    shared:SSL:1m;\n    #    ssl_session_timeout  5m;\n\n    #    ssl_ciphers  HIGH:!aNULL:!MD5;\n    #    ssl_prefer_server_ciphers  on;\n\n    #    location / {\n    #        root   html;\n    #        index  index.html index.htm;\n    #    }\n    #}\n}\n
\n", "tags": [ "Linux", "服务", "Nginx", "Nginx", "反向代理" ] }, { "id": "https://blog.jingxiyuan.cn/2022/11/04/%E8%AE%B0%E4%B8%80%E6%AC%A1Vue%E9%A1%B9%E7%9B%AE%E7%9A%84%E9%83%A8%E7%BD%B2/", "url": "https://blog.jingxiyuan.cn/2022/11/04/%E8%AE%B0%E4%B8%80%E6%AC%A1Vue%E9%A1%B9%E7%9B%AE%E7%9A%84%E9%83%A8%E7%BD%B2/", "title": "记一次Vue项目的部署", "date_published": "2022-11-04T07:21:00.000Z", "content_html": "

# 描述

\n\n

# 过程

\n\n
sudo apt autoremove --purge nodejs\n
\n\n
curl -fsSL https://deb.nodesource.com/setup_16.x | sudo -E bash - && sudo apt-get install -y nodejs\n
\n\n
curl -sL https://dl.yarnpkg.com/debian/pubkey.gpg | gpg --dearmor | sudo tee /usr/share/keyrings/yarnkey.gpg >/dev/null\n\necho "deb [signed-by=/usr/share/keyrings/yarnkey.gpg] https://dl.yarnpkg.com/debian stable main" | sudo tee /etc/apt/sources.list.d/yarn.list\n\nsudo apt-get update && sudo apt-get install yarn\n
\n\n
yarn install\n
\n\n
yarn build\n
\n\n
apt install nginx\n
\n\n
server {\n        listen 80 default_server;\n        listen [::]:80 default_server;\n\n        # SSL configuration\n        #\n        # listen 443 ssl default_server;\n        # listen [::]:443 ssl default_server;\n        #\n        # Note: You should disable gzip for SSL traffic.\n        # See: https://bugs.debian.org/773332\n        #\n        # Read up on ssl_ciphers to ensure a secure configuration.\n        # See: https://bugs.debian.org/765782\n        #\n        # Self signed certs generated by the ssl-cert package\n        # Don't use them in a production server!\n        #\n        # include snippets/snakeoil.conf;\n\n        root /var/www/html;\n\n        # Add index.php to the list if you are using PHP\n        index index.html index.htm index.nginx-debian.html;\n\n        server_name _;\n\n        location /api {\n                proxy_pass http://localhost:8080;\n        }\n\n        location / {\n                # First attempt to serve request as file, then\n                # as directory, then fall back to displaying a 404.\n                #try_files $uri $uri/ =404;\n                alias /opt/codes/dayu-tools-arbitrage-web/dist/;\n                try_files $uri $uri/ @router;\n                index index.html index.htm;\n        }\n\n        location @router {\n                rewrite ^.*$ /index.html last;\n        }\n}\n\n
\n

# 其它

\n\n
rm dist -fr\n\nyarn build\n
\n", "tags": [ "Linux", "项目部署", "vue", "NodeJS", "yarn" ] }, { "id": "https://blog.jingxiyuan.cn/2022/11/03/%E4%B8%8A%E7%8F%AD%E4%BA%86/", "url": "https://blog.jingxiyuan.cn/2022/11/03/%E4%B8%8A%E7%8F%AD%E4%BA%86/", "title": "上班了", "date_published": "2022-11-03T03:25:00.000Z", "content_html": "\n", "tags": [ "生活", "心情", "心情" ] }, { "id": "https://blog.jingxiyuan.cn/2022/11/02/2-dev-null%E5%92%8C-dev-null-2-1%E5%92%8C2-1-dev-null%E7%9A%84%E5%8C%BA%E5%88%AB/", "url": "https://blog.jingxiyuan.cn/2022/11/02/2-dev-null%E5%92%8C-dev-null-2-1%E5%92%8C2-1-dev-null%E7%9A%84%E5%8C%BA%E5%88%AB/", "title": "2>/dev/null和>/dev/null 2>&1和2>&1>/dev/null的区别", "date_published": "2022-11-02T08:29:00.000Z", "content_html": "

# 区别:

\n
2>/dev/null\n
\n

意思就是把错误输出到 “黑洞”

\n
>/dev/null 2>&1\n
\n

默认情况是 1,也就是等同于 1>/dev/null 2>&1。意思就是把标准输出重定向到 “黑洞”,还把错误输出 2 重定向到标准输出 1,也就是标准输出和错误输出都进了 “黑洞”

\n
2>&1 >/dev/null\n
\n

意思就是把错误输出 2 重定向到标准出书 1,也就是屏幕,标准输出进了 “黑洞”,也就是标准输出进了黑洞,错误输出打印到屏幕

\n

# 解释:

\n
    \n
  1. \n

    文件描述符
    \n Linux 系统预留三个文件描述符:0、1 和 2,他们的意义如下所示:
    \n0—— 标准输入(stdin)
    \n略...
    \n1—— 标准输出(stdout)
    \n在当前目录下,有且只有一个文件名称为 a.txt 的文件,这时我们运行这个命令【ls a.txt】, 就会获得一个标准输出 stdout 的输出结果:a.txt
    \n\"\"
    \n2—— 标准错误(stderr)
    \n在当前目录下,有且只有一个文件名称为 a.txt 的文件,我们运行命令【ls b.txt】,我们就会获得一个标准错误 stderr 的输出结果 “ls:无法访问 b.txt:没有这样的文件或目录”。
    \n\"\"

    \n
  2. \n
  3. \n

    重定向
    \n重定向的符号有两个:> 或 >>,两者的区别是:前者会先清空文件,然后再写入内容,后者会将重定向的内容追加到现有文件的尾部。举例如下:

    \n
  4. \n
\n\n
ls b.txt 2> stderr.txt 1>stdout.txt\n
\n\n
ls b.txt > output.txt 2>&1\n
\n\n
ls b.txt &> output.txt\nls b.txt >& output.txt #两个表达式效果一样的\n
\n
    \n
  1. Linux 特殊文件
    \n /dev/null 是一个特殊的设备文件,这个文件接收到任何数据都会被丢弃。因此,null 这个设备通常也被称为位桶(bit bucket)或黑洞。
    \n所以,2>/dev/null 的意思就是将标准错误 stderr 删掉。
  2. \n
\n", "tags": [ "Linux", "Shell", "Shell", "2>&1" ] }, { "id": "https://blog.jingxiyuan.cn/2022/11/01/360%E7%8B%AC%E7%AB%8B%E7%89%88%E5%B0%8F%E5%B7%A5%E5%85%B7/", "url": "https://blog.jingxiyuan.cn/2022/11/01/360%E7%8B%AC%E7%AB%8B%E7%89%88%E5%B0%8F%E5%B7%A5%E5%85%B7/", "title": "360独立版小工具", "date_published": "2022-11-01T07:20:00.000Z", "content_html": "

# 360 独立版小工具

\n

\"\"
\n360 全家桶众说纷纭但工具箱还是挺实用的,这波小工具可以单独下载使用,有需要的朋友赶紧下载吧!

\n

下载地址

\n

# 部分工具截图

\n

\"\"
\n\"\"
\n\"\"

\n", "tags": [ "Windows", "工具", "360小工具" ] }, { "id": "https://blog.jingxiyuan.cn/2022/10/31/%E4%B8%80%E9%94%AE%E5%85%B3%E9%97%ADWindows10-11%E7%B3%BB%E7%BB%9F%E8%87%AA%E5%8A%A8%E6%9B%B4%E6%96%B0/", "url": "https://blog.jingxiyuan.cn/2022/10/31/%E4%B8%80%E9%94%AE%E5%85%B3%E9%97%ADWindows10-11%E7%B3%BB%E7%BB%9F%E8%87%AA%E5%8A%A8%E6%9B%B4%E6%96%B0/", "title": "一键关闭Windows10/11系统自动更新", "date_published": "2022-10-31T07:30:00.000Z", "content_html": "

# 介绍

\n\n

# 下载

\n

win10 / win11 / 本地

\n", "tags": [ "Windows", "工具", "Windows10", "Windows11", "自动更新" ] }, { "id": "https://blog.jingxiyuan.cn/2022/10/27/%E6%9E%81%E7%A9%BA%E9%97%B4web%E7%AB%AFhttps%E7%9B%B4%E8%BF%9Enginx%E9%85%8D%E7%BD%AE/", "url": "https://blog.jingxiyuan.cn/2022/10/27/%E6%9E%81%E7%A9%BA%E9%97%B4web%E7%AB%AFhttps%E7%9B%B4%E8%BF%9Enginx%E9%85%8D%E7%BD%AE/", "title": "极空间web端https直连nginx配置", "date_published": "2022-10-27T05:34:00.000Z", "content_html": "

# 介绍

\n\n

# 配置

\n
    \n
  1. 需要先把 10000 端口在路由器上做好映射。
  2. \n
  3. 证书生成好并放置到 nginx 上。(证书生成方法不做介绍请自行百度)
  4. \n
  5. http 跳转 https 配置
  6. \n
\n
server {\n\t\tif ($scheme = http) {\n\t\t\trewrite ^(.*)$ https://$host$1 permanent;\n\t\t}\n}\n
\n
    \n
  1. web 端口监听配置
  2. \n
\n
#极空间-web\nserver {\n\tlisten 10000 ssl http2; #ipv4\n\tlisten [::]:10000 ssl http2; #ipv6\n\tserver_name xxx.xxx.com; #填写自己的域名,主域名或者子域名\n\n\t#include /etc/nginx/conf.d/ssl/ssl_common.conf;\n\tssl_certificate_key /etc/nginx/conf.d/ssl/xxx.key;  #加密证书\n\tssl_certificate /etc/nginx/conf.d/ssl/xxx.pem;  #加密证书\n\tssl_session_timeout 1d;\n\tssl_session_cache shared:MozSSL:10m;\n\tssl_session_tickets off;\n\tssl_protocols TLSv1.2 TLSv1.3;\n\tssl_ciphers ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:DHE-RSA-AES128-GCM-SHA256:DHE-RSA-AES256-GCM-SHA384;\n\tssl_prefer_server_ciphers on;\n\n   #开启OCSP stapling\n\tssl_stapling on;\n\tssl_stapling_verify on;\n\n\tclient_max_body_size 128M;\n\n\tadd_header Strict-Transport-Security "max-age=31536000; includeSubdomains; preload";\n\n\tproxy_send_timeout 180s; #设置发送超时时间\n   proxy_read_timeout 180s; #设置读取超时时间\n\n\t# Prevent Information leaks\n\tproxy_hide_header X-Powered-By;\n\tproxy_hide_header Server;\n\tproxy_hide_header X-AspNetMvc-Version;\n\tproxy_hide_header X-AspNet-Version;\n\n\t# http security headers\n\tadd_header X-Content-Type-Options nosniff;\n\tadd_header Pragma no-cache;\n\tadd_header Cache-Control no-store;\n\tadd_header X-XSS-Protection "1; mode=block";\n\tadd_header Referrer-Policy origin-when-cross-origin;\n\tadd_header X-Permitted-Cross-Domain-Policies none;\n   add_header X-Frame-Options SAMEORIGIN; #允许同域嵌套\n\n\t# Add Security cookie flags\n\tproxy_cookie_path ~(.*) "$1; SameSite=strict; secure; httponly";\n\n\t# Path to the root of your installation\n\tlocation / {\n\t\tproxy_intercept_errors on;\n\t\tproxy_max_temp_file_size 0;\n\t\tproxy_set_header Host $host;\n\t\tproxy_set_header X-Real-IP $remote_addr;\n\t\tproxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;\n\t\tproxy_set_header X-Forwarded-Proto $scheme;\n  \n\t\tproxy_pass http://极空间内网ip:5055; #这里设置你自己要跳转的局域网应用;\n\t\tproxy_redirect http://域名:5055/home https://域名:10000/home; #极空间在登陆后会跳转到http协议的5055端口,所以要在此替换为https协议的10000端口\n\t}\n\n\terror_page  500 502 503 504 /500.html;\n\terror_page  400 404 /500.html;\n\tlocation = /500.html {\n\t\troot /usr/share/nginx/html/; #错误html\n\t}\n}\n
\n

# 问题

\n\n", "tags": [ "极空间", "nginx", "极空间", "https", "web" ] }, { "id": "https://blog.jingxiyuan.cn/2022/10/22/%E6%9E%81%E7%A9%BA%E9%97%B4Docker%E7%89%88%E9%9D%92%E9%BE%99%E9%9D%A2%E6%9D%BF%E5%AE%89%E8%A3%85%E4%B8%8E%E9%85%8D%E7%BD%AE/", "url": "https://blog.jingxiyuan.cn/2022/10/22/%E6%9E%81%E7%A9%BA%E9%97%B4Docker%E7%89%88%E9%9D%92%E9%BE%99%E9%9D%A2%E6%9D%BF%E5%AE%89%E8%A3%85%E4%B8%8E%E9%85%8D%E7%BD%AE/", "title": "极空间Docker版青龙面板安装与配置", "date_published": "2022-10-22T02:44:00.000Z", "content_html": "

# 介绍

\n\n

# 安装

\n\n
#青龙面板装载路径\n/ql/data\n#博客装载路径(如果你不部署hexo博客可以不用配置)\n/root/.ssh  #ssh证书文件(如果你不用把hexo推送到git上可以不用配置)\n/blog      #hexo博客编译目录\n/blog/nginx_blog  #nginx上放置博客的目录(例如:/Docker/nginx/html/blog)\n
\n\n

# 配置

\n\n
名称:JD_COOKIE\n值:web京东登陆后按F12在网络tab页中的请求内查找cookie,然后复制pt_key=到pt_pin=等\n
\n\n
repo命令拉取脚本时需要拉取的文件后缀,直接写文件后缀名即可\nRepoFileExtensions="js py ts"\n钉钉(消息推送)\nexport DD_BOT_TOKEN=\nexport DD_BOT_SECRET=\n##开卡\nexport guaopencard_All="true"\nexport guaopencard_addSku_All="true"\nexport guaopencardRun_All="true"\nexport guaopencard_draw="true"\nexport JD_TRY="true"\nexport exjxbeans="true"\nexport DY_OPENALL="true"\n#抽奖\nexport opencard_draw=3\n#开启脚本依赖文件缺失修复\nexport ec_fix_dep="true" \n#开启脚本依赖文件更新\nexport ec_re_dep="true" \n#清空购物车\nexport JD_CART_REMOVE="true"\nexport JD_CART="true"\n#去掉多余的双十一红包脚本\nexport FLCODE=''\n#加购物车抽奖\nexport RUN_CAR=true\n#停用小额免密支付\nexport JD_PAY_CONTRACT=true\n
\n\n
#nodejs依赖\ncrypto-js\t\nprettytable\t\ndotenv\t\njsdom\t\ndate-fns\t\ntough-cookie\t\ntslib\t\nws@7.4.3\t\nts-md5\t\njsdom -g\t\njieba\t\nfs\t\nform-data\t\njson5\t\nglobal-agent\t\npng-js\t\n@types/node\t\nrequire\t\ntypescript\t\njs-base64\t\naxios\n#pythone依赖\nrequests\t\ncanvas\t\nping3\t\njieba\t\naiohttp\t\nPyExecJS\n#Linux依赖\nbizCode\nbizMsg\nlxml\n
\n

# 其它

\n
#配置国内源\npip config --global set global.index-url https://mirrors.aliyun.com/pypi/simple/\npip config --global set install.trusted-host https://mirrors.aliyun.com\n\n#升级pip\npip install --upgrade pip\n\n#更新青龙\nql update\n\n#已知要安装的依赖(不安装部分脚本任务会失败)\npnpm install ds\n\n#一键安装所有依赖(基于Faker一键脚本安装的青龙\n可通过执行/ql/data/scripts下的QLDependency.sh脚本安装,如脚本已经更新则通过下面命令执行\ncurl -fsSL https://git.metauniverse-cn.com/https://raw.githubusercontent.com/shufflewzc/QLDependency/main/Shell/QLOneKeyDependency.sh | sh\n\n#一般出现这种错误:(缺依赖)\nError: Cannot find module 'xx'\n执行pnpm install xxx\n\n#一般出现这种错误:(缺文件)\nError: Cannot find module './xx'\n那就是拉库命令不完整,请检查或复制完整的拉库命\n\n#Python3依赖安装失败修复(基于Faker一键脚本安装的青龙)\ncurl -sS https://bootstrap.pypa.io/get-pip.py | python3\n
\n", "tags": [ "极空间", "Docker", "docker", "青龙面板", "定时任务" ] }, { "id": "https://blog.jingxiyuan.cn/2022/10/21/Hexo-Theme-Shoka-Valine%E8%AF%84%E8%AE%BA%E9%85%8D%E7%BD%AE/", "url": "https://blog.jingxiyuan.cn/2022/10/21/Hexo-Theme-Shoka-Valine%E8%AF%84%E8%AE%BA%E9%85%8D%E7%BD%AE/", "title": "Hexo + Theme.Shoka + Valine评论配置", "date_published": "2022-10-21T03:48:00.000Z", "content_html": "\n

# LeanCloud 注册

\n
    \n
  1. LeanCloud 网站完成注册。
  2. \n
  3. 创建应用。
    \n\"\"
  4. \n
  5. 名称随便取,方案看自己选择。开发版免费但是有限制,商业版收费无限制。
    \n\"\"
  6. \n
  7. 点击配置按钮进行配置。
    \n\"\"
  8. \n
  9. 点击设置 - 应用凭证可获取 App ID 和 App Key
    \n\"\"
  10. \n
  11. 点击设置 - 安全中心根据自己的需求配置
    \n\"\"
  12. \n
\n

# 修改 Theme.Shoka 配置

\n
valine:\n  appId: 粘贴5中获取的App ID #Your_appId\n  appKey: 粘贴5中获取的App Key #Your_appkey\n  placeholder: ヽ(○´∀`)ノ♪欢迎畅所欲言 # Comment box placeholder\n  avatar: mp #默认头像设置 Gravatar style : mp, identicon, monsterid, wavatar, robohash, retro\n  pageSize: 10 # Pagination size\n  lang: zh-CN\n  visitor: true # Article reading statistic 这个要设置为false,以免与 leancloud_visitors 突冲 \n  NoRecordIP: false # Whether to record the commenter IP\n  serverURLs: # When the custom domain name is enabled, fill it in here (it will be detected automatically by default, no need to fill in)\n  powerMode: true\n  tagMeta:\n    visitor: 新朋友\n    master: 博主\n    friend: 小伙伴\n    investor: 金主粑粑\n  tagColor:\n    master: "var(--color-orange)"\n    friend: "var(--color-aqua)"\n    investor: "var(--color-pink)"\n  tagMember:\n    master:\n      # - hash of master@email.com\n      # - hash of master2@email.com\n    friend:\n      # - hash of friend@email.com\n      # - hash of friend2@email.com\n    investor:\n      # - hash of investor1@email.com\n
\n", "tags": [ "极空间", "Docker", "Hexo", "博客", "Hexo", "Shoka", "Valine", "评论" ] }, { "id": "https://blog.jingxiyuan.cn/2022/10/21/%E6%9E%81%E7%A9%BA%E9%97%B4Docker%E7%89%88mariadb%E5%AE%89%E8%A3%85%E4%B8%8E%E9%85%8D%E7%BD%AE/", "url": "https://blog.jingxiyuan.cn/2022/10/21/%E6%9E%81%E7%A9%BA%E9%97%B4Docker%E7%89%88mariadb%E5%AE%89%E8%A3%85%E4%B8%8E%E9%85%8D%E7%BD%AE/", "title": "极空间Docker版mariadb安装与配置", "date_published": "2022-10-21T01:06:00.000Z", "content_html": "

# 介绍

\n\n

# 安装

\n\n

# 配置

\n\n
stream {\n\t\n\t#极空间-docker-mariadb\n\tupstream mariadb {\n\t\thash $remote_addr consistent;\n\t\tserver mariadb的ip:端口;\n\t}\n\n\tserver {\n\t\tlisten 监听端口;\n\n\t\tproxy_connect_timeout 30s;\n\t\tproxy_timeout 300s;\n\t\tproxy_pass mariadb;\n\t}\n    \n}\n
\n", "tags": [ "极空间", "Docker", "极空间", "Docker", "mariadb", "mysql" ] }, { "id": "https://blog.jingxiyuan.cn/2022/10/20/%E6%9E%81%E7%A9%BA%E9%97%B4Docker%E7%89%88Wordpress%E5%AE%89%E8%A3%85%E4%B8%8E%E9%85%8D%E7%BD%AE/", "url": "https://blog.jingxiyuan.cn/2022/10/20/%E6%9E%81%E7%A9%BA%E9%97%B4Docker%E7%89%88Wordpress%E5%AE%89%E8%A3%85%E4%B8%8E%E9%85%8D%E7%BD%AE/", "title": "极空间Docker版Wordpress安装与配置", "date_published": "2022-10-20T00:56:00.000Z", "content_html": "

# 安装

\n\n

# 配置

\n\n
if((!empty( $_SERVER['HTTP_X_FORWARDED_HOST'])) || (!empty( $_SERVER['HTTP_X_FORWARDED_FOR'])) ) {\n    $_SERVER['HTTP_HOST'] = $_SERVER['HTTP_X_FORWARDED_HOST'];\n    $_SERVER['HTTPS'] = 'on';\n}\n
\n\n
define('WP_TEMP_DIR', ABSPATH.'wp-content/tmp');\ndefine('FS_METHOD', 'direct');\ndefine('FS_CHMOD_DIR', 0777);\ndefine('FS_CHMOD_FILE', 0777);\n
\n\n
chown('/var/www/html', 'www-data');\nchgrp('/var/www/html', 'www-data');\nchmod('/var/www/html/wp-content/plugins', 0777);\nchmod('/var/www/html/wp-content/themes', 0777);\nchmod('/var/www/html/wp-content/tmp', 0777);\n
\n\n
if($_GET['key'] != 'value') {\n\theader('Location: https://www.xxx.com/');\n}\n
\n", "tags": [ "极空间", "Docker", "博客", "极空间", "Wordpress" ] }, { "id": "https://blog.jingxiyuan.cn/2022/10/19/%E9%95%BF%E4%BA%86%E4%B8%80%E5%B2%81/", "url": "https://blog.jingxiyuan.cn/2022/10/19/%E9%95%BF%E4%BA%86%E4%B8%80%E5%B2%81/", "title": "又长了一岁", "date_published": "2022-10-19T00:51:00.000Z", "content_html": "

一年一次的总结时间又到了,这一年前半年平平无奇,后半年惊涛骇浪。中年危机如期而遇,人身的低谷终究还是来了。很沮丧也很无助,但还是要坚强面对。人生起起伏伏,时好时坏,终归还是会好起来的。加油!加油!加油
\n!

\n", "tags": [ "生活", "心情", "心情" ] }, { "id": "https://blog.jingxiyuan.cn/2022/10/18/%E6%90%AD%E5%BB%BAnagios%E7%9B%91%E6%8E%A7/", "url": "https://blog.jingxiyuan.cn/2022/10/18/%E6%90%AD%E5%BB%BAnagios%E7%9B%91%E6%8E%A7/", "title": "搭建nagios监控", "date_published": "2022-10-18T01:39:00.000Z", "content_html": "

# 监控端服务安装与配置

\n
    \n
  1. nagios 需要安装主程序 core 和 nrpe(nagios 和各被监控主机都必须安装)。如需使用自研前端可通过安装 ndoutils (用于把 nagios 监控信息写入数据库) 和 mysql 实现。具体安装见官网
  2. \n
  3. nagios 默认监控命令脚本放置在 libexec 中,自定义脚本也放到此处
  4. \n
  5. etc/objects/commands.cfg 用于保存 nagios 默认监控命令
  6. \n
  7. etc/nrpe.cfg 文件中需要添加用于被监控执行命令项(各被监控主机中都需要添加)
    \n\"\"
  8. \n
  9. etc/objects/hosts 目录下配置需要被监控的主机信息
    \n\"\"
  10. \n
  11. etc/objects/servers 目录下配置需要在被监控主机上执行的监控命令(第 4 项中的命令)
    \n\"\"
  12. \n
\n

# 被监控端服务安装与配置

\n
    \n
  1. 被监控端需要安装 nrpe
  2. \n
  3. 被监控端需要把监控端的命令写入到 nrpe 的配置文件中
  4. \n
  5. 被监控端需要把命令执行脚本放入 libexec 目录中
  6. \n
  7. 被监控端自动安装脚本(可借鉴)
  8. \n
\n
1、请先修改脚本中的服务端IP。\n2、如被监控端不支持let计算命令请执行sudo dpkg-reconfigure dash命令,弹出选择窗口后选择no。\n3、需要在脚本同目录下创建CentOS、Ubuntu、sh和conf目录,目录下分别放置nrpe的tar安装包、监控脚本和nrpe配置文件。\n\n#!/bin/bash\n#服务端ip\nSERVER_IP=10.10.10.121\n#安装目录\nINSTALL_HOME=`pwd`\n#安装ubuntu版本\nINSTALL_UBUNTU()\n{\n\tsudo apt-get update\n\tsudo apt-get install -y autoconf automake gcc libc6 libmcrypt-dev make libssl-dev wget openssl\n\t\n\tcd /tmp\n\t#wget --no-check-certificate -O nrpe.tar.gz https://github.com/NagiosEnterprises/nrpe/archive/nrpe-4.0.3.tar.gz\n\tcp $INSTALL_HOME/Ubuntu/nrpe.tar.gz ./\n\ttar xzf nrpe.tar.gz\n\n\tcd /tmp/nrpe-nrpe-4.0.3/\n\tsudo ./configure --enable-command-args --with-ssl-lib=/usr/lib/x86_64-linux-gnu/\n\tsudo make all\n\n\tsudo make install-groups-users\n\n\tsudo make install\n\n\tsudo make install-config\n\n\tsudo sh -c "echo >> /etc/services"\n\tsudo sh -c "sudo echo '# Nagios services' >> /etc/services"\n\tsudo sh -c "sudo echo 'nrpe    5666/tcp' >> /etc/services"\n\t\n\t#判断系统是高版本还是低版本\n\tVERSION=`lsb_release -r --short`\n\tIS_LOW_VERSION=`echo "$VERSION < 15" | bc`\n\n\tif [ $IS_LOW_VERSION = 1 ]; then\n\t\t#低版本\n\t\tsudo make install-init\n\telse\n\t\t#高版本\n\t\tsudo make install-init\n\t\tsudo systemctl enable nrpe.service\n\tfi\n\t\n\tsudo mkdir -p /etc/ufw/applications.d\n\tsudo sh -c "echo '[NRPE]' > /etc/ufw/applications.d/nagios"\n\tsudo sh -c "echo 'title=Nagios Remote Plugin Executor' >> /etc/ufw/applications.d/nagios"\n\tsudo sh -c "echo 'description=Allows remote execution of Nagios plugins' >> /etc/ufw/applications.d/nagios"\n\tsudo sh -c "echo 'ports=5666/tcp' >> /etc/ufw/applications.d/nagios"\n\tsudo ufw allow NRPE\n\tsudo ufw reload\n\t\n\tsudo sh -c "sed -i '/^allowed_hosts=/s/$/,$SERVER_IP/' /usr/local/nagios/etc/nrpe.cfg"\n\tsudo sh -c "sed -i 's/^dont_blame_nrpe=.*/dont_blame_nrpe=1/g' /usr/local/nagios/etc/nrpe.cfg"\n\t\n\tcd $INSTALL_HOME\n\tsudo cp ./sh/* /usr/local/nagios/libexec/\n\tsudo chmod +xr /usr/local/nagios/libexec/*\n\t\n\tsudo sh -c "echo 'command[check_ping]=/usr/local/nagios/libexec/check_ping -H 127.0.0.1 -w 3000.0,80% -c 5000.0,100% -p 5' >> /usr/local/nagios/etc/nrpe.cfg"\n\tsudo sh -c "echo 'command[check_cpu]=/usr/local/nagios/libexec/check_cpu.sh' >> /usr/local/nagios/etc/nrpe.cfg"\n\tsudo sh -c "echo 'command[check_mem]=/usr/local/nagios/libexec/check_mem.sh' >> /usr/local/nagios/etc/nrpe.cfg"\n\tsudo sh -c "echo 'command[check_disk]=/usr/local/nagios/libexec/check_disk.sh' >> /usr/local/nagios/etc/nrpe.cfg"\n\tsudo sh -c "echo 'command[check_my_service]=/usr/local/nagios/libexec/check_my_service.sh \\$ARG1\\$' >> /usr/local/nagios/etc/nrpe.cfg"\n\tsudo sh -c "echo 'command[check_system_info]=/usr/local/nagios/libexec/check_system_info.sh' >> /usr/local/nagios/etc/nrpe.cfg"\n\tNETWORK_INDEX=1\n\tfor NETWORK_NAME in `cat /proc/net/dev | awk '{i++; if(i>2){print $1}}' | sed 's/^[\\t]*//g' | sed 's/[:]*$//g'`;do\n\t\t\tif [ $NETWORK_NAME != 'lo' ]; then\n\t\t\t\t\tsudo sh -c "echo 'command[check_network$NETWORK_INDEX]=/usr/local/nagios/libexec/check_network.sh $NETWORK_NAME' >> /usr/local/nagios/etc/nrpe.cfg"\n\t\t\t\t\tNETWORK_INDEX=`expr $NETWORK_INDEX + 1 `\n\t\t\tfi\n\tdone\n\t\n\tif [ $IS_LOW_VERSION = 1 ]; then\n\t\t#低版本\n\t\tsudo start nrpe\n\telse\n\t\t#高版本\n\t\tsudo systemctl start nrpe.service\n\tfi\n}\n\n#安装centos版本\nINSTALL_CENTOS()\n{\n\tyum install -y gcc glibc glibc-common openssl openssl-devel perl wget\n\n\tcd /tmp\n\t#wget --no-check-certificate -O nrpe.tar.gz https://github.com/NagiosEnterprises/nrpe/archive/nrpe-4.0.3.tar.gz\n\tcp $INSTALL_HOME/CentOS/nrpe.tar.gz ./\n\ttar xzf nrpe.tar.gz\n\n\tcd /tmp/nrpe-nrpe-4.0.3/\n\t./configure --enable-command-args\n\tmake all\n\n\tmake install-groups-users\n\n\tmake install\n\n\tmake install-config\n\n\techo >> /etc/services\n\techo '# Nagios services' >> /etc/services\n\techo 'nrpe    5666/tcp' >> /etc/services\n\t\n\t#判断系统是高版本还是低版本\n\tVERSION=`rpm -q centos-release|cut -d- -f3`\n\t#安装bc命令\n\tyum -y install bc\n\tIS_LOW_VERSION=`echo "$VERSION < 7" | bc`\n\n\tif [ $IS_LOW_VERSION = 1 ]; then\n\t\t#低版本\n\t\tmake install-init\n\t\t\n\t\tiptables -I INPUT -p tcp --destination-port 5666 -j ACCEPT\n\t\tservice iptables save\n\t\tip6tables -I INPUT -p tcp --destination-port 5666 -j ACCEPT\n\t\tservice ip6tables save\n\telse\n\t\t#高版本\n\t\tmake install-init\n\t\tsystemctl enable nrpe.service\n\t\t\n\t\tfirewall-cmd --zone=public --add-port=5666/tcp\n\t\tfirewall-cmd --zone=public --add-port=5666/tcp --permanent\n\tfi\n\t\n\tsudo sh -c "sed -i '/^allowed_hosts=/s/$/,$SERVER_IP/' /usr/local/nagios/etc/nrpe.cfg"\n\tsudo sh -c "sed -i 's/^dont_blame_nrpe=.*/dont_blame_nrpe=1/g' /usr/local/nagios/etc/nrpe.cfg"\n\t\n\tcd $INSTALL_HOME\n\tsudo cp ./sh/* /usr/local/nagios/libexec/\n\tsudo chmod +xr /usr/local/nagios/libexec/*\n\t\n\tsudo sh -c "echo 'command[check_ping]=/usr/local/nagios/libexec/check_ping -H 127.0.0.1 -w 3000.0,80% -c 5000.0,100% -p 5' >> /usr/local/nagios/etc/nrpe.cfg"\n\tsudo sh -c "echo 'command[check_cpu]=/usr/local/nagios/libexec/check_cpu.sh' >> /usr/local/nagios/etc/nrpe.cfg"\n\tsudo sh -c "echo 'command[check_mem]=/usr/local/nagios/libexec/check_mem.sh' >> /usr/local/nagios/etc/nrpe.cfg"\n\tsudo sh -c "echo 'command[check_disk]=/usr/local/nagios/libexec/check_disk.sh' >> /usr/local/nagios/etc/nrpe.cfg"\n\tsudo sh -c "echo 'command[check_my_service]=/usr/local/nagios/libexec/check_my_service.sh \\$ARG1\\$' >> /usr/local/nagios/etc/nrpe.cfg"\n\tsudo sh -c "echo 'command[check_system_info]=/usr/local/nagios/libexec/check_system_info.sh' >> /usr/local/nagios/etc/nrpe.cfg"\n\tNETWORK_INDEX=1\n\tfor NETWORK_NAME in `cat /proc/net/dev | awk '{i++; if(i>2){print $1}}' | sed 's/^[\\t]*//g' | sed 's/[:]*$//g'`;do\n\t\t\tif [ $NETWORK_NAME != 'lo' ]; then\n\t\t\t\t\tsudo sh -c "echo 'command[check_network$NETWORK_INDEX]=/usr/local/nagios/libexec/check_network.sh $NETWORK_NAME' >> /usr/local/nagios/etc/nrpe.cfg"\n\t\t\t\t\tNETWORK_INDEX=`expr $NETWORK_INDEX + 1 `\n\t\t\tfi\n\tdone\n\t\n\tif [ $IS_LOW_VERSION = 1 ]; then\n\t\t#低版本\n\t\tif [ $(echo "$VERSION < 6" | bc) -eq 1 ]; then\n\t\t\tservice nrpe start\n\t\telse\n\t\t\tstart nrpe\n\t\tfi\n\telse\n\t\t#高版本\n\t\tsystemctl start nrpe.service\n\tfi\n}\n\n#安装其它版本\nINSTALL_OTHER()\n{\n\techo "Not supported at the moment."\n}\n\n#根据不同系统安装不同版本\nINSTALL()\n{\n\tif grep -Eqii "CentOS" /etc/issue || grep -Eq "CentOS" /etc/*-release; then\n\t\tDISTRO='CentOS'\n        PM='yum'\n\t\tINSTALL_CENTOS\n    elif grep -Eqi "Red Hat Enterprise Linux Server" /etc/issue || grep -Eq "Red Hat Enterprise Linux Server" /etc/*-release; then\n        DISTRO='RHEL'\n        PM='yum'\n\t\tINSTALL_OTHER\n    elif grep -Eqi "Aliyun" /etc/issue || grep -Eq "Aliyun" /etc/*-release; then\n        DISTRO='Aliyun'\n        PM='yum'\n\t\tINSTALL_OTHER\n    elif grep -Eqi "Fedora" /etc/issue || grep -Eq "Fedora" /etc/*-release; then\n        DISTRO='Fedora'\n        PM='yum'\n\t\tINSTALL_OTHER\n    elif grep -Eqi "Debian" /etc/issue || grep -Eq "Debian" /etc/*-release; then\n        DISTRO='Debian'\n        PM='apt'\n\t\tINSTALL_OTHER\n    elif grep -Eqi "Ubuntu" /etc/issue || grep -Eq "Ubuntu" /etc/*-release; then\n        DISTRO='Ubuntu'\n        PM='apt'\n\t\tINSTALL_UBUNTU\n    elif grep -Eqi "Raspbian" /etc/issue || grep -Eq "Raspbian" /etc/*-release; then\n        DISTRO='Raspbian'\n        PM='apt'\n\t\tINSTALL_OTHER\n    else\n        echo "unknow linux."\n        exit 1\n    fi\n    echo $DISTRO\n}\n\nINSTALL\n\nexit 0\n
\n

# 登录

\n

地址:http:// 服务器 IP/nagios
\n 用户名:nagiosadmin
\n 密码:nagiosadmin

\n

# 常见问题

\n
    \n
  1. 监控日志未写入 mysql(可能是 ndoutils 服务不正常导致)。采用以下脚本命令解决
  2. \n
\n
#!/bin/bash\nsudo rm -f /usr/local/nagios/var/ndo2db.pid\nsudo rm -f /usr/local/nagios/var/ndo.sock\nsudo systemctl restart ndo2db.service\nsudo systemctl status ndo2db.service\n
\n", "tags": [ "Linux", "服务", "nagios", "服务监控" ] }, { "id": "https://blog.jingxiyuan.cn/2022/10/17/redis%E4%B8%BB%E4%BB%8E%E5%9F%BA%E7%A1%80%E9%85%8D%E7%BD%AE%E8%AE%B0%E5%BD%95/", "url": "https://blog.jingxiyuan.cn/2022/10/17/redis%E4%B8%BB%E4%BB%8E%E5%9F%BA%E7%A1%80%E9%85%8D%E7%BD%AE%E8%AE%B0%E5%BD%95/", "title": "redis主从基础配置", "date_published": "2022-10-17T06:07:00.000Z", "content_html": "

# 主服务

\n
    \n
  1. 基础配置
  2. \n
\n
port 6379\nrequirepass 123456(密码,建议不设置)\nvm-enabled no (虚拟内存,内存够的情况下可以不使用)\nmaxmemory 1GB(告诉Redis当使用了多少物理内存后就开始拒绝后续的写入)\nbind 127.0.0.1 (注释掉,否则不能外部连接)\nrdbchecksum no(持久化数据检查)\nlist-max-ziplist-size 1024(ziplist的最大容量,正数为自己指定的大小。负数-1到-5为对应的值4到64Kb)\nlist-compress-depth 20(quicklist的两端多少个node不压缩,0为全部不压缩)\n
\n
sysctl vm.overcommit_memory=1 (立即生效)\n修改/etc/sysctl.conf添加vm.overcommit_memory=1(表示内核允许分配所有的物理内存,而不管当前的内存状态如何。Redis的RDB持久化实现是folk一个子进程,然后让子进程将内存镜像dump到RDB文件中。理论上来说是需要跟父进程一样的内存空间,但是由于linux很早就支持的copy-on-write技术,所以实际上并不需要这么多的物理内存的。)\n
\n
    \n
  1. 禁用透明大页(影响性能)
  2. \n
\n
需要sudo su 切换到root身份(sudo 没用)\necho never > /sys/kernel/mm/transparent_hugepage/enabled\n修改/etc/init.d/redis-server,加入/bin/echo never > /sys/kernel/mm/transparent_hugepage/enabled\n
\n
    \n
  1. 修复 TCP 警告
  2. \n
\n
sysctl net.core.somaxconn=1024(立即生效)\n修改/etc/sysctl.conf添加net.core.somaxconn=1024\n
\n
    \n
  1. 客户端缓冲区限制
  2. \n
\n
客户端的输出缓冲区的限制,因为某种原因客户端从服务器读取数据的速度不够快,可用于强制断开连接(一个常见的原因是一个发布 / 订阅客户端消费消息的速度无法赶上生产它们的速度)。\n可以三种不同客户端的方式进行设置:\nnormal ->  正常客户端\nslave  -> slave 和 MONITOR 客户端\npubsub ->  至少订阅了一个 pubsub channel 或 pattern 的客户端\n语法 :\nclient-output-buffer-limit <class><hard limit> <soft limit> <soft seconds>\n一旦达到硬限制客户端会立即断开,或者达到软限制并保持达成的指定秒数(连续)。\n例如,如果硬限制为 32 兆字节和软限制为 16 兆字节 /10 秒,客户端将会立即断开。如果输出缓冲区的大小达到 32 兆字节,客户端达到 16 兆字节和连续超过了限制 10 秒,也将断开连接。默认 normal 客户端不做限制,因为他们在一个请求后未要求时(以推的方式)不接收数据,\n只有异步客户端可能会出现请求数据的速度比它可以读取的速度快的场景。\n把硬限制和软限制都设置为 0 来禁用该特性\nclient-output-buffer-limit normal 0 0 0\nclient-output-buffer-limit slave 5gb 512mb 60\nclient-output-buffer-limit pubsub 32mb 8mb 60\n
\n
    \n
  1. 持久化配置
  2. \n
\n
---关闭RDB持久化---\nsave ""\n默认配置如下:\nsave 900 1 #900秒内有1次更新就持久化\nsave 300 10 #300秒内有10次更新就持久化\nsave 60 10000 #60秒内有10000次更新就持久化\n---关闭RDB持久化---\n主从同步支持两种策略,即disk和socket方式。\n新的slave端和重连的salve端不允许去继续同步进程,这被称之为“完全同步”。\n一个RDB文件从master端传到slave端,分为两种情况:\n1、支持disk:master端将RDB file写到disk,稍后再传送到slave端;\n2、无磁盘diskless:master端直接将RDB file传到slave socket,不需要与disk进行交互。无磁盘diskless方式适合磁盘读写速度慢但网络带宽非常高的环境。\nrepl-diskless-sync no 默认不使用diskless同步方式\nrepl-diskless-sync-delay 30 无磁盘diskless方式在进行数据传递之前会有一个时间的延迟,以便slave端能够进行到待传送的目标队列中,这个时间默认是5秒\nrepl-ping-slave-period 60 slave端向server端发送pings的时间区间设置,默认为10秒\nrepl-timeout 3600 设置超时时间\nrepl-disable-tcp-nodelay no 是否启用TCP_NODELAY,如果启用则会使用少量的TCP包和带宽去进行数据传输到slave端,当然速度会比较慢;如果不启用则传输速度比较快,但是会占用比较多的带宽。\nrepl-backlog-size 1mb 设置backlog的大小,backlog是一个缓冲区,在slave端失连时存放要同步到slave的数据,因此当一个slave要重连时,经常是不需要完全同步的,执行局部同步就足够了。\nbacklog设置的越大,slave可以失连的时间就越长。\nrepl-backlog-ttl 3600 如果一段时间后没有slave连接到master,则backlog size的内存将会被释放。如果值为0则表示永远不释放这部份内存。\nslave-priority 100 slave端的优先级设置,值是一个整数,数字越小表示优先级越高。当master故障时将会按照优先级来选择slave端进行恢复,如果值设置为0,则表示该slave永远不会被选择。\nmin-slaves-to-write 3\nmin-slaves-max-lag 10 设置当一个master端的可用slave少于N个,延迟时间大于M秒时,不接收写操作。\n
\n

# 从服务

\n
基本配置同主服务一致\nslaveof 127.0.0.1 6379(主redis的ip和端口)\nmasterauth 123456 (主redis的密码)\n可以通过slaveof no one命令将Slaver升级为Maste\nbgsave (持久化命令,在redis-cli中执行,默认创建dump.rdb文件,路径为 /var/lib/redis/dump.rdb。可通过find / -name dump.rd查找)\n
\n

# 相关命令

\n
看状态\nsudo /etc/init.d/redis-server status\n看端口\nnetstat -nlt|grep 6379\n外部连接\nsudo vim /etc/redis/redis.conf把protected-mode改为no,把bind ip注释掉\n重启\nsudo server redis-server restart\n查看内存\nfree -m\n批量删除指定key\nredis-cli -n 6 scan 0 match *2020-06-12 count 10000| xargs redis-cli -n 6 del\n大量删除key后快速释放被占用的内存\nmemory purge\n
\n

# 问题解决

\n
写入问题\nredis-cli config set stop-writes-on-bgsave-error no\nsudo vim /etc/redis/redis.conf把stop-writes-on-bgsave-error改为no\n修改系统 sudo vim /etc/sysctl.conf加入vm.overcommit_memory=1\nsudo sysctl vm.overcommit_memory=1\n
\n", "tags": [ "Linux", "服务", "redis" ] }, { "id": "https://blog.jingxiyuan.cn/2022/10/14/nginx%E5%85%81%E8%AE%B8%E8%B7%A8%E5%9F%9F%E8%8E%B7%E5%8F%96cookies%E6%96%B9%E6%B3%95/", "url": "https://blog.jingxiyuan.cn/2022/10/14/nginx%E5%85%81%E8%AE%B8%E8%B7%A8%E5%9F%9F%E8%8E%B7%E5%8F%96cookies%E6%96%B9%E6%B3%95/", "title": "nginx允许跨域获取cookie的方法", "date_published": "2022-10-14T09:13:00.000Z", "content_html": "

# 使用场景

\n

  在 A 域名的页面向 B 域名提交数据时需要代入 B 域名的 cookie,否则 B 域名会跳转到登陆页面。解决方式需要使用到 nginx 反向代理,配置如下:

\n
server {\n\tlisten port ssl http2;\n\tserver_name xxx.com;\n\tssl_certificate_key /xxx.key;\n\tssl_certificate /xxx.pem;\n\tproxy_cookie_path ~(.*) "$1; SameSite=None; secure; httponly";\n\n\tlocation / {\n\t\t#允许镶套的方式(可以同域镶套、指定域名镶套或者所有域名镶套)\n\t\tadd_header X-Frame-Options ALLOWALL; #允许被所有域名镶套\n\t\tproxy_pass http://xxx;\n\t}\n}\n
\n", "tags": [ "Linux", "服务", "Nginx", "nginx", "iframe", "cookie" ] }, { "id": "https://blog.jingxiyuan.cn/2022/10/12/%E4%BD%BF%E7%94%A8picgo%E4%B8%8A%E4%BC%A0%E5%9B%BE%E7%89%87%E5%88%B0chevereto/", "url": "https://blog.jingxiyuan.cn/2022/10/12/%E4%BD%BF%E7%94%A8picgo%E4%B8%8A%E4%BC%A0%E5%9B%BE%E7%89%87%E5%88%B0chevereto/", "title": "使用PicGo上传图片到chevereto", "date_published": "2022-10-12T06:40:00.000Z", "content_html": "

# 简介

\n

PicGo 是一款开源的图床管理工具,十分流行。

\n

PicGo 官方指南:PicGo | PicGo

\n

# 配置

\n
    \n
  1. \n

    安装插件(需要先安装 NodeJS)
    \n\"\"

    \n
  2. \n
  3. \n

    图床配置  
    \nurl 后缀必须用红线圈中的部分,key 在 chevereto 登陆后 api 配置中查找
    \n\"\"

    \n
  4. \n
\n", "tags": [ "Windows", "工具", "PicGo", "chevereto" ] }, { "id": "https://blog.jingxiyuan.cn/2022/10/11/svn%E5%BA%93%E8%BD%ACgit%E5%BA%93/", "url": "https://blog.jingxiyuan.cn/2022/10/11/svn%E5%BA%93%E8%BD%ACgit%E5%BA%93/", "title": "svn库转git库", "date_published": "2022-10-11T02:40:00.000Z", "content_html": "

# 前期准备

\n

  首先安装好 svn 和 git 工具。

\n

# svn 转 git

\n

1、 到 svn 项目目录右键选中 gitbash 打开窗口,执行获取用户并映射成 git 样式账号命令如下:
\n svn log -q | awk -F '|' '/^r/ {sub("^ ", "", $2); sub(" $", "", $2); print $2" = "$2" <"$2">"}' | sort -u > users.txt

\n

  然后会在目录下生成文件 users.txt 样式如:zhansan = 张三 zhansan@xxx.com

\n

2、新建个文件夹,将生成的 users.txt 放入新建的文件夹,然后在新建的文件夹中右键选中 gitbash 弹出窗口后执行下面命令(https://svn_project_url/ 为 svn 库的 url),拉取 svn 代码到本地新建文件夹中。
\n git svn clone https://svn_project_url/ --no-metadata --no-minimize-url --authors-file=users.txt

\n\n

# 推送项目到 git 库

\n

1、在 gitbash 窗口 cd 到 git 项目文件夹中执行以下命令把 git 仓库地址加入到 remote 中(https://git_project_url/ 为 git 库的 url)。
\n git remote add origin https://git_project_url/

\n

2、push 项目到 git 库中。
\n git push origin master

\n", "tags": [ "Windows", "工具", "svn", "git" ] }, { "id": "https://blog.jingxiyuan.cn/2022/10/06/Nginx%E9%85%8D%E7%BD%AEiframe%E8%AE%BF%E9%97%AE/", "url": "https://blog.jingxiyuan.cn/2022/10/06/Nginx%E9%85%8D%E7%BD%AEiframe%E8%AE%BF%E9%97%AE/", "title": "Nginx配置iframe访问", "date_published": "2022-10-06T15:46:00.000Z", "content_html": "

# X-Frame-Options 响应头配置详解

\n

  X-Frame-Options HTTP 响应头是用来给浏览器指示允许一个页面可否在,或者 中展现的标记。网站可以使用此功能,来确保自己网站的内容没有被嵌套到别人的网站中去,也从而避免了点击劫持 (clickjacking) 的攻击。
\nX-Frame-Options 三个参数:

\n

1、 DENY

\n

  表示该页面不允许在 frame 中展示,即便是在相同域名的页面中嵌套也不允许。

\n

2、SAMEORIGIN

\n

  表示该页面可以在相同域名页面的 frame 中展示。

\n

3、ALLOW-FROM uri

\n

  表示该页面可以在指定来源的 frame 中展示。

\n

4、ALLOWALL

\n

  表示该页面可以在任何来源的 frame 中展示。

\n

  换一句话说,如果设置为 DENY,不光在别人的网站 frame 嵌入时会无法加载,在同域名页面中同样会无法加载。另一方面,如果设置为 SAMEORIGIN,那么页面就可以在同域名页面的 frame 中嵌套。正常情况下我们通常使用 SAMEORIGIN 参数。

\n

# Apache 配置

\n

  需要把下面这行添加到'site' 的配置中

\n

   Header always append X-Frame-Options SAMEORIGIN

\n

# Nginx 配置

\n

  需要添加到 ‘http’, ‘server’ 或者 ‘location’ 的配置项中,个人来讲喜欢配置在‘server’ 中

\n

  正常情况下都是使用 SAMEORIGIN 参数,允许同域嵌套
\n   add_header X-Frame-Options SAMEORIGIN;

\n

  允许单个域名 iframe 嵌套
\n   add_header X-Frame-Options ALLOW-FROM http://xxx.com/;

\n

  允许多个域名 iframe 嵌套,注意这里是用逗号分隔
\n   add_header X-Frame-Options "ALLOW-FROM http://xxx.com/,https://xxx.com/";

\n

  允许任何域名 iframe 嵌套
\n   add_header X-Frame-Options ALLOWALL;

\n

# Tomcat 配置

\n

  在‘conf/web.xml’填加以下配置

\n
<filter>
        <filter-name>httpHeaderSecurity</filter-name>
        <filter-class>org.apache.catalina.filters.HttpHeaderSecurityFilter</filter-class>
        <init-param>
            <param-name>antiClickJackingOption</param-name>
            <param-value>SAMEORIGIN</param-value>
        </init-param>
        <async-supported>true</async-supported>
    </filter>
<filter-mapping>
        <filter-name>httpHeaderSecurity</filter-name>
        <url-pattern>/*</url-pattern>
    <dispatcher>REQUEST</dispatcher>
    <dispatcher>FORWARD</dispatcher>
</filter-mapping>

# IIS 配置

\n

  添加下面的配置到 ‘Web.config’文件中

\n
<system.webServer>
  <httpProtocol>
    <customHeaders>
      <add name=\"X-Frame-Options\" value=\"SAMEORIGIN\" />
    </customHeaders>
  </httpProtocol>
</system.webServer>
", "tags": [ "Linux", "服务", "Nginx", "nginx", "iframe" ] }, { "id": "https://blog.jingxiyuan.cn/2022/09/28/%E6%B7%B1%E6%B7%B1%E7%9A%84%E6%8C%AB%E8%B4%A5%E5%92%8C%E6%97%A0%E5%8A%A9%E6%84%9F/", "url": "https://blog.jingxiyuan.cn/2022/09/28/%E6%B7%B1%E6%B7%B1%E7%9A%84%E6%8C%AB%E8%B4%A5%E5%92%8C%E6%97%A0%E5%8A%A9%E6%84%9F/", "title": "深深的挫败和无助感", "date_published": "2022-09-28T08:02:00.000Z", "content_html": "

  一个月都过去了,工作还没有着落!

\n", "tags": [ "生活", "心情", "心情", "郁闷" ] }, { "id": "https://blog.jingxiyuan.cn/2022/09/27/nginx%E8%B4%9F%E8%BD%BD%E5%9D%87%E8%A1%A1%E9%85%8D%E7%BD%AE/", "url": "https://blog.jingxiyuan.cn/2022/09/27/nginx%E8%B4%9F%E8%BD%BD%E5%9D%87%E8%A1%A1%E9%85%8D%E7%BD%AE/", "title": "nginx负载均衡配置", "date_published": "2022-09-27T06:45:00.000Z", "content_html": "

# nginx 负载均衡配置

\n
    \n
  1. 轮询(默认)
  2. \n
\n

  每个请求按时间顺序逐一分配到不同的后端服务器,如果后端服务器 down 掉,能自动剔除。

\n
upstream my_server {\n\tserver 192.168.0.2:8080;\n\tserver 192.168.0.3:8080;\n}\n\nserver {\n\tlisten 80;\n\tserver_name 192.168.0.1;\n\n\t# Path to the root of your installation\n\tlocation / {\n\t\tproxy_pass http://my_server;\n\t}\n\t\n}\n
\n
    \n
  1. weight 权重策略
  2. \n
\n

  weight 代表权重,默认为 1,权重越高被分配的客户端越多,指定轮询几率。weight 和访问比率成正比,用于后端服务器性能不均的情况。

\n
upstream my_server {\n\tserver 192.168.0.2:8080 weight=1;\n\tserver 192.168.0.3:8080 weight=2;\n}\n\nserver {\n\tlisten 80;\n\tserver_name 192.168.0.1;\n\n\t# Path to the root of your installation\n\tlocation / {\n\t\tproxy_pass http://my_server;\n\t}\n\t\n}\n
\n
    \n
  1. ip_hash
  2. \n
\n

  每个请求按访问 ip 的 hash 结果分配,这样每个访客固定访问一个后端服务器,可以解决 session 的问题。

\n
upstream my_server {\n\tip_hash;\n\tserver 192.168.0.2:8080;\n\tserver 192.168.0.3:8080;\n}\n\nserver {\n\tlisten 80;\n\tserver_name 192.168.0.1;\n\n\t# Path to the root of your installation\n\tlocation / {\n\t\tproxy_pass http://my_server;\n\t}\n\t\n}\n
\n
    \n
  1. fair (第三方)
  2. \n
\n

  按后端服务器的响应时间来分配请求,响应时间短的优先分配。

\n
upstream my_server {\n\tserver 192.168.0.2:8080;\n\tserver 192.168.0.3:8080;\n\tfair;\n}\n\nserver {\n\tlisten 80;\n\tserver_name 192.168.0.1;\n\n\t# Path to the root of your installation\n\tlocation / {\n\t\tproxy_pass http://my_server;\n\t}\n\t\n}\n
\n
    \n
  1. 动静分离
  2. \n
\n

  把静态的资源,比如图片,css,js 等先加载到 Nginx 的服务器里。

\n", "tags": [ "Linux", "服务", "Nginx", "nginx", "负载均衡" ] } ] }