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. iOS 查看代码总行数

    1.打开终端 2.cd 拖入工程 回车 3.输入命令 find . "(" -name "*.m" -or -name "*.mm" -or ...

  2. OC字符串与C语言字符串之间的相互转换

    1.C转OC字符串 const char *cString = "This is a C string"; // 动态方法 NSString *ocString1 = [[NSSt ...

  3. 【bzoj3576】[Hnoi2014]江南乐 数论分块+博弈论

    Description 小A是一个名副其实的狂热的回合制游戏玩家.在获得了许多回合制游戏的世界级奖项之后,小A有一天突然想起了他小时候在江南玩过的一个回合制游戏. 游戏的规则是这样的,首先给定一个数F ...

  4. 消息中间件ActiveMQ、RabbitMQ、RocketMQ、ZeroMQ、Kafka如何选型?

    最近要为公司的消息队列中间件进行选型,市面上相关的开源技术又非常多,如ActiveMQ.RabbitMQ.ZeroMQ.Kafka,还有阿里巴巴的RocketMQ等. 这么多技术,如何进行选型呢? 首 ...

  5. 【ExecutorService】概述

    初试 今天做一个上传excel,后台异步导入数据功能,使用ExecutorService private final ExecutorService m_longPollingService; pub ...

  6. struts2配置文件中的method={1}详解

    struts.xml中的配置: <!-- 配置用户模块的action --> <action name="user_*" class="userActi ...

  7. 洛谷 P2096 最佳旅游线路

    某旅游区的街道成网格状.其中东西向的街道都是旅游街,南北向的街道都是林阴道.由于游客众多,旅游街被规定为单行道,游客在旅游街上只能从西向东走,在林阴道上则既可从南向北走,也可以从北向南走. 阿龙想到这 ...

  8. c语言数据结构学习心得——数据结构基本概念

    1.数据>数据元素>数据项      数据的基本单位是数据元素,数据元素的基本单位是数据项 2.运算的定义->针对逻辑结构 集合:同属于一个集合,无其他关系.(数学上的集合) 线性结 ...

  9. SDUT OJ 效率至上(线段树)

    效率至上 Time Limit: 5000 ms Memory Limit: 65536 KiB Submit Statistic Problem Description 题意很简单,给出一个数目为n ...

  10. 一个很棒的PHP缓存类,收藏下

    <?php class Cache { /** 缓存目录 **/ var $CacheDir = './cache'; /** 缓存的文件 **/ var $CacheFile = ''; /* ...