源碼包:
創(chuàng)新互聯(lián)從2013年成立,是專業(yè)互聯(lián)網(wǎng)技術(shù)服務(wù)公司,擁有項(xiàng)目網(wǎng)站建設(shè)、成都做網(wǎng)站網(wǎng)站策劃,項(xiàng)目實(shí)施與項(xiàng)目整合能力。我們以讓每一個(gè)夢(mèng)想脫穎而出為使命,1280元靈璧做網(wǎng)站,已為上家服務(wù),為靈璧各地企業(yè)和個(gè)人服務(wù),聯(lián)系電話:18980820575
httpd-2.2.24.tar.gz
php-5.2.17.tar.gzcd
MySQL-5.1.73-linux-x86_64-glibc23.tar.gz
其余依賴程序均通過(guò)yum源來(lái)安裝,推薦EPEL和CentOS
163鏡像
http://mirrors.163.com/
http://mirror.centos.org/
epel鏡像
http://mirrors.fedoraproject.org
操作步驟:
mysql安裝:
tar zxf mysql-5.1.73-linux-x86_64-glibc23.tar.gz -C /usr/local/
mv mysql-5.1.73-linux-x86_64-glibc23/ mysql
chown -R mysql.root mysql/ # 修改mysql目錄的權(quán)限
chown -R mysql. mysql/data/ # 修改mysql數(shù)據(jù)目錄的權(quán)限
初始化mysql
./scripts/mysql_install_db --basedir=/usr/local/mysql \ --datadir=/usr/local/mysql/data \ --defaults-file=/usr/local/mysql/my.cnf \ --skip-name-resolve --user=mysql
拷貝自啟動(dòng)腳本:
cp mysql.server /etc/init.d/mysqld
修改啟動(dòng)腳本中的內(nèi)容,明確告訴啟動(dòng)腳本mysql的運(yùn)行路徑
basedir=/usr/local/mysql #46行
datadir=/usr/local/mysql/data #47行
pid_file=/usr/local/mysql/mysql_v51.pid #59行
conf=/usr/local/mysql/my.cnf #218行
my.cnf配置文件主要部分
[mysqld] port = 3306 socket = /usr/local/mysql/mysql.sock skip-external-locking key_buffer_size = 16M max_allowed_packet = 1M table_open_cache = 64 sort_buffer_size = 512K net_buffer_length = 8K read_buffer_size = 256K read_rnd_buffer_size = 512K myisam_sort_buffer_size = 8M
/etc/init.d/mysqld start
Starting MySQL.[ OK ]
源碼編譯安裝http:
先安裝apr-1.5.1,編譯安裝時(shí)指定:
./configure --prefix=/usr/local/apr --disable-ipv6 LDFLAGS=-L/usr/lib64
apr-util-1.5.3,編譯安裝時(shí)指定:
./configure --prefix=/usr/local/apr \ --with-apr=/usr/local/apr/bin/apr-1-config \ --with-mysql=/usr/local/mysql \ LDFLAGS=-L/usr/lib64
編譯安裝apache
./configure --prefix=/usr/local/apache2 \- -enable-so \ --enable-modules=all \ --enable-mods-shared=all \- -with-mpm=worker --with-apr=/usr/local/apr/bin/apr-1-config \ --with-apr-util=/usr/local/apr/bin/apu-1-config \ --with-pcre \ --enable-disk-cache \ --enable-mem-cache \ --enable-file-cache \ --enable-cache \ --enable-cgi \ --enable-authn-alias \ --enable-proxy \ --enable-proxy-ftp \ --enable-proxy-http \ --enable-proxy-scgi \ --enable-proxy-connect \ --enable-proxy-balancer \ --enable-suexec \ LDFLAGS=-L/usr/lib64
make && make install
chown -R apache.root apache2/
http配置主要部分:篇幅問(wèn)題無(wú)法寫全
ServerRoot "/usr/local/apache2"
Listen 8085
ServerName 10.28.7.127:8085
DocumentRoot "/usr/local/apache2/htdocs"
DirectoryIndex index.html index.php
編譯安裝php:
編譯參數(shù)參照yum源安裝的PHP包時(shí)使用的選項(xiàng)
./configure --build=x86_64-redhat-linux-gnu \ --host=x86_64-redhat-linux-gnu \ --target=x86_64-redhat-linux-gnu \ --prefix=/usr/local/php \ --with-libdir=lib64 \ --with-config-file-path=/usr/local/php/etc \ --with-apxs2=/usr/local/apache2/bin/apxs \ --disable-debug \ --with-pic \ --disable-rpath \ --with-bz2 \ --with-exec-dir=/usr/bin \ --with-freetype-dir=/usr \ --with-png-dir=/usr \ --with-xpm-dir=/usr \ --enable-gd-native-ttf \ --without-gdbm \ --with-gettext \ --with-gmp \ --with-iconv \ --with-jpeg-dir=/usr \ --with-openssl \ --with-pcre-regex=/usr \ --with-zlib \ --with-layout=GNU \ --enable-exif \ --enable-ftp \ --enable-magic-quotes \ --enable-sockets \ --enable-sysvsem \ --enable-sysvshm \ --enable-sysvmsg \ --with-kerberos \ --enable-ucd-snmp-hack \ --enable-shmop \ --enable-calendar \ --without-sqlite \ --with-libxml-dir=/usr \ --enable-xml \ --enable-force-cgi-redirect \ --enable-pcntl \ --with-imap=shared \ --with-imap-ssl \ --enable-mbstring=shared \ --enable-mbregex \ --with-gd=shared \ --enable-bcmath=shared \ --enable-dba=shared \ --with-db4=/usr \ --with-xmlrpc=shared \ --with-ldap=shared \ --with-ldap-sasl \ --with-mysql=shared,/usr/local/mysql \ --with-mysqli=shared,/usr/local/mysql/bin/mysql_config \ --enable-dom=shared \ --enable-wddx=shared \ --with-snmp=shared,/usr \ --enable-soap=shared \ --with-xsl=shared,/usr \ --enable-xmlreader=shared \ --enable-xmlwriter=shared \ --with-curl=shared,/usr \ --enable-fastcgi \ --enable-pdo=shared \ --with-pdo-odbc=shared,unixODBC,/usr \ --with-pdo-mysql=shared,/usr/local/mysql/bin/mysql_config \ --with-pdo-sqlite=shared,/usr \ --enable-json=shared \ --enable-zip=shared \ --without-readline \ --enable-sysvmsg=shared \ --enable-sysvshm=shared \ --enable-sysvsem=shared \ --enable-posix=shared \ --with-unixODBC=shared,/usr \ --with-mysql-sock=/usr/local/mysql/mysql.sock \ --with-iconv-dir
make的時(shí)候加上ZEND_EXTRA_LIBS防止過(guò)程中報(bào)錯(cuò)
make ZEND_EXTRA_LIBS='-liconv'
php配置:
extension_dir = "/usr/local/php/lib/php/20060613-zts/"
extension=pdo_mysql.so # 此處為范例,多個(gè)模塊需要添加多個(gè)extension
date.timezone = Asia/Shanghai
LAMP環(huán)境完成后,檢查php加載狀況,在/usr/local/apache2/htdocs/下創(chuàng)建index.php文件語(yǔ)法:
phpinfo();
?>
通過(guò)訪問(wèn)http://domainname//index.php訪問(wèn)可以發(fā)現(xiàn)php插件是否正常加載
Apache : cat /usr/local/apache2/build/config.nice #查看編譯參數(shù)
apachectl -t -D DUMP_MODULES #查看加載模塊
MySQL: grep configure /usr/local/mysql/bin/mysqlbug #查看mysql編譯參數(shù)
PHP: /usr/local/php/bin/php -i |grep configure #查看PHP編譯參數(shù)
為了方便調(diào)用命令把Apache、Mysql、PHP 三個(gè)軟件的執(zhí)行文件路徑寫入環(huán)境變量~/.bash_profile
PATH=$PATH:$HOME/bin:/usr/local/mysql/bin:/usr/local/apache/bin:/usr/local/php/bin
LD_LIBRARY_PATH=/lib:/lib64:/usr/lib:/usr/lib64:/usr/local/mysql/lib:/usr/local/lib:/usr/local/lib64 #64位環(huán)境下添加該環(huán)境變量,方便編譯安裝時(shí)查看庫(kù)文件。
source ~/.bash_profile 使當(dāng)前環(huán)境變量生效
CACTI搭建:
搭建前先通過(guò)YUM安裝net-snmp,net-snmp-libs,net-snmp-utils,net-snmp-devel,elfutils-libelf-devel-static,elfutils-devel,lm_sensors-devel,lm_sensors,beecrypt-devel包,Cacti主要依賴snmp協(xié)議獲取備監(jiān)控主機(jī)的信息。
Cacti下載地址:http://www.cacti.net/downloads/
tar zxf cacti-0.8.8b.tar.gz
mv cacti-0.8.8b /usr/local/apache2/htdocs/cacti
mysql -u root -p mysql> create database cactidb; mysql> grant all privileges on cactidb.* to 'cacti'@'10.0.0.127' identified by 'cacti' with grant option; mysql> flush privileges; mysql> use cactidb mysql> source /usr/local/apache2/htdocs/cacti/cacti.sql #導(dǎo)入cacti表結(jié)構(gòu)
修改cacti配置文件
include/config.php include/global.php $database_type = "mysql"; $database_default = "cacti"; $database_hostname = "10.0.0.127"; $database_username = "cacti"; $database_password = "cacti"; $database_port = "3306"; $database_ssl = false; $url_path = "/cacti/"; chmod -R 775 rra/ log/ scripts/ #修改cacti目錄中的文件執(zhí)行權(quán)限
http://10.0.0.127:8085/cti/install/index.php 通過(guò)頁(yè)面安裝cacti
配置時(shí)注意執(zhí)行命令路徑是否被找到,如路徑不對(duì)后續(xù)也可以再設(shè)置。
安裝部分插件:
thold-v0.5.0.tgz
monitor-v1.3-1.tgz
settings-v0.71-1.tgz
解壓后移至插件目錄下
mv settings monitor thold /usr/local/apache2/htdocs/cacti/plugins/
激活插件
安裝cacti-spine插件
cacti-spine-0.8.8b
./configure --with-mysql \ --with-snmp=/usr/include/net-snmp \ LDFLAGS=-L/usr/local/mysql/lib
編譯過(guò)程中遇到 Cannot find UCD-SNMP libraries(snmp)報(bào)錯(cuò),查看configure文件,里面把snmp庫(kù)路徑指向--with-snmp所指的路徑之后,而snmp默認(rèn)的庫(kù)安裝路徑是/usr/lib64,因此通過(guò)軟鏈方式解決:
ln -s /usr/lib64/libsnmp* /usr/include/net-snmp/lib64/
還有一類據(jù)說(shuō)是spine-0.8.7c文檔提供的編譯方式
[root@SH-021Y-DBAP cacti-spine-0.8.8b] aclocal
[root@SH-021Y-DBAP cacti-spine-0.8.8b] libtoolize
[root@SH-021Y-DBAP cacti-spine-0.8.8b] autoconf && autoheader && automake
這類編譯過(guò)程需要借助 autoconf,automake工具。直接從GNU上下載最近版本的就可以了。發(fā)現(xiàn)yum來(lái)的或者低版本的會(huì)遇到些問(wèn)題。
GNU軟件下載地址,另外GNU現(xiàn)在在募集免費(fèi)軟件基金。畢竟一直在使用,大家能支援的就支援點(diǎn)吧。
http://www.gnu.org/software
安裝完成后進(jìn)spine行配置
vi /usr/local/spine/etc/spine.conf DB_Host 10.x.x.127 DB_Database cactidb DB_User cacti DB_Pass cacti DB_Port 3306 DB_PreG 0
Cacti搭建完成以后,出現(xiàn)無(wú)法生成圖片的方式,觀察cacti.log正常執(zhí)行poller.php腳本生產(chǎn)數(shù)據(jù),查看
查看apache的error日志,一直出現(xiàn)如下報(bào)錯(cuò):
ERROR: opening '*.rrd': No such file or directory
很明顯是沒(méi)有在rra下創(chuàng)建文件圖片數(shù)據(jù)文件,但是rra的權(quán)限已經(jīng)給到777了啊,對(duì)于這類頭疼的問(wèn)題只能一點(diǎn)點(diǎn)的試
在數(shù)據(jù)源目錄下選擇一臺(tái)主機(jī),選擇其中一個(gè)數(shù)據(jù)模板內(nèi)容,打開(kāi)debug模式
看到那行rrdtool的命令,粘貼到主機(jī)上運(yùn)行,確認(rèn)錯(cuò)誤的原因。查看生產(chǎn)圖形數(shù)據(jù)的語(yǔ)句
檢查是否運(yùn)行正常!
插件的錯(cuò)誤訪問(wèn)http://forums.cacti.net網(wǎng)站尋找解決方式
安裝Nagios
下載地址:
http://sourceforge.jp/projects/sfnet_nagios/releases/
最新nagios-plugin地址:
http://www.nagios.org/download/plugins/
nrpe下載地址:
wget http://sourceforge.net/projects/nagios/files/nrpe-2.x/nrpe-2.9/nrpe-2.9.tar.gz
目前能獲取的最新版本:
nagios-4.0.8.tar.gz
nagios-plugins-2.0.3.tar.gz
nrpe-2.9.tar.gz
tar zxf nagios-4.0.8.tar.gz ./configure --with-nagios-user=nagios \ --with-nagios-group=nagios \ --with-command-user=nagios \ --with-command-group=nagios \ --with-httpd-conf=/usr/local/apache2/conf make all
make install - This installs the main program, CGIs, and HTML files make install-init - This installs the init script in /etc/rc.d/init.d make install-commandmode - This installs and configures permissions on the directory for holding the external command file make install-config - This installs *SAMPLE* config files in /usr/local/nagios/etc You'll have to modify these sample files before you can use Nagios. Read the HTML documentation for more info on doing this. Pay particular attention to the docs on object configuration files, as they determine what/how things get monitored! make install-webconf - This installs the Apache config file for the Nagios web interface make install-exfoliation - This installs the Exfoliation theme for the Nagios web interface make install-classicui - This installs the classic theme for the Nagios web interface
tar zxf nagios-plugins-2.0.3.tar.gz ./configure --with-nagios-user=nagios --with-nagios-group=root --enable-redhat-pthread-workaround make && make install
./configure --with-nrpe-user=nagios \ --with-nrpe-group=nagios \ --with-nagios-user=nagios \ --with-nagios-group=nagios \ --enable-command-args General Options: ------------------------- NRPE port: 5666 #默認(rèn)端口為5666 make all make install-plugin make install-daemon make install-daemon-config make install-xinetd
ScriptAlias /nagios/cgi-bin "/usr/local/nagios/sbin"Options ExecCGI AllowOverride None Order allow,deny Allow from all AuthName "Nagios Access" AuthType Basic AuthUserFile /usr/local/nagios/etc/htpasswd.users Require valid-user Alias /nagios "/usr/local/nagios/share"Options None AllowOverride None Order allow,deny Allow from all AuthName "Nagios Access" AuthType Basic AuthUserFile /usr/local/nagios/etc/htpasswd.users Require valid-user Alias /pub/p_w_picpaths "/usr/local/nagios/share/docs/p_w_picpaths"Options None AllowOverride None Order allow,deny Allow from all AuthName "Nagios Access" AuthType Basic AuthUserFile /usr/local/nagios/etc/htpasswd.users Require valid-user
在http的配置文件中添加上面的內(nèi)容后,通過(guò)http的秘鑰命令在nagios配置目錄中生產(chǎn)秘鑰文件。
htpasswd -c /usr/local/nagios/etc/htpasswd.users nagiosadmin
修改NRPE配置
vi /usr/local/nagios/etc/nrpe.cfg allowed_hosts=10.x.0.0/24 vi /etc/xinetd.d/nrpe service nrpe { flags = REUSE socket_type = stream port = 5666 wait = no user = nagios group = nagios server = /usr/local/nagios/bin/nrpe server_args = -c /usr/local/nagios/etc/nrpe.cfg --inetd log_on_failure += USERID disable = no only_from = 127.0.0.1 10.28.7.127 } vi /etc/services nrpe 5666/tcp # NRPE service xinetd restart netstat -anltp | grep 5666 /usr/local/nagios/libexec/check_nrpe -H 10.x.x.127 #測(cè)試 NRPE v2.15
在啟動(dòng)nagios之后發(fā)現(xiàn)部分監(jiān)控報(bào)警沒(méi)啟動(dòng),啟動(dòng)時(shí)發(fā)現(xiàn)如下報(bào)錯(cuò):
Error: Could not open command file '/usr/local/nagios/var/rw/nagios.cmd' for update!
在nagios.cfg中對(duì)該命令進(jìn)行解釋,參考了網(wǎng)上的解決方式,發(fā)現(xiàn)修改命令權(quán)限為777時(shí),無(wú)報(bào)錯(cuò),判斷一定是權(quán)限的問(wèn)題。但此方法僅臨時(shí)解決問(wèn)題,當(dāng)nagios重啟后,該命令重新創(chuàng)建,問(wèn)題依然存在??吹浇忉屩刑岬?nbsp;“It is also where the command CGI will write commands that are submitted by users”,覺(jué)得應(yīng)該是apache的用戶需要有對(duì)該文件具有寫的權(quán)限,因此修改apache的所屬可選組為nagios,問(wèn)題徹底解決。
usermod -G apache,nagios nagios
關(guān)于nagios的配置內(nèi)容,需要另開(kāi)篇詳述。這里就不在說(shuō)明
雙劍合璧Nagios+Cacti
Cacti通過(guò)npc(Nagios plugin for Cacti)插件將Nagios集成在一起。
wget http://prdownloads.sourceforge.net/sourceforge/nagios/ndoutils-2.0.0.tar.gz
tar xvf ndoutils-2.0.0.tar.gz ./configure --prefix=/usr/local/nagios \ --mandir=/usr/local/share/man \ --enable-mysql \ --disable-pgsql \ --with-ndo2db-user=nagios \ --with-ndo2db-group=nagios \ --with-mysql 這里需要特別注意的是,仔細(xì)觀察編譯內(nèi)容,當(dāng)出現(xiàn)如下情況時(shí)說(shuō)明mysql的庫(kù)文件沒(méi)有找到,雖然可以正常安裝該軟件,但啟動(dòng)時(shí)最終會(huì)導(dǎo)致"Support for the specified database server is either not yet supported, or was not found on your system."這樣的錯(cuò)誤信息: *** MySQL library could not be located... ************************** You chose to compile NDOutils with MySQL support, but I was unable to locate the MySQL library on your system. If the library is installed, use the --with-mysql-lib argument to specify the location of the MySQL library. installed, use the --with-mysql=DIR argument to specify the location of the MySQL library, We assume mysql_config is in DIR/dir NOTE: After you install the necessary libraries on your system: 1. Make sure /etc/ld.so.conf has an entry for the directory in which the MySQL libraries are installed. 2. Run 'ldconfig' to update the run-time linker options. 3. Run 'make devclean' in the NDBXT distribution to clean out any old references to your previous compile. 4. Rerun the configure script. TIP: Try the following.... ./configure --with-mysql=/usr/lib/mysql ******************************************************************** 如果出現(xiàn)如下報(bào)錯(cuò)信息: In file included from io.c:11: ../include/config.h:261:25: error: mysql/mysql.h: No such file or directory ../include/config.h:262:26: error: mysql/errmsg.h: No such file or directory 修改include/config.h中第261行的內(nèi)容去掉mysql/,這是因?yàn)樯a(chǎn)的編譯文件路徑指定錯(cuò)誤。 make && make install cd config cp ndo2db.cfg-sample /usr/local/nagios/etc/ndo2db.cfg cp ndomod.cfg-sample /usr/local/nagios/etc/ndomod.cfg vi /usr/local/nagios/etc/ndo2db.cfg socket_name=/usr/local/nagios/var/ndo.sock db_name=cactidb db_prefix=npc_ db_user=cacti db_pass=cacti debug_level=1 debug_file=/usr/local/nagios/var/ndo2db.debug vi /usr/local/nagios/etc/nagios.cfg broker_module=/usr/local/nagios/bin/ndomod.o config_file=/usr/local/nagios/etc/ndomod.cfg
到這步需要做個(gè)小改動(dòng),因?yàn)閚doutils的數(shù)據(jù)庫(kù)腳本中定義的表名為nagios_,而配置文件中定義為npc_,需要手動(dòng)改一下腳本nstalldb,upgradedb及mysql.sql的內(nèi)容將nagios替換為npc。替換的方式用vi在command模式下:
%s/nagios_/npc_/
除此之外還有perl的相關(guān)包也需要安裝,主要是DBI,Data::ShowTables,DBD::mysql,一般通過(guò)perl的CPAN項(xiàng)目(類似YUM)安裝。涉及的相關(guān)包如lynx,ncftp,ftp
cpan源地址使用 http://mirrors.163.com/cpan/
CPAN> o conf urllist push http://mirrors.163.com/cpan/ CPAN> o conf prerequisites_policy follow CPAN> o conf commit CPAN> install DBD::mysql
一切就緒后運(yùn)行ndoutil的升級(jí)庫(kù)腳本:
cd ndoutils-2.0.0/db ./installdb -u cacti -p cacti -h 10.x.x.127 -d cactidb #for a new installation ./upgradedb -u cacti -p cacti -h 10.x.x.127 -d cactidb #for an existing one
解壓NPC移置cacti的plugins目錄下修改cacti配置文件
vi /usr/local/apache/htdocs/cacti/include/plugins.php $plugins[] = 'npc'; #第30行,$plugins = array();下方添加該語(yǔ)句(目前看該步驟非必要)
一切就緒開(kāi)啟ndoutils服務(wù):
/usr/local/nagios/bin/ndo2db -c /usr/local/nagios/etc/ndo2db.cfg
查看一下nagios的日志記錄
tail -100 /usr/local/nagios/var/nagios.log ndomod: Successfully connected to data sink. 4160 queued items to flush. #出現(xiàn)如下提示表示ndo正常連接數(shù)據(jù)庫(kù),把nagios的數(shù)據(jù)寫入到cactidb庫(kù)中了。
Dec 13 00:55:37 021Y-SH-BKAP ndo2db: Error: max retries exceeded sending message to queue. Kernel queue parameters may neeed to be tuned. See README
ALTER TABLE `npc_hostchecks` MODIFY COLUMN `long_output` varchar(8192) NOT NULL default '' AFTER `output`; ALTER TABLE `npc_hoststatus` MODIFY COLUMN `long_output` varchar(8192) NOT NULL default '' AFTER `output`; ALTER TABLE `npc_servicechecks` MODIFY COLUMN `long_output` varchar(8192) NOT NULL default '' AFTER `output`; ALTER TABLE `npc_servicestatus` MODIFY COLUMN `long_output` varchar(8192) NOT NULL default '' AFTER `output`; ALTER TABLE `npc_statehistory` MODIFY COLUMN `long_output` varchar(8192) NOT NULL default '' AFTER `output`; ALTER TABLE `npc_eventhandlers` MODIFY COLUMN `long_output` varchar(8192) NOT NULL default '' AFTER `output`; ALTER TABLE `npc_systemcommands` MODIFY COLUMN `long_output` varchar(8192) NOT NULL default '' AFTER `output`; ALTER TABLE `npc_notifications` MODIFY COLUMN `long_output` varchar(8192) NOT NULL default '' AFTER `output`;
參考:
http://os.51cto.com/art/201411/458006_all.htm
http://blog.chinaunix.net/uid-24727220-id-3025015.html
http://yahoon.blog.51cto.com/13184/49722/