1.keepalived的启动过程:

启动健康检查子进程和vrrp子进程。其中_WITH_LVS_,_WITH_VRRP_在configure和configure.in文件中定义。

源码如下:

/* Daemon init sequence */
static void
start_keepalived(void)
{
#ifdef _WITH_LVS_
/* start healthchecker child */
if (daemon_mode & || !daemon_mode)
start_check_child();
#endif
#ifdef _WITH_VRRP_
/* start vrrp child */
if (daemon_mode & || !daemon_mode)
start_vrrp_child();
#endif
}

2. 启动健康检查子进程。

/* Register CHECK thread */
int
start_check_child(void)
{
#ifndef _DEBUG_
pid_t pid;
int ret; /* Initialize child process */
pid = fork(); if (pid < ) {
log_message(LOG_INFO, "Healthcheck child process: fork error(%s)"
, strerror(errno));
return -;
} else if (pid) {
checkers_child = pid;
log_message(LOG_INFO, "Starting Healthcheck child process, pid=%d"
, pid); /* Start respawning thread */
thread_add_child(master, check_respawn_thread, NULL,
pid, RESPAWN_TIMER);
return ;
} /* Opening local CHECK syslog channel */
openlog(PROG_CHECK, LOG_PID | ((debug & ) ? LOG_CONS : ),
(log_facility==LOG_DAEMON) ? LOG_LOCAL2 : log_facility); /* Child process part, write pidfile */
if (!pidfile_write(checkers_pidfile, getpid())) {
log_message(LOG_INFO, "Healthcheck child process: cannot write pidfile");
exit();
} /* Create the new master thread */
signal_handler_destroy();
thread_destroy_master(master);
master = thread_make_master(); /* change to / dir */
ret = chdir("/");
if (ret < ) {
log_message(LOG_INFO, "Healthcheck child process: error chdir");
} /* Set mask */
umask();
#endif /* If last process died during a reload, we can get there and we
* don't want to loop again, because we're not reloading anymore.
*/
UNSET_RELOAD; /* Signal handling initialization */
check_signal_init(); /* Start Healthcheck daemon */
start_check(); /* Launch the scheduling I/O multiplexer */
launch_scheduler(); /* Finish healthchecker daemon process */
stop_check();
exit();
}

debug模式暂且不考虑。

2.1 健康检查信号初始化

/* CHECK Child signal handling */
void
check_signal_init(void)
{
signal_handler_init();
signal_set(SIGHUP, sighup_check, NULL);
signal_set(SIGINT, sigend_check, NULL);
signal_set(SIGTERM, sigend_check, NULL);
signal_ignore(SIGPIPE);
} /* Handlers intialization */
void
signal_handler_init(void)
{
int n = pipe(signal_pipe);
assert(!n); fcntl(signal_pipe[], F_SETFL, O_NONBLOCK | fcntl(signal_pipe[], F_GETFL));
fcntl(signal_pipe[], F_SETFL, O_NONBLOCK | fcntl(signal_pipe[], F_GETFL)); signal_SIGHUP_handler = NULL;
signal_SIGINT_handler = NULL;
signal_SIGTERM_handler = NULL;
signal_SIGCHLD_handler = NULL;
}

2.2 启动健康检查后台程序

/* Daemon init sequence */
static void
start_check(void)
{
/* Initialize sub-system */
ipvs_start();
init_checkers_queue();
#ifdef _WITH_VRRP_
init_interface_queue();
kernel_netlink_init();
#endif
#ifdef _WITH_SNMP_
if (!reload && snmp)
check_snmp_agent_init();
#endif /* Parse configuration file */
global_data = alloc_global_data();
check_data = alloc_check_data();
init_data(conf_file, check_init_keywords);
if (!check_data) {
stop_check();
return;
} /* Post initializations */
log_message(LOG_INFO, "Configuration is using : %lu Bytes", mem_allocated); /* SSL load static data & initialize common ctx context */
if (!init_ssl_ctx()) {
stop_check();
return;
} /* Processing differential configuration parsing */
if (reload) {
clear_diff_services();
copy_srv_states();
} /* Initialize IPVS topology */
if (!init_services()) {
stop_check();
return;
} /* Dump configuration */
if (debug & ) {
dump_global_data(global_data);
dump_check_data(check_data);
} #ifdef _WITH_VRRP_
/* Initialize linkbeat */
init_interface_linkbeat();
#endif /* Register checkers thread */
register_checkers_thread();
}

2.3 启动I/O复用分发调度器

