Browse files

add port probe program.

  • Loading branch information...
1 parent ffac0b6 commit 0adf66d031e3dc3411156cf0e023b708d015bf80 @digoal committed Nov 15, 2012
Showing with 78 additions and 2 deletions.
  1. +8 −1 INSTALL.txt
  2. +69 −0 port_probe.c
  3. +1 −1 sky_pg_clusterd.sh
View
9 INSTALL.txt
@@ -374,6 +374,12 @@ vi /home/postgres/.pgpass
127.0.0.1:1921:sky_pg_cluster:sky_pg_cluster:SKY_PG_cluster_321
192.168.101.35:11921:sky_pg_cluster:sky_pg_cluster:SKY_PG_cluster_321
+编译port_probe : (node1, node2):
+gcc -O3 -Wall -Wextra -Werror -g -o port_probe ./port_probe.c
+chmod 555 port_probe
+mv port_probe /usr/local/bin
+测试port_probe是否正常:
+port_probe $node_ip $port
配置failover, log_filter, nagios脚本 : (node1, node2):
1. /usr/local/bin/sky_pg_clusterd.sh
@@ -450,7 +456,8 @@ service xinetd restart
2. 关闭vip和vote_host上的转发端口, 不发生failover
3. 关闭主库, 发生failover.(可能因为telnet vote:proxy_port返回1而造成无法满足切换条件.
原因是balance在处理tcp三次握手时需要和后面的主机交互,所以如果关闭了主库,将会收到主库的reset信号关闭连接.
- 这种情况下telnet的返回值是1.)
+ 这种情况下telnet的返回值是1.
+ 所以探测vote上的端口代理是否正常改用port_probe程序.)
4. 关闭standby网卡, 不发生failover
View
69 port_probe.c
@@ -0,0 +1,69 @@
+/*
+# 用于探测仲裁服务器上的vip端口代理.
+# install:
+# gcc -O3 -Wall -Wextra -Werror -g -o port_probe ./port_probe.c
+
+# Author : Digoal zhou
+# Email : digoal@126.com
+# Blog : http://blog.163.com/digoal@126/
+*/
+
+
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+#include <errno.h>
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <strings.h>
+#include <netinet/in.h>
+#include <arpa/inet.h>
+#include <unistd.h>
+#include <sys/time.h>
+
+// 错误函数, 当exit_val=0只输出错误信息, 不退出程序. 其他值输出错误信息并退出程序
+void error(char * msg, int exit_val);
+
+void error(char * msg, int exit_val) {
+ fprintf(stderr, "%s: %s\n", msg, strerror(errno));
+ // if exit_val == 0, not exit the program.
+ if (exit_val)
+ exit(exit_val);
+}
+
+int main(int argc,char *argv[])
+{
+ if(argc == 1)
+ error("USAGE [program ip port]", 1);
+ int cfd;
+ struct sockaddr_in s_add;
+
+ cfd = socket(AF_INET, SOCK_STREAM, 0);
+ if(-1 == cfd)
+ error("socket create failed!", -1);
+ fprintf(stdout, "socket created!\n");
+
+ bzero(&s_add, sizeof(struct sockaddr_in));
+ s_add.sin_family=AF_INET;
+ s_add.sin_addr.s_addr= inet_addr(argv[1]);
+ s_add.sin_port=htons(atoi(argv[2]));
+
+ // 设置连接超时, 否则如果端口不通, connect可能会很久.
+ struct timeval tv_timeout;
+ tv_timeout.tv_sec = 2;
+ tv_timeout.tv_usec = 0;
+ if (setsockopt(cfd, SOL_SOCKET, SO_SNDTIMEO, (void *) &tv_timeout, sizeof(struct timeval)) < 0) {
+ error("setsockopt error!", -1);
+ }
+ if (setsockopt(cfd, SOL_SOCKET, SO_RCVTIMEO, (void *) &tv_timeout, sizeof(struct timeval)) < 0) {
+ error("setsockopt error!", -1);
+ }
+
+ if(-1 == connect(cfd, (struct sockaddr *)(&s_add), sizeof(struct sockaddr))) {
+ error("connect failed!", -1);
+ }
+ fprintf(stdout, "connect ok!\n");
+
+ close(cfd);
+ return 0;
+}
View
2 sky_pg_clusterd.sh
@@ -141,7 +141,7 @@ do
break
fi
# 判断从standby机器到仲裁机的跳转端口网络是否正常. 0正常. 如果结果不正常, 后面判断就省略了.
- echo -e "q"|telnet -e "q" $VOTE_IP $VOTE_PORT
+ /usr/local/bin/port_probe $VOTE_IP $VOTE_PORT
VOTEHOST_STATUS=$?
if [ $VOTEHOST_STATUS -ne 0 ]; then
break

0 comments on commit 0adf66d

Please sign in to comment.