排查elasticsearch的cpu居高不下,查询慢的问题

背景 近来es查询很慢,kibana的discover界面偶尔还会因为查询请求超时而无法显示数据。/_cat/indices?v 等对es的查询也慢的出奇,需要1、2分钟才返回结果。 排查 top命令看了es的java进程,发现cpu一直很高,130%左右,一直没有下降过。查看es的日志,发现gc.log中几乎每秒都要触发一次GC Full GC (Allocation Failure)。内存不够用,又没有内存可回收,所以GC也不断。怪不得CPU这么高,大部分时间都用在gc上面了。 处理 调整es可使用的内存大小。编辑config/jvm.options,调整了Xms和Xmx的大小,由原来默认的1g调整为10g。(官方建议这个值不要超过物理内存的50%,也不要超过32G。详见官网说明)接着重启es就好了。观察cpu,虽然偶尔也会彪上130%,但总体来说正常了,查询也变得很快。 ps:es重启后,需要观察logstash是否退出了。如果退出,需要重新把logstash拉起来。 pss:这次是小坑,后面可能还有很多大坑需要踩。后续有cpu高、查询慢的问题也一并归类到该文。

2018-07-16 · 1 分钟 · 13 字

mac卸载和安装java指定版本

2020-04-02更新: 之前的安装方法已经废弃了,可通过以下方式安装 brew tap AdoptOpenJDK/openjdk brew cask install <version> 这里有全部的version列表 例如可以这么安装 brew cask install adoptopenjdk8 之前用brew安装了java9。但我有些软件不兼容,只能降级到java8。这里简单记录下步骤。 卸载 brew cask uninstall java 安装指定版本 brew tap caskroom/versions foam@foamdeMBP: sens » brew cask search java [15:13:54] ==> Exact Match java ==> Partial Matches charles-applejava eclipse-javascript java6 netbeans-java-ee yourkit-java-profiler eclipse-java java-jdk-javadoc java8 netbeans-java-se 估计我没更新brew的缘故,上面只列出java6和java8。java7呢,有点懵逼。 键入下面命令,然后就会自动下载安装了。可能会有点慢。 foam@foamdeMBP: sens » brew cask install java8 Updating Homebrew... ^CWarning: Unexpected method 'license' called during caveats on Cask java8. Follow the instructions here: https://github.com/caskroom/homebrew-cask#reporting-bugs ==> Caveats This Cask makes minor modifications to the JRE to prevent issues with packaged applications, as discussed here: https://bugs.eclipse.org/bugs/show_bug.cgi?id=411361 If your Java application still asks for JRE installation, you might need to reboot or logout/login. ==> Satisfying dependencies ==> Downloading http://download.oracle.com/otn-pub/java/jdk/8u172-b11/a58eab1ec242421181065cdc37240b08/jdk-8u172-macosx-x64.dmg ######################################################################## 100.0% ==> Verifying checksum for Cask java8 ==> Installing Cask java8 ==> Running installer for java8; your password may be necessary. ==> Package installers may write to any location; options such as --appdir are ignored. Password: ==> installer: Package name is JDK 8 Update 172 ==> installer: Installing at base path / ==> installer: The install was successful. 🍺 java8 was successfully installed! 确认下,ok了。 ...

2018-06-29 · 1 分钟 · 206 字

Squid使用SSLBump正向代理

