您好,登錄后才能下訂單哦!
源碼包:
httpd-2.2.24.tar.gz
php-5.2.17.tar.gzcd
mysql-5.1.73-linux-x86_64-glibc23.tar.gz
其余依賴程序均通過yum源來安裝,推薦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目錄的權限
chown -R mysql. mysql/data/ # 修改mysql數據目錄的權限
初始化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
拷貝自啟動腳本:
cp mysql.server /etc/init.d/mysqld
修改啟動腳本中的內容,明確告訴啟動腳本mysql的運行路徑
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,編譯安裝時指定:
./configure --prefix=/usr/local/apr --disable-ipv6 LDFLAGS=-L/usr/lib64
apr-util-1.5.3,編譯安裝時指定:
./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配置主要部分:篇幅問題無法寫全
ServerRoot "/usr/local/apache2"
Listen 8085
ServerName 10.28.7.127:8085
DocumentRoot "/usr/local/apache2/htdocs"
<IfModule dir_module>
DirectoryIndex index.html index.php
</IfModule>
編譯安裝php:
編譯參數參照yum源安裝的PHP包時使用的選項
./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的時候加上ZEND_EXTRA_LIBS防止過程中報錯
make ZEND_EXTRA_LIBS='-liconv'
php配置:
extension_dir = "/usr/local/php/lib/php/20060613-zts/"
extension=pdo_mysql.so # 此處為范例,多個模塊需要添加多個extension
date.timezone = Asia/Shanghai
LAMP環境完成后,檢查php加載狀況,在/usr/local/apache2/htdocs/下創建index.php文件語法:
<?php
phpinfo();
?>
通過訪問http://domainname//index.php訪問可以發現php插件是否正常加載
Apache : cat /usr/local/apache2/build/config.nice #查看編譯參數
apachectl -t -D DUMP_MODULES #查看加載模塊
MySQL: grep configure /usr/local/mysql/bin/mysqlbug #查看mysql編譯參數
PHP: /usr/local/php/bin/php -i |grep configure #查看PHP編譯參數
為了方便調用命令把Apache、Mysql、PHP 三個軟件的執行文件路徑寫入環境變量~/.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位環境下添加該環境變量,方便編譯安裝時查看庫文件。
source ~/.bash_profile 使當前環境變量生效
CACTI搭建:
搭建前先通過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協議獲取備監控主機的信息。
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 #導入cacti表結構
修改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目錄中的文件執行權限
http://10.0.0.127:8085/cti/install/index.php 通過頁面安裝cacti
配置時注意執行命令路徑是否被找到,如路徑不對后續也可以再設置。
安裝部分插件:
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
編譯過程中遇到 Cannot find UCD-SNMP libraries(snmp)報錯,查看configure文件,里面把snmp庫路徑指向--with-snmp所指的路徑之后,而snmp默認的庫安裝路徑是/usr/lib64,因此通過軟鏈方式解決:
ln -s /usr/lib64/libsnmp* /usr/include/net-snmp/lib64/
還有一類據說是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
這類編譯過程需要借助 autoconf,automake工具。直接從GNU上下載最近版本的就可以了。發現yum來的或者低版本的會遇到些問題。
GNU軟件下載地址,另外GNU現在在募集免費軟件基金。畢竟一直在使用,大家能支援的就支援點吧。
http://www.gnu.org/software
安裝完成后進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搭建完成以后,出現無法生成圖片的方式,觀察cacti.log正常執行poller.php腳本生產數據,查看
查看apache的error日志,一直出現如下報錯:
ERROR: opening '*.rrd': No such file or directory
很明顯是沒有在rra下創建文件圖片數據文件,但是rra的權限已經給到777了啊,對于這類頭疼的問題只能一點點的試
在數據源目錄下選擇一臺主機,選擇其中一個數據模板內容,打開debug模式
看到那行rrdtool的命令,粘貼到主機上運行,確認錯誤的原因。查看生產圖形數據的語句
檢查是否運行正常!
插件的錯誤訪問http://forums.cacti.net網站尋找解決方式
安裝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 #默認端口為5666 make all make install-plugin make install-daemon make install-daemon-config make install-xinetd
ScriptAlias /nagios/cgi-bin "/usr/local/nagios/sbin" <Directory "/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 </Directory> Alias /nagios "/usr/local/nagios/share" <Directory "/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 </Directory> Alias /pub/p_w_picpaths "/usr/local/nagios/share/docs/p_w_picpaths" <Directory "/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 </Directory>
在http的配置文件中添加上面的內容后,通過http的秘鑰命令在nagios配置目錄中生產秘鑰文件。
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 #測試 NRPE v2.15
在啟動nagios之后發現部分監控報警沒啟動,啟動時發現如下報錯:
Error: Could not open command file '/usr/local/nagios/var/rw/nagios.cmd' for update!
在nagios.cfg中對該命令進行解釋,參考了網上的解決方式,發現修改命令權限為777時,無報錯,判斷一定是權限的問題。但此方法僅臨時解決問題,當nagios重啟后,該命令重新創建,問題依然存在。看到解釋中提到 “It is also where the command CGI will write commands that are submitted by users”,覺得應該是apache的用戶需要有對該文件具有寫的權限,因此修改apache的所屬可選組為nagios,問題徹底解決。
usermod -G apache,nagios nagios
關于nagios的配置內容,需要另開篇詳述。這里就不在說明
雙劍合璧Nagios+Cacti
Cacti通過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 這里需要特別注意的是,仔細觀察編譯內容,當出現如下情況時說明mysql的庫文件沒有找到,雖然可以正常安裝該軟件,但啟動時最終會導致"Support for the specified database server is either not yet supported, or was not found on your system."這樣的錯誤信息: *** 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 ******************************************************************** 如果出現如下報錯信息: 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行的內容去掉mysql/,這是因為生產的編譯文件路徑指定錯誤。 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
到這步需要做個小改動,因為ndoutils的數據庫腳本中定義的表名為nagios_,而配置文件中定義為npc_,需要手動改一下腳本nstalldb,upgradedb及mysql.sql的內容將nagios替換為npc。替換的方式用vi在command模式下:
%s/nagios_/npc_/
除此之外還有perl的相關包也需要安裝,主要是DBI,Data::ShowTables,DBD::mysql,一般通過perl的CPAN項目(類似YUM)安裝。涉及的相關包如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
一切就緒后運行ndoutil的升級庫腳本:
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();下方添加該語句(目前看該步驟非必要)
一切就緒開啟ndoutils服務:
/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. #出現如下提示表示ndo正常連接數據庫,把nagios的數據寫入到cactidb庫中了。
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/
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。