设为首页 收藏本站
查看: 991|回复: 0

nagios+LAMP自动安装脚本

[复制链接]

尚未签到

发表于 2015-8-19 11:22:12 | 显示全部楼层 |阅读模式
  #!/bin/sh
# Nagios V3.03 install script
# Write by zhengyp
#Date:2008-10-8

# Softwares are all store in /usr/local/src
cd /usr/local/src
#Install LAMP for Nagios
# Step 1. Install Apache
tar zxvf httpd-2.2.9.tar.gz
cd httpd-2.2.9
./configure --prefix=/usr/local/apache --enable-so --enable-mods-shared=all
make && make install
#Configure the apache server for PHP
sed -i 's#DirectoryIndex index.html#& index.php#' /usr/local/apache/conf/http.conf
sed -i '/AddType application\/x-gzip .gz .tgz/i\AddType application/x-httpd-php .php\
AddType application/x-httpd-php-source .phps' /usr/local/apache/conf/http.conf
#Step 2. Install Mysql As a server
#Add a mysql user
/usr/sbin/groupadd mysql
/usr/sbin/useradd -g mysql mysql
cd ..
tar zxvf mysql-5.1.26-rc.tar.gz
cd mysql-5.1.26-rc/
./configure --prefix=/usr/local/mysql/ --without-debug --with-unix-socket-path=/usr/local/mysql/mysql.sock --with-client-ldflags=-all-static --with-mysqld-ldflags=-all-static --enable-assembler --with-extra-charsets=gbk,gb2312,utf8 --with-pthread --enable-thread-safe-client
make && make install
chmod +w /usr/local/mysql
chown -R mysql:mysql /usr/local/mysql
cp support-files/my-medium.cnf /usr/local/mysql/my.cnf
cd ../
#Initialize the database
#You can change the data directory by set "--datadir="
#mkdir /data
#chown -R mysql:mysql /data
/usr/local/mysql/bin/mysql_install_db --defaults-file=/usr/local/mysql/my.cnf --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data --user=mysql --pid-file=/usr/local/mysql/mysql.pid --skip-locking --port=3306 --socket=/tmp/mysql.sock
#Start Mysql
/bin/sh /usr/local/mysql/bin/mysqld_safe --defaults-file=/usr/local/mysql/my.cnf &
#Step 3. Install PHP
#If you use CentOS, Please run yum to check that the graphics library have installed.Also it will update for these softwares
#If you use Redhat , Install the graphics library by "rpm" command
cd ..
yum -y install gcc gcc-c++ autoconf libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel libpng libpng-devel libxml2 libxml2-devel zlib zlib-devel glibc glibc- devel glib2 glib2-devel bzip2 bzip2-devel ncurses ncurses-devel curl curl-devel
tar zxvf php-5.2.6.tar.gz
cd php-5.2.6
./configure --prefix=/usr/local/php5 --with-mysql=/usr/local/mysql --with-mysqli=/usr/local/mysql/bin/mysql_config --with-iconv-dir=/usr/local --with-apxs2=/usr/local/apache/bin/apxs --with-freetype --with-jpeg --with-png --with-zlib --with-libxml-dir=/usr --enable-xml --disable-rpath --with-curl --with-curlwrappers --with-gd --enable-gd-native-ttf --with-openssl
make && make install
cd ..
#Step 4.Install Nagios 3.03
#Add nagios user
adduser nagios
mkdir /usr/local/nagios
chown nagios:nagios /usr/local/nagios
groupadd nagcmd
usermod -G nagcmd nagios
tar zxvf nagios-3.0.3.tar.gz
cd nagios-3.0.3
sed -i 's#wav#x-mplayer2#' cgi/status.c
#Configure and make
./configure --prefix=/usr/local/nagios --with-command-group=nagcmd --with-httpd-conf=/usr/local/apache/conf/httpd.conf --with-gd
make all
make install
make install-init
make install-config
make install-commandmode
#Add a user for nagios ,You can change the passwd for the user you add
/usr/local/apache/bin/htpasswd -c /usr/local/nagios/etc/htpasswd nagios <<EOF
123
123
EOF
sed -i '/AddType application\/x-gzip .gz .tgz/i\AddType application/x-httpd-php .php\
AddType application/x-httpd-php-source .phps' /usr/local/apache/conf/http.conf
sed -i '/<\/IfModule>/a\Alias /nagios/cgi-bin/images/ "/usr/local/nagios/share/images/"\
<Directory "/usr/local/nagios/share/images/">\
    AllowOverride None\
    Options None\
    Order allow,deny\
    Allow from all\
    AuthType Basic\
    AuthName "Login User"\
    AuthUserFile /usr/local/nagios/etc/htpasswd\
    require user nagios\
</Directory>\
ScriptAlias /nagios/cgi-bin/ "/usr/local/nagios/sbin/"\
<Directory "/usr/local/nagios/sbin/">\
AllowOverride None\
    Options None\
    Order allow,deny\
    Allow from all\
    AuthType Basic\
    AuthName "Login User"\
    AuthUserFile /usr/local/nagios/etc/htpasswd\
    require user nagios\
</Directory>\
Alias /nagios/ "/usr/local/nagios/share/"\
<Directory "/usr/local/nagios/share/">\
    AllowOverride None\
    Options None\
    Order allow,deny\
    Allow from all\
    AuthType Basic\
    AuthName "Login User"\
    AuthUserFile /usr/local/nagios/etc/htpasswd\
    require user nagios\
</Directory>' /usr/local/apache/conf/http.conf
sed -i 's#ServerName www.temple.com:80#ServerName 127.0.0.1#' /usr/local/apache/conf/http.conf
/usr/local/apache/bin/apachectl start
#Step 5. Install Naigos plugins
#Install plugins
cd /usr/local/src
tar xvzf nagios-plugins-1.4.12.tar.gz
cd nagios-plugins-1.4.11
./configure --prefix=/usr/local/nagios --with-nagios-user=nagios --with-nagios-group=nagios --enable-redhat-pthread-workaround --with-nagios-user=nagios --with-mysql=/usr/local/mysql
make && make install
# Install nrpe
cd /usr/local/src
tar zxvf nrpe-2.12.tar.gz
cd nrpe-2.12
./configure --enable-ssl --with-ssl-lib=/usr/local/nagios/openssl/lib --with-kerberos-inc=/usr/local/nagios/openssl/include --enable-command-args
make;make install
make install-plugin
make install-daemon
make install-daemon-config
chown nagios:nagios /usr/local/nagios/etc/nrpe.cfg
sed 's#dont_blame_nrpe=0#dont_blame_nrpe=1#' /usr/local/nagios/etc/nrpe.cfg
#Add nrpe to service
echo "nrpe 5666/tcp # NRPE" >>/etc/service
echo " " > /etc/xinetd.d/nrpe
sed -i '/ /i\service nrpe\
{\
disable     =   no\
flags       =   REUSE\
socket_type =   stream\
wait        =   no\
user        =   nagios\
server      =   /usr/local/nagios/bin/nrpe\
server_args =   -c /usr/local/nagios/etc/nrpe.cfg --inetd\
log_on_failure += USERID\
only_from = 192.168.0.200 #nagiosServer IP\
}' /etc/xinetd.d/nrpe
#Step 6. Configure Naigos
#Add the user who you've create in step 4 by htpasswd for nagios
cd /usr/local/nagios/etc
sed -i 's#default_user_name=guest#default_user_name=nagios' cgi.cfg
sed -i 's#=nagiosadmin#=nagiosadmin,nagios' cgi.cfg
#Start nagios
/usr/local/nagios/bin/nagios -d /usr/local/nagios/etc/nagios.cfg
service nagios start
#Step 7 . Set all servers start after system boot
echo "/usr/local/nagios/bin/nagios -d /usr/local/nagios/etc/nagios.cfg" >> /etc/rc.local
echo "service nagios start" >> /etc/rc.local
echo "/bin/sh /usr/local/mysql/bin/mysqld_safe --defaults-file=/usr/local/mysql/my.cnf &" >> /etc/rc.local
echo "/usr/local/apache/bin/apache/bin/apachectl start" >> /etc/rc.local

运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-101078-1-1.html 上篇帖子: LAMP学习笔记 下篇帖子: Ubuntu14.04搭建LAMP环境
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表