/* Our infinite scheduling loop */
void
launch_scheduler(void)
{
thread_t thread; signal_set(SIGCHLD, thread_child_handler, master); /*
* Processing the master thread queues,
* return and execute one ready thread.
*/
while (thread_fetch(master, &thread)) {
/* Run until error, used for debuging only */
#ifdef _DEBUG_
if ((debug & ) == ) {
debug &= ~;
thread_add_terminate_event(master);
}
#endif
thread_call(&thread);
}
}

深入学习keepalived之一 keepalived的启动的更多相关文章

  1. keepalived之 Keepalived 原理(定义、VRRP 协议、VRRP 工作机制)

    1.Keepalived 定义 Keepalived 是一个基于VRRP协议来实现的LVS服务高可用方案,可以利用其来避免单点故障.一个LVS服务会有2台服务器运行Keepalived,一台为主服务器 ...

  2. (转)redis 学习笔记(1)-编译、启动、停止

    redis 学习笔记(1)-编译.启动.停止   一.下载.编译 redis是以源码方式发行的,先下载源码,然后在linux下编译 1.1 http://www.redis.io/download 先 ...

  3. Windows phone 8 学习笔记(4) 应用的启动

    原文:Windows phone 8 学习笔记(4) 应用的启动 Windows phone 8 的应用除了可以直接从开始菜单以及应用列表中打开外,还可以通过其他的方式打开.照片中心.音乐+视频中心提 ...

  4. springboot 学习之路 9 (项目启动后就执行特定方法)

    目录:[持续更新.....] spring 部分常用注解 spring boot 学习之路1(简单入门) spring boot 学习之路2(注解介绍) spring boot 学习之路3( 集成my ...

  5. zookeeper学习(零)_安装与启动

    zookeeper学习(零)_安装与启动 最近换了新的电脑,终于买了梦寐以求的macbook.最近也换了新的公司,公司技术栈用到了zookeeper.当然自己也要安装学习下.省的渣渣的我,被鄙视就麻烦 ...

  6. keepalived yum安装后启动报错解决

    [root@centos8 ~]yum install keepalived -y [root@centos8 ~]systemctl start keepalived.services [root@ ...

  7. (二)Netty源码学习笔记之服务端启动

    尊重原创,转载注明出处,原文地址:http://www.cnblogs.com/cishengchongyan/p/6129971.html  本文将不会对netty中每个点分类讲解,而是一个服务端启 ...

  8. Hadoop学习11--Ha集群配置启动

    理论知识: http://www.tuicool.com/articles/jameeqm 这篇文章讲的非常详细了: http://www.tuicool.com/articles/jameeqm 以 ...

  9. Android学习笔记1 android adb启动失败问题 adb server is out of date. killing...

    下面是Android的学习笔记,原文地址. 我是使用adb devices出现如下红字错误, 使用第一种方法方法,结果关掉豌豆荚就可以了. android adb启动失败问题 adb server i ...

随机推荐

  1. c#winform pictureBox使用url加载图片

    string url = "http://b.hiphotos.baidu.com/image/pic/item/03087bf40ad162d93b3a196f1fdfa9ec8b13cd ...

  2. webservice不能序列化接口问题,返回值为IList或者参数为接口的解决办法。

    1. webservice 不能返回泛型接口集合IList,解决办法如下链接: 参考资料:http://www.cnblogs.com/yinhaiming/articles/1379424.html ...

  3. sqlite数据库文件查看

  4. memcached装、启动和卸载

    1.下载相关软件: 下载地址:http://download.csdn.net/download/wangshuxuncom/8249501: 2.解压获取到的压缩文件,将得到一个名为“memcach ...

  5. HTML中&nbsp; &ensp; &emsp; &thinsp;等6种空白空格

  6. python 时间相关函数

    python 中与时间处理相关的模块包括 time.datetime.以及 calendar time 模块 time() 函数:time() 函数用于返回当前时间的时间戳(1970年01月08时00 ...

  7. python3入门之字符串

    获得更多资料欢迎进入我的网站或者 csdn或者博客园 经过前面的介绍相信大家也对python有了一个初步的了解:本节主要介绍字符串,不管学习什么编语言字符串一定在其中扮演着重要的地位.本节主要讲解,字 ...

  8. php中的静态方法实例理解

    <?php header("content-type:text/html;charset=utf-8"); class Human{ static public $name ...

  9. Android WebView的使用(用来显示网页)

    1.WebView介绍 2.URL介绍 简单说就是网址. 3.java后台代码 package com.lucky.test34webview; import android.support.v7.a ...

  10. python之常用的数据类型

    1. 变量的定义以及声明 在学习变量之前,咱们需要知道变量的命名规则: ① 变量必须由数字字母下划线构成,如a_1 ② 变量名不能以数字开头,如1a ③ 需要遵循驼峰命名法 给变量赋值通常采用“=”, ...