![如何在不使用 CLI 向导的情况下设置 Icinga2 主机(用于远程客户端)?](https://linux22.com/image/669127/%E5%A6%82%E4%BD%95%E5%9C%A8%E4%B8%8D%E4%BD%BF%E7%94%A8%20CLI%20%E5%90%91%E5%AF%BC%E7%9A%84%E6%83%85%E5%86%B5%E4%B8%8B%E8%AE%BE%E7%BD%AE%20Icinga2%20%E4%B8%BB%E6%9C%BA%EF%BC%88%E7%94%A8%E4%BA%8E%E8%BF%9C%E7%A8%8B%E5%AE%A2%E6%88%B7%E7%AB%AF%EF%BC%89%EF%BC%9F.png)
作为后续问题如何在不使用 CLI 向导的情况下设置 Icinga2 远程客户端?,我想以自动化的方式设置主机。
答案1
示例脚本用于解决上述问题。尽情享受吧!
HOSTNAME=`cat /etc/hostname`
icinga2 pki new-ca
chown nagios:nagios /etc/icinga2/pki
icinga2 pki new-cert --cn ${HOSTNAME} --key /etc/icinga2/pki/${HOSTNAME}.key --csr /etc/icinga2/pki/${HOSTNAME}.csr --cert /etc/icinga2/pki/${HOSTNAME}.crt
icinga2 pki sign-csr --csr /etc/icinga2/pki/${HOSTNAME}.csr --cert /etc/icinga2/pki/${HOSTNAME}.crt # typo fixed :)
cp -vR --preserve=all /var/lib/icinga2/ca/ca.crt /etc/icinga2/pki
cat >/etc/icinga2/zones.conf << EOFZONECONF
/**
* Generated by $0.
*/
object Endpoint "${HOSTNAME}" {
}
object Zone "master" {
//this is the local node master named = "master"
endpoints = [ "${HOSTNAME}" ]
}
EOFZONECONF
icinga2 feature enable api
# The next three lines modify the NodeName and TicketSalt assignments
sed -i "s/\/\/const NodeName.*/const NodeName = \"${HOSTNAME}\"/" /etc/icinga2/constants.conf
SALT=`cat /dev/urandom | tr -dc 'a-z0-9' | fold -w 16 | head -n 1`
sed -i "s/const TicketSalt.*/const TicketSalt = \"${SALT}\"/" /etc/icinga2/constants.conf
service icinga2 restart