日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問(wèn) 生活随笔!

生活随笔

當(dāng)前位置: 首頁(yè) > 编程资源 > 编程问答 >内容正文

编程问答

深入学习keepalived之一 keepalived的启动

發(fā)布時(shí)間:2025/4/5 编程问答 35 豆豆
生活随笔 收集整理的這篇文章主要介紹了 深入学习keepalived之一 keepalived的启动 小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

1.keepalived的啟動(dòng)過(guò)程:

? ? 啟動(dòng)健康檢查子進(jìn)程和vrrp子進(jìn)程。其中_WITH_LVS_,_WITH_VRRP_在configure和configure.in文件中定義。

源碼如下:

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

2.?啟動(dòng)健康檢查子進(jìn)程。

/* Register CHECK thread */ int start_check_child(void) { #ifndef _DEBUG_pid_t pid;int ret;/* Initialize child process */pid = fork();if (pid < 0) {log_message(LOG_INFO, "Healthcheck child process: fork error(%s)", strerror(errno));return -1;} 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 0;}/* Opening local CHECK syslog channel */openlog(PROG_CHECK, LOG_PID | ((debug & 1) ? LOG_CONS : 0),(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(0);}/* Create the new master thread */signal_handler_destroy();thread_destroy_master(master);master = thread_make_master();/* change to / dir */ret = chdir("/");if (ret < 0) {log_message(LOG_INFO, "Healthcheck child process: error chdir");}/* Set mask */umask(0); #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(0); }

debug模式暫且不考慮。

2.1 健康檢查信號(hào)初始化

/* 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[0], F_SETFL, O_NONBLOCK | fcntl(signal_pipe[0], F_GETFL));fcntl(signal_pipe[1], F_SETFL, O_NONBLOCK | fcntl(signal_pipe[1], F_GETFL));signal_SIGHUP_handler = NULL;signal_SIGINT_handler = NULL;signal_SIGTERM_handler = NULL;signal_SIGCHLD_handler = NULL; }

2.2 啟動(dòng)健康檢查后臺(tái)程序

/* 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 & 4) {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 啟動(dòng)I/O復(fù)用分發(fā)調(dià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 & 520) == 520) {debug &= ~520;thread_add_terminate_event(master);} #endifthread_call(&thread);} }

?

?

?

?

?

轉(zhuǎn)載于:https://www.cnblogs.com/davidwang456/p/3543098.html

《新程序員》:云原生和全面數(shù)字化實(shí)踐50位技術(shù)專(zhuān)家共同創(chuàng)作,文字、視頻、音頻交互閱讀

總結(jié)

以上是生活随笔為你收集整理的深入学习keepalived之一 keepalived的启动的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。

如果覺(jué)得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。