環境:lamp
系統:centos 6
前提:編譯安裝軟體需要安裝開發環境,關閉iptables和selinux
# yum groupinstall "Development Tools" "Server Platform Development"
一、編譯安裝httpd
httpd2.4需要apr、apr-util依賴包
1.編譯安裝apr、apr-util
# tar xf apr-1.5.0.tar.bz2
# cd apr-1.5.0
# ./configure --prefix=/usr/local/apr
# make && make install
# tar xf apr-util-1.5.3.tar.bz2
# cd apr-util-1.5.3
# ./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr
# make && make install
2.編譯安裝httpd
在安裝之前需要安裝pcre-devel包,因為在編譯安裝http時會安裝pcre,這個包依賴于pcre-devel,系統自帶沒有pcre-devel這個包
# yum install pcre-devel
# tar xf httpd-2.4.10.tar.bz2
# cd httpd-2.4.10
# ./configure --prefix=/usr/local/apache --sysconfdir=/etc/httpd24 --enable-so --enable-ssl --enable-cgi --enable-rewrite --with-zlib --with-pcre --with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util --enable-modules=most --enable-mpms-shared=all --with-mpm=event
# make && make install
3.啟動httpd服務
編譯安裝的httpd自帶有啟動腳本:apachectl,是以執行/usr/local/apache/bin/apachectl指令即可啟動httpd服務
直接使用apachectl指令需做一下步驟:
# vim /etc/profile.d/httpd.sh
# . /etc/profile.d/httpd.sh
# echo $PATH
# cat /etc/profile.d/httpd.sh
export PATH=/usr/local/apache/bin:$PATH
4.修改httpd的主配置檔案 vim /etc/httpd24/httpd.conf ,添加下行即可:
PidFile "/var/run/httpd.pid"
5.将之前的httpd sysv服務腳本拷貝過來并修改配置檔案中的以下資料:
cp /etc/rc.d/init.d/httpd /etc/rc.d/init.d/httpd24
# pidfile: /var/run/httpd.pid
apachectl=/usr/local/apache/bin/apachectl
httpd=${HTTPD-/usr/local/apache/bin/httpd}
pidfile=${PIDFILE-/var/run/httpd.pid}
給腳本執行權限:
# chmod +x /etc/rc.d/init.d/httpd24
6.加入服務清單并啟動服務:
# chkconfig --add httpd24
# chkconfig httpd24 on
# service httpd24 status
# service httpd24 start
二、編譯安裝mysql
1.建立一個lvm,然後将其挂載到資料庫目錄下:
# mkdir -pv /mydata/data
//此處省略lvm的建立和挂載
2.建立使用者以安全方式運作
# groupadd -r mysql
# useradd -g mysql -r -s /sbin/nologin -M -d /mydata/data mysql
# chown -R mysql:mysql /mydata/data
3.安裝并初始化mysql
# tar xf mariadb-5.5.43-linux-x86_64.tar.gz -C /usr/local
# cd /usr/local
# ln -sv mariadb-5.5.43-linux-x86_64 mysql
# cd mysql
# chown -R root:mysql ./*
# scripts/mysql_install_db --datadir=/mydata/data/ --user=mysql //初始化資料庫
4.為資料庫建立主配置檔案
# mkdir /etc/mysql
# cp support-files/my-large.cnf /etc/mysql/my.cnf
5.修改配置檔案:添加如下幾行,并修改此檔案中thread_concurrency的值為你的CPU個數乘以2
datadir = /mydata/data //資料存放目錄
innodb_file_per_table= on //每個innnodb表使用單個表檔案
skip_name_resolve = on //跳過主機名稱解析
6.在配置檔案中定義“pid-file”檔案路徑,否則啟動mysql會出現錯誤
vim /etc/my.cnf
pid-file=/mydata/data/mysql.pid
vim /etc/rc.d/init.d/mysqld
mysqld_pid_file_path=/mydata/data
7.為mysql提供sysv服務腳本,并添加至服務清單
# cp support-files/mysql.server /etc/rc.d/init.d/mysqld
# chmod +x /etc/rc.d/init.d/mysqld
# chkconfig --add mysqld
# service mysqld start
8.輸出mysql的man手冊至man指令中:
# vim /etc/man.config 添加下行即可:
MANPATH /usr/local/mysql/man
9.輸出mysql的頭檔案至系統檔案路徑/usr/include:
# ln -sv /usr/local/mysql/include /usr/include/mysql
10.輸出mysql的庫檔案給系統庫查找路徑:
# echo '/usr/local/mysql/lib' > /etc/ld.so.conf.d/mysql.conf
重新加載系統庫:
# ldconfig
11.修改PATH環境變量,讓系統可以直接使用mysql的相關指令:
vim /etc/profile.d/mysqld.sh
# export PATH=/usr/local/mysql/bin:$PATH
三、編譯安裝php
1.開始安裝php所需依賴環境:
# yum -y groupinstall "Desktop Platform Development"
# yum -y install bzip2-devel libmcrypt-devel libxml2-devel
// libmcrypt-devel 本地CD光牒沒有在epel源裡面。其他的是epel源.,編譯安裝libmcrypt
2.編譯安裝libmcrypt
# tar xf libmcrypt-2.5.7.tar.gz
# cd libmcrypt-2.5.7
# ./configure --prefix=/usr/local/libmcrypt
# make && make install
3.開始編譯安裝php:
# tar xf php-5.4.40.tar.bz2
# cd php-5.4.40
#./configure --prefix=/usr/local/php --with-mysql=/usr/local/mysql --with-openssl --with-mysqli=/usr/local/mysql/bin/mysql_config --enable-mbstring --with-freetype-dir --with-jpeg-dir --with-png-dir --with-zlib --with-libxml-dir=/usr --enable-xml --enable-sockets --with-apxs2=/usr/local/apache/bin/apxs --with-mcrypt --with-config-file-path=/etc --with-config-file-scan-dir=/etc/php.d --with-bz2 --enable-maintainer-zts --with-mcrypt=/usr/local/libmcrypt --with-gd --with-gettext --enable-bcmath
//msqli:對應mysql另外的一個接口 ,freetype:多種字型 libxml:處理xml的文檔 socket:支援socket apxs:支援http第三方子產品 zts:如果之前安裝過httpd且子產品是prefork則不需要,否則必須安裝上去
# make -j //啟用多線程安裝(由于php安裝比較耗時)
# make install
預設情況下http但是不支援php的,是以需要修改配置檔案:
# cp /etc/httpd24/httpd.conf /etc/httpd24/httpd.conf.bak
4.為php提供配置檔案:
# cp php.ini-production /etc/php.ini
5.編輯apache檔案使其支援php:
在檔案中添加入下行:
DirectoryIndex index.php index.html
AddType application/x-httpd-php .php
AddType application/x-httpd-php-source .phps
6.重置下httpd服務:
# /usr/local/apache/bin/apachectl reload
7.預設測試頁面在/usr/local/apache/htdocs,添加一個index.php測試檔案:
<?php
$link = mysql_connect('127.0.0.1','root',' ');
if ($link)
echo "Success...";
else
echo "Failure...";
phpinfo();
mysql_close();
?>
8.測試網頁http://hostloaclIP
四.編譯安裝zabbix
1.解壓zabbix包
# tar xf zabbix-2.4.7.tar.gz
2.建立使用者和使用者組
# groupadd zabbix
# useradd -g zabbix zabbix
3.Server和agent端編譯安裝
提前安裝好libcurl,否則會出錯,一般報錯都是因為沒有安裝所需要的包
# yum install libcurl*
# ./configure --enable-server --enable-agent --with-mysql --enable-ipv6 --with-libcurl --with-libxml2
出現問題:
configure: error: Not found mysqlclient library
解決辦法:
sudo yum install mysql-devel
configure: error: Curl library not found
解決辦法:
sudo yum install curl-devel
# make && make install
4.建立zabbix運作所需要的資料庫和使用者權限
shell> mysql -uroot -p<password>
mysql> CREATE DATABASE zabbix CHARACTER SET utf8 COLLATE utf8_bin;
mysql> GRANT ALL ON zabbix.* TO [email protected]'localhost' IDENTIFIED BY 'zabbix';
5.将zabbix的初始資料導入到資料庫中
# mysql -uzabbix -pzabbix zabbix < database/mysql/schema.sql
# mysql -uzabbix -pzabbix zabbix < database/mysql/p_w_picpaths.sql
# mysql -uzabbix -pzabbix zabbix < database/mysql/data.sql
//導入的順序跟目錄下的順序剛好相反
6.編輯zabiix-server配置檔案
# vim /usr/local/etc/zabbix/zabbix_server.conf
LogFile=/var/log/zabbix_server.log
LogFileSize=10 //日志大小限制
PidFile=/var/run/zabbix/zabbix_server.pid
DBHost=172.16.100.67
DBName=zabbix
DBUser=zbxuser
DBPassword=zbxpass
DBSocket=/var/lib/mysql/mysql.sock
SNMPTrapperFile=/var/log/snmptt/snmptt.log
AlertScriptsPath=/usr/lib/zabbix/alertscripts
ExternalScripts=/usr/lib/zabbix/externalscripts
7.編輯php.ini檔案并重新開機httpd24服務
# cp /etc/php.ini /etc/php.ini.bak
# vim /etc/php.ini
max_execution_time = 300
max_input_time = 300
post_max_size = 16M
date.timezone = Asia/Shanghai
# service httpd24 restart
8.設定時區
# ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
# yum install ntpdate //安裝ntpdate
ntpdate us.pool.ntp.org //同步時間
9.服務啟動與配置
cp提供的init.d啟動腳本到系統中去
$ sudo cp misc/init.d/fedora/core/* /etc/init.d/
編輯下啟動腳本以适應自己的安裝環境,由于預設沒有指定安裝目錄是以不用修改,如果指定安裝目錄的話則修改“BASEDIR=”即可
10.啟動server、agent服務
$ sudo /etc/init.d/zabbix_server start (或者zabbix_server)
$ sudo /etc/init.d/zabbix_agentd start (或者zabbix_agentd)
11.添加開機啟動服務
sudo chkconfig --add zabbix_server
sudo chkconfig zabbix_server on
sudo chkconfig --add zabbix_agentd
sudo chkconfig zabbix_agentd on
12.建立并授權zabbix日志目錄
$ sudo mkdir /var/log/zabbix
$ sudo chown zabbix:zabbix /var/log/zabbix
$ sudo chmod -R 775 /var/log/zabbix
13.檢查服務可用性
$ sudo service zabbix_server restart
$ sudo service zabbix_server status
[[email protected] etc]$ sudo service zabbix_server restart
Shutting down zabbix_server: [确定]
Starting zabbix_server: [确定]
[[email protected] etc]$ sudo service zabbix_server status
zabbix_server (pid 11831) 正在運作...
[[email protected] etc]$ sudo service zabbix_agentd status
zabbix_agentd (pid 11501 11500 11499 11498 11497 11495) 正在運作...
14.複制網頁到http網頁目錄下
$ cd frontends/php/
$ sudo cp -a . /usr/local/apache/htdocs/zabbix
$ sudo locale/make_mo.sh
15.打開zabbix web界面
http://hostlocalIP/zabbix

轉載于:https://blog.51cto.com/9480860/1736915