背景:最近需要使用nodeJs访问一个历史久远的网站,那个网站的服务器证书是错误的,且使用的协议是TLSv1.0。浏览器上不得不使用IE并关闭各种安全设置和设置为兼容模式才能正常访问。Nodejs的新版本已经不支持这种不安全的协议,所以需要搭建一个代理服务进行访问。刚开始使用的是mitmproxy ,当时的最新版本对于SSL错误会报错,所以将源码中校验部分去掉就可以正常使用了。但部署到生产环境,会出现cpu占用过高的情况。所以后面换了Squid。 部署Squid参考了一篇文章,原文:here,下面是简单翻译。 Squid是个很强大的Web代理,它可以应用于无线认证、重定向、用户身份验证、日志记录等。但其在SSL方面一直存在局限性。在3.2版本之前,Squid的策略只是简单地传递SSL加密流量,因为它无法校验受信任的SSL链接。对于每个SSL连接也无法给用户做预警。但3.5版本后允许更多的控制,但要注意仍然无法校验受信任的SSL链接。 这里不会过多地介绍使用SSL Bump配置Squid以外的知识,对于编译和配置squid的细节你最好看下官方文档。 如果通过代理自动监测,通知浏览器连接到代理服务器,这样是挺简单的。但有些用户可能会试图规避这一点,并尝试直接连接。 在这种情况下,我们需要强制这些用户通过截取流量来使用代理。SSL Bumping的前提是中间人攻击,但由于这是在您的用户清楚所有流量都是检查过的环境中完成的,因此这并不是真正的攻击,这只是一种策略。Squid用于执行SSL Bumping有一些新方法,但是我会总结出最具实战性的方法:Squid收到一个https请求,然后为用户建立安全连接。 远程连接建立后,Squid会重新加密所有流量; 这时候的加密使用的是本地私钥,以及本地证书颁发机构即时创建出来的证书。 所以我们首先要确保的是你已经安装了3.5或更高版本的Squid。尽管3.2,3.3以及3.4版本也能实现,但3.5版本后SSL Bump的指令有了些显著变化。另外,编译Squid时需要带上‘–with-openssl’参数。 在CentOS我使用以下参数来编译Squid(foam:我带上–enable-ipf-transparent参数会报错,所以我是去掉再编译的) ./configure \ --prefix=/usr \ --exec-prefix=/usr \ --includedir=/usr/include \ --datadir=/usr/share \ --libdir=/usr/lib64 \ --libexecdir=/usr/lib64/squid \ --localstatedir=/var \ --sysconfdir=/etc/squid \ --sharedstatedir=/var/lib \ --with-logdir=/var/log/squid \ --with-pidfile=/var/run/squid.pid \ --with-default-user=squid \ --enable-silent-rules \ --enable-dependency-tracking \ --with-openssl \ --enable-icmp \ --enable-delay-pools \ --enable-useragent-log \ --enable-esi \ --enable-follow-x-forwarded-for \ --enable-ipf-transparent \ --enable-auth 接下来我们需要生成本地的SSL证书,这里我使用的是简单的命令,没有在意怎么去加密。 # Generate Private Key openssl genrsa -out example.com.private 2048 然后是创建Certificate Signing Request(CSR),即证书注册请求。 ...

2017-09-23 · 3 分钟 · 630 字

在XAMPP、WAMP等集成环境中配置虚拟站点

对于不喜欢折腾运行环境的同学来说,集成环境包绝对是好东西。由于WAMP上php5.6版本有点小坑,现在已转向XAMPP的怀抱。 给apache服务器授权 打开Apache的配置文件httpd.conf,找到下面的节点 DocumentRoot "C:/xampp/htdocs" <Directory "C:/xampp/htdocs"> # # Possible values for the Options directive are "None", "All", # or any combination of: # Indexes Includes FollowSymLinks SymLinksifOwnerMatch ExecCGI MultiViews # # Note that "MultiViews" must be named *explicitly* --- "Options All" # doesn't give it to you. # # The Options directive is both complicated and important. Please see # http://httpd.apache.org/docs/2.4/mod/core.html#options # for more information. # Options Indexes FollowSymLinks Includes ExecCGI # # AllowOverride controls what directives may be placed in .htaccess files. # It can be "All", "None", or any combination of the keywords: # AllowOverride FileInfo AuthConfig Limit # AllowOverride All # # Controls who can get stuff from this server. # Require all granted </Directory> 可以看到已经在C:/xampp/htdocs目录下授权了,你可以把多个项目放在该目录下。我一般习惯在非系统盘放置项目,此时将C:/xampp/htdocs改为自定义目录就可以。 接着查看是否加载了vhost的配置文件。若你的配置文件没有这一行,你可以手动添加上去并在对应目录新建httpd-vhosts.conf配置文件。 ...

2015-07-23 · 1 分钟 · 135 字