编译安装naigos
1.#编译安装apache与nagios必要依赖包
yum -y install gcc glibc glibc-common gcc-c++ gd gd-devel openssl openssl-devel libxml2 libxml2-devel sqlite-devel
2.#创建配置apache,nagios用户与nagios组,添加附属组及用户;
groupadd -r nagios && groupadd -r nagcmd && groupadd -r apache
useradd nagios -g nagios -s /sbin/nologin && useradd apache -g apache -s /sbin/nologin
usermod -a -G nagcmd nagios && usermod -a -G nagcmd apache
3.配置解压apr/apr-uint/httpd/nagios/nagios-plugins/pcre
tar -xf apr-1.7.0.tar.gz ;tar -xf apr-util-1.6.1.tar.gz ;tar -xf httpd-2.4.41.tar.gz \
tar -xf php-7.4.4.tar.gz ; tar -xf nagios-plugins-2.3.3.tar.gz; tar -xf pcre-8.33.tar.gz
4.编译安装apache,nagios,顺序apr==>apr-uint==>pcre==>httpd==>nagios==>nagios-plugins
- step1.编译apr,注释掉 R M " RM " RM"cfgfile",避免发生未知错误
cd apr-1.7.0
sed -i 's/$RM "$cfgfile"/# $RM "$cfgfile"/g' ./configure
./configure --prefix=/usr/local/apr
make && make install
- step2.编译安装apr-uint,关联apr
cd apr-util-1.6.1
./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr/bin/apr-1-config
make && make install
- step3.编译安装pcre
cd pcre-8.33/
./configure --prefix=/usr/local/pcre
make && make install
- step4.编译安装httpd,指定apr,apr-util,pcre
cd httpd-2.4.41/
./configure --prefix=/usr/local/apache2 --with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util --with-pcre=/usr/local/pcre
make && make install
- step5.编译安装php-7.4.4
cd php-7.4.4/
./configure --prefix=/usr/local/php --with-apxs2=/usr/local/apache2/bin/apxs
make && make install
- step6.编译安装nagios,配置httpd.conf文件
cd nagios-4.3.2/
./configure --with-command-group=nagcmd
make all
make install
make install-init
make install-config
make install-commandmode
#实例配置httpd.conf配置脚本复制到extra文件
cp sample-config/httpd.conf /usr/local/apache2/conf/extra/httpd-nagios.conf
/usr/local/apache2/bin/htpasswd -bc /usr/local/nagios/etc/htpasswd.users nagiosadmin admin@123
- step7.编译安装nagios-plugins
cd nagios-plugins-2.3.3/
./configure --with-nagios-user=nagios --with-nagios-group=nagios
make && make install
5.修改apache,nagios配置文件 创建config.sh
touch apache-nagios.sh && chmod +x apache-nagios.sh
vim apache-nagios.sh
#!/bin/bash
#定义变量关联配置文件
conf=/usr/local/apache2/conf/httpd.conf
#1开启apache cgi模块,解决点击页面下载cgi情况
sed -i "s/^#LoadModule cgid_module/LoadModule cgid_module/g" $conf
#2.开启apache php模块,解决403禁止访问问题
sed -i "s/DirectoryIndex index.html/& index.php/g" $conf
sed -i "/application\/x-gzip/aAddType application\/x-httpd-php .php" $conf
#3.添加apache nagios配置文件
echo "# naigos httpd config" >> $conf
echo "Include conf/extra/httpd-nagios.conf" >> $conf
#4.设置apache 运行用户和组为apache"
sed -i "s/^User.*$/User apache/g" $conf
sed -i "s/^Group.*$/Group apache/g" $conf
#5.配置添加apache到自定义环境变量my.sh(自己定义的)中,重新加载;
echo 'export PATH=/usr/local/apache2/bin:$PATH' >> /etc/profile.d/my.sh
source /etc/profile.d/my.sh