Linux 安装配置 icinga2
前些天用 ArchLinux 安装 icinga2,一直装不上。后来用 Ubuntu 试了一下,装上了但是中间过程也很烦人,特此记录一下。
至于 Arch 为什么没装上,是因为我正好赶上了“好时候”,icingaweb2 依赖 PHP7,但是正好 PHP8 已经发布了,所以 Arch 上的 PHP 默认版本是 8,而 PHP7 是一个单独的包,就叫 PHP7,所以就没办法咯。后来我在用户自己的 bin
目录下面创建一个 php->/bin/php7
软链接,算是解决了大问题,但是因为 Arch 上配置还是有所不同,就没尝试装了,欢迎在 Arch 上装好的同学分享一下经验~
安装 Icinga2
按照官网上的步骤来就好
apt-get update
apt-get -y install apt-transport-https wget gnupg
wget -O - https://packages.icinga.com/icinga.key | apt-key add -
. /etc/os-release; if [ ! -z ${UBUNTU_CODENAME+x} ]; then DIST="${UBUNTU_CODENAME}"; else DIST="$(lsb_release -c| awk '{print $2}')"; fi; \
echo "deb https://packages.icinga.com/ubuntu icinga-${DIST} main" > \
/etc/apt/sources.list.d/${DIST}-icinga.list
echo "deb-src https://packages.icinga.com/ubuntu icinga-${DIST} main" >> \
/etc/apt/sources.list.d/${DIST}-icinga.list
apt-get update
apt-get install icinga2
apt-get install monitoring-plugins
安装完后查看 icinga2 的运行情况,也可以设置开机自启动
systemctl status icinga2
systemctl enable icinga2
依赖软件安装
需要先安装 mysql, php, apache 等软件
apt-get install mysql-server mysql-client
mysql_secure_installation
apt-get install apache2
apt-get install apache2 php7.3 php7.3-common php7.3-gd php7.3-ldap php7.3-intl php7.3-curl libapache2-mod-php7.3 php7.3-mysql php7.3-pgsql php7.3-xml
需要设置一下 php,配置文件在
/etc/php/7.3/apache2/php.ini
,不同版本位置不同,记得调整。date.timezone = Asia/Singapore
cgi.fix_pathinfo=0
最后依旧看看各个服务的运行情况,设置开机自启动。
systemctl restart apache2
systemctl enable apache2
systemctl status apache2
密码配置 1
1. 首先安装 icinga2-ido-mysql
,这里需要密码,这里设定为 password1。最后一步选 ignore,不太清楚其它选项可不可以。
2. 然后需要在 mysql 中添加一个数据库 icinga2,并且让赋权给用户 icinga2。
CREATE DATABASE icinga2;
GRANT SELECT, INSERT, UPDATE, DELETE, DROP, CREATE VIEW, INDEX, EXECUTE ON icinga2.* TO 'icinga2'@'localhost';
quit
3. 执行下面命令,来配置和启动 icinga2 的 IDO MYSQL module。
mysql -u root -p icinga2 < /usr/share/icinga2-ido-mysql/schema/mysql.sql
icinga2 feature enable ido-mysql
密码配置 2
1. 设置 icinga2 的 RESET API
icinga2 api setup
2. 增加 icingaweb2 用户访问 API 的权限,文件位置为 /etc/icinga2/conf.d/api-users.conf
,这里的密码设置为 password2。
object ApiUser "icingaweb2" {
password = "password2"
permissions = [ "status/query", "actions/*", "objects/modify/*", "objects/query/*" ]
}
安装 icingaweb2
apt install icingaweb2 icingacli
安装后生成一个 token,比如我的为: The newly generated setup token is: 9b871ead0a60c94f。
# 生产 token
icingacli setup token create
# 查看 token
icingacli setup token create
密码配置 3
1. 在 mysql 中添加一个数据库,并且权限赋给用户 icingaweb2,这里密码设为 password3
create database icingaweb2;
create user icingaweb2@localhost identified with mysql_native_password by "password3";
grant all privileges on icingaweb2.* to icingaweb2@localhost with grant option;
flush privileges;
登录 icingaweb2 界面
常见问题
1. ssh connection to localhost refused
这是因为没有安装 ssh... 直接 apt-get install ssh
,然后 systemctl status sshd
查看情况,可以设置开机自启动
参考资料
1. https://www.howtoforge.com/how-to-install-icinga-2-monitoring-on-ubuntu-20-04/
1. https://icinga.com/docs/icinga-2/latest/doc/02-installation/#webserver
1. https://icinga.com/docs/icinga-web-2/latest/doc/02-Installation/#installation