深入学习keepalived之一 keepalived的启动
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的启动的更多相关文章
- keepalived之 Keepalived 原理(定义、VRRP 协议、VRRP 工作机制)
1.Keepalived 定义 Keepalived 是一个基于VRRP协议来实现的LVS服务高可用方案,可以利用其来避免单点故障.一个LVS服务会有2台服务器运行Keepalived,一台为主服务器 ...
- (转)redis 学习笔记(1)-编译、启动、停止
redis 学习笔记(1)-编译.启动.停止 一.下载.编译 redis是以源码方式发行的,先下载源码,然后在linux下编译 1.1 http://www.redis.io/download 先 ...
- Windows phone 8 学习笔记(4) 应用的启动
原文:Windows phone 8 学习笔记(4) 应用的启动 Windows phone 8 的应用除了可以直接从开始菜单以及应用列表中打开外,还可以通过其他的方式打开.照片中心.音乐+视频中心提 ...
- springboot 学习之路 9 (项目启动后就执行特定方法)
目录:[持续更新.....] spring 部分常用注解 spring boot 学习之路1(简单入门) spring boot 学习之路2(注解介绍) spring boot 学习之路3( 集成my ...
- zookeeper学习(零)_安装与启动
zookeeper学习(零)_安装与启动 最近换了新的电脑,终于买了梦寐以求的macbook.最近也换了新的公司,公司技术栈用到了zookeeper.当然自己也要安装学习下.省的渣渣的我,被鄙视就麻烦 ...
- keepalived yum安装后启动报错解决
[root@centos8 ~]yum install keepalived -y [root@centos8 ~]systemctl start keepalived.services [root@ ...
- (二)Netty源码学习笔记之服务端启动
尊重原创,转载注明出处,原文地址:http://www.cnblogs.com/cishengchongyan/p/6129971.html 本文将不会对netty中每个点分类讲解,而是一个服务端启 ...
- Hadoop学习11--Ha集群配置启动
理论知识: http://www.tuicool.com/articles/jameeqm 这篇文章讲的非常详细了: http://www.tuicool.com/articles/jameeqm 以 ...
- Android学习笔记1 android adb启动失败问题 adb server is out of date. killing...
下面是Android的学习笔记,原文地址. 我是使用adb devices出现如下红字错误, 使用第一种方法方法,结果关掉豌豆荚就可以了. android adb启动失败问题 adb server i ...
随机推荐
- windows下go调用内存dll
有时候我们希望将dll嵌入到程序内部,以提高程序的安全性,这里我写的一个开源memorydll模块. 首先 go get github.com/nkbai/go-memorydll 然后在需要的时候 ...
- django中itsdangerous的用法
itsdangerous用来解决什么问题,为什么需要用到itsdangerous? 安装命令:pip install itsdangerous 有时候你想向不可信的环境发送一些数据,但如何安全完成这个 ...
- MySQL 学习笔记(二):数据库更新、视图和数据控制
基础准备: 在 school 数据库下建立student.course.sc 三个表: create table student( Sno ) primary key, Sname ) unique, ...
- Java面向对象之构造代码块 入门实例
一.基础概念 1.构造代码块,给所有对象进行初始化. 2.构造函数,只给对应的对象初始化. 3.局部代码块,控制局部变量的生命周期. 二.实例代码 class Person { private int ...
- java集合类学习笔记之ArrayList
1.简述 ArrayList底层的实现是使用了数组保存所有的数据,所有的操作本质上是对数组的操作,每一个ArrayList实例都有一个默认的容量(数组的大小,默认是10),随着 对ArrayList不 ...
- Javascript 上传文件到Azure存储
对一些前端工程师来讲,使用javascript上传文件到Azure存储中可能是需要掌握的技能,希望这篇博客能给到帮助. 在开始前我们需要了解以下几点: 共享访问签名(Shared Access Sig ...
- PHP简单实现一言 / 随机一句功能
很多网站都喜欢在页面中加个一言,不过一般都是调用的第三方api.其实,使用万能的php能用短短的几行代码就实现该功能! 将下列代码复制并粘贴到 api.php 中保存,你的专属“一言” API 就搭建 ...
- PHP脚本占用内存太多,解决方案
Fatal Error: Allowed memory size of xxxxxx bytes exhausted 今天遇到服务器很多自动任务的php脚本占用服务内存过多,并且程序不在运行了. 解决 ...
- DQL、DML、DDL、DCL的区别
1. 历史发展 SQL(Structure Query Language)语言是数据库的核心语言. SQL的发展是从1974年开始的,其发展过程如下:1974年-----由Boyce和Chamberl ...
- LeetCode905.按奇偶排序数组
905.按奇偶排序数组 问题描述 给定一个非负整数数组 A,返回一个由 A 的所有偶数元素组成的数组,后面跟 A 的所有奇数元素. 你可以返回满足此条件的任何数组作为答案. 示例 输入:[3,1,2, ...