您好,登錄后才能下訂單哦!
怎樣進行LAMP源碼安裝以及如何搭建zabbix監控,相信很多沒有經驗的人對此束手無策,為此本文總結了問題出現的原因和解決方法,通過這篇文章希望你能解決這個問題。
1、系統環境檢查,版本說明
1)版本說明
#httpd-2.4.25
#mysql-5.7.17-linux-glibc2.5-x86_64 二進制壓縮版
#php5.6.30
#zabbix-3.0.8
2)關閉selinux、iptables,檢查系統版本信息
sed -i 's/SELINUX=enabled/SELINUX=disabled/g' /etc/selinux/config
getenforce 0
/etc/init.d/iptables stop
cat /etc/redhat-release
CentOS release 6.7 (Final)
uname -r
2.6.32-431.el6.x86_64
uname -m
x86_64
2、安裝apache
http://httpd.apache.org/download.cgi #apache官網
#新建apache運行用戶
useradd -s /sbin/nologin -M www
mkdir tools
cd tools#下載http代碼包
wget http://mirrors.tuna.tsinghua.edu.cn/apache//httpd/httpd-2.4.25.tar.gz
wget http://mirrors.cnnic.cn/apache//apr/apr-1.5.2.tar.gz
wget http://mirrors.cnnic.cn/apache//apr/apr-util-1.5.4.tar.gz
#附上aliyun下載地址
wget -c http://mirrors.aliyun.com/apache/apr/apr-1.5.2.tar.gz
wget -c http://mirrors.aliyun.com/apache/apr/apr-util-1.5.4.tar.gz
wget -c http://mirrors.aliyun.com/apache/httpd/httpd-2.4.25.tar.gz
#安裝插件apr和apr-util
#編譯安裝apr
tar xf apr-1.5.2.tar.gz
cd apr-1.5.2
./configure --prefix=/usr/local/apr-1.5.2
make && make install
echo $?
ln -s /usr/local/apr-1.5.2/ /usr/local/apr
cd ..
#編譯安裝apr-util
tar xf apr-util-1.5.4.tar.gz
cd apr-util-1.5.4
./configure --prefix=/usr/local/apr-util-1.5.4 --with-apr=/usr/local/apr-1.5.2/
echo $?
make && make install
echo $?
ln -s /usr/local/apr-util-1.5.4/ /usr/local/apr-util
cd ..#安裝功能包
yum install pcre-devel zlib-devel openssl-devel -y
#安裝apache
tar zxvf httpd-2.4.25.tar.gz
cd httpd-2.4.25./configure --prefix=/usr/local/httpd-2.4.25 \
--with-apr=/usr/local/apr-1.5.2 \
--with-apr-util=/usr/local/apr-util-1.5.4 \
--enable-so --enable-deflate --enable-expires \
--enable-headers --enable-ssl --enable-rewrite \
--enable-mpms-shared=all --with-mpm=prefork \
--enable-mods-shared=most
#編譯與安裝
make
make install
配置參數解釋:
#--prefix= apache安裝目錄。默認情況下,安裝目錄設置為 /usr/local/apache2。
#--sysconfdir= 指定配置文件安裝路徑
#--with-apr= 如果要使用已安裝的APR,則必須告訴腳本configure的apr的安裝路徑
#--with-apr-util 指定已安裝的apr-util的安裝路徑
#--enable-so 允許運行時加載DSO模塊
#--enable-cgi 啟用cgi協議
#--with-zlib 啟用zlib庫文件
#--with-pcre 指定pcre的安裝路徑
#--enable-modules=most 啟用大多數共享模塊
#--enable-deflate 壓縮傳輸編碼支持
#--enable-expires Expires頭控制
#--enable-headers HTTP頭控制
#--enable-ssl 啟動ssl加密功能,SSL/TLS支持(mod_ssl)
#--enable-rewrite 基于規則的URL操作,啟用URL重寫功能
#--enable-mpms-shared=all 空間分隔的MPM模塊列表啟用,動態加載
#--with-mpm=prefork 指定使用的MPM的類型, 選擇Apache使用的進程模型(event|worker|prefork|winnt)
#--enable-mods-shared=most 啟用MPM大多數參數, 定義要啟用并構建為動態共享模塊的模塊列表,默認設置為most(all|most|few|reallyall)
#去版本號,做鏈接
ln -s /usr/local/httpd-2.4.25/ /usr/local/httpd
#配置http環境變量
echo "export PATH=/usr/local/httpd/bin:$PATH" >>/etc/profile
. /etc/profile
#查看http模塊
ls /usr/local/httpd/modules
#查看安裝的模塊
/usr/local/httpd/bin/apachectl -l
/usr/local/httpd/bin/apachectl -M
apachectl -t -D DUMP_MODULES
#修改http配置文件
sed -i 's/#ServerName www.example.com:80/ServerName localhost:80/g' /usr/local/httpd/conf/httpd.conf
#啟動apache服務
apachectl start
#查看http服務
netstat -lntup|grep httpd
tcp 0 0 :::80 :::* LISTEN 56389/httpd
#配置啟動腳本
cp /usr/local/httpd/bin/apachectl /etc/init.d/httpd
chmod +x /etc/init.d/httpd
/etc/init.d/httpd stop
netstat -lntup|grep httpd
/etc/init.d/httpd start
netstat -lntup|grep httpd
vim /etc/init.d/httpd
#在開始位置添加:
# chkconfig: 345 85 15
# description: this my apache is httpd server
#加入系統啟動服務,開機自啟動
chkconfig --add httpd
chkconfig httpd on
chkconfig --list httpd
#測試訪問正常!到此apache安裝完成!
#一鍵式安裝apache 2.4.25
useradd -s /sbin/nologin -M wwwm kdir ~/tools cd ~/tools /bin/ping baidu.com -c 2[ $? -eq 0 ] && { wget wget wget } || exit 110 tar xf apr-1.5.2.tar.gz cd apr-1.5.2 ./configure --prefix=/usr/local/apr-1.5.2 make && make install echo $? [ $? -eq 0 ] && { ln -s /usr/local/apr-1.5.2/ /usr/local/apr cd .. } #編譯安裝apr-util tar xf apr-util-1.5.4.tar.gz cd apr-util-1.5.4 ./configure --prefix=/usr/local/apr-util-1.5.4 --with-apr=/usr/local/apr-1.5.2/ make && make install echo $? sleep 2 ln -s /usr/local/apr-util-1.5.4/ /usr/local/apr-util cd .. yum install pcre-devel zlib-devel openssl-devel -y tar zxvf httpd-2.4.25.tar.gz cd httpd-2.4.25 ./configure --prefix=/usr/local/httpd-2.4.25 \ --with-apr=/usr/local/apr-1.5.2 \ --with-apr-util=/usr/local/apr-util-1.5.4 \ --enable-so --enable-deflate --enable-expires \ --enable-headers --enable-ssl --enable-rewrite \ --enable-mpms-shared=all --with-mpm=prefork \ --enable-mods-shared=most echo $? sleep 2 make make install ln -s /usr/local/httpd-2.4.25/ /usr/local/httpd echo "export PATH=/usr/local/httpd/bin:$PATH" >>/etc/profile . /etc/profile sed -i 's/#ServerName www.example.com:80/ServerName localhost:80/g' /usr/local/httpd/conf/httpd.conf apachectl start netstat -lntup|grep 80 >/dev/null && echo OK!
3、MySQL安裝與配置,此處為二進制安裝
useradd -s /sbin/nologin -M mysql
wget https://cdn.mysql.com//Downloads/MySQL-5.7/mysql-5.7.17-linux-glibc2.5-x86_64.tar.gz
tar -zxvf mysql-5.7.17-linux-glibc2.5-x86_64.tar.gz
mv mysql-5.7.17-linux-glibc2.5-x86_64 /usr/local/mysql-5.7.17
ln -s /usr/local/mysql-5.7.17 /usr/local/mysql
#創建數據庫文件目錄
mkdir -p /data/mysql
chown -R mysql.mysql /data/
#配置啟動腳本文件,并加入系統服務,自啟動
cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld
chmod +x /etc/init.d/mysqld
chkconfig --add mysqld
chkconfig mysqld on
#配置mysql配置文件
cat > /etc/my.cnf << EOF [client] port = 3306 socket = /tmp/mysql.sock default-character-set = utf8 [mysqld] port = 3306 socket = /tmp/mysql.sock basedir = /usr/local/mysql datadir = /data/mysql pid-file = /data/mysql/mysql.pid user = mysql bind-address = 0.0.0.0 server-id = 1 init-connect = 'SET NAMES utf8' character-set-server = utf8 #skip-name-resolve #skip-networking back_log = 300 max_connections = 1000 max_connect_errors = 6000 open_files_limit = 65535 table_open_cache = 128 max_allowed_packet = 4M binlog_cache_size = 1M max_heap_table_size = 8M tmp_table_size = 16M read_buffer_size = 2M read_rnd_buffer_size = 8M sort_buffer_size = 8M join_buffer_size = 8M key_buffer_size = 4M thread_cache_size = 8 query_cache_type = 1 query_cache_size = 8M query_cache_limit = 2M ft_min_word_len = 4 log_bin = mysql-bin binlog_format = mixed expire_logs_days = 30 log_error = /data/mysql/mysql-error.log slow_query_log = 1 long_query_time = 1 slow_query_log_file = /data/mysql/mysql-slow.log performance_schema = 0 explicit_defaults_for_timestamp #lower_case_table_names = 1skip-external-locking default_storage_engine = InnoDB #default-storage-engine = MyISAM innodb_file_per_table = 1 innodb_open_files = 500 innodb_buffer_pool_size = 64M innodb_write_io_threads = 4 innodb_read_io_threads = 4 innodb_thread_concurrency = 0 innodb_purge_threads = 1 innodb_flush_log_at_trx_commit = 2 innodb_log_buffer_size = 2M innodb_log_file_size = 32M innodb_log_files_in_group = 3 innodb_max_dirty_pages_pct = 90 innodb_lock_wait_timeout = 120 bulk_insert_buffer_size = 8M myisam_sort_buffer_size = 8M myisam_max_sort_file_size = 10G myisam_repair_threads = 1 interactive_timeout = 28800 wait_timeout = 28800 [mysqldump] quick max_allowed_packet = 16M [myisamchk] key_buffer_size = 8M sort_buffer_size = 8M read_buffer = 4M write_buffer = 4M EOF
#初始化數據庫:
/usr/local/mysql/bin/mysqld --initialize-insecure --user=mysql --basedir=/usr/local/mysql --datadir=/data/mysql
#配合環境變量
echo "export PATH=$PATH:/usr/local/mysql/bin" >>/etc/profile
. /etc/profile
#啟動MySQL服務
/etc/init.d/mysqld start
Starting MySQL.. SUCCESS!
netstat -lntup|grep 3306
tcp 0 0 0.0.0.0:3306 0.0.0.0:* LISTEN 28150/mysqld
ps -ef |grep mysql
root 28284 1 2 07:26 pts/0 00:00:00 /bin/sh /usr/local/mysql/bin/mysqld_safe --datadir=/data/mysql --pid-file=/data/mysql/mysql.pid
mysql 29119 28284 5 07:26 pts/0 00:00:00 /usr/local/mysql/bin/mysqld --basedir=/usr/local/mysql --datadir=/data/mysql --plugin-dir=/usr/local/mysql/lib/plugin --user=mysql --log-error=/data/mysql/mysql-error.log --open-files-limit=65535 --pid-file=/data/mysql/mysql.pid --socket=/tmp/mysql.sock --port=3306
#修改root密碼:
法1:mysql -uroot -e "Set password=password(‘123.com’);"
法2:mysql -uroot -p123.com -e "use mysql;update user set authentication_string=password('456.com') where user='root';"
法3:update mysql.user set authentication_string=password("123.com") where user='root';
4、PHP的安裝與配置
#查看apache和MySQL啟動是否正常
netstat -lntup|egrep '80|3306'
tcp 0 0 0.0.0.0:3306 0.0.0.0:* LISTEN 29119/mysqld
tcp 0 0 :::80 :::* LISTEN 26925/httpd
1)擴展支持(mcrypt、mhash擴展和libevent)
mcrypt擴展庫可以實現加密解密功能,就是既能將明文加密,也可以密文還原。
mhash是基于離散數學原理的不可逆向的php加密方式擴展庫,其在默認情況下不開啟。
mhash的可以用于創建校驗數值,消息摘要,消息認證碼,以及無需原文的關鍵信息保存(如密碼)等。libevent是一個異步事件通知庫文件,其API提供了在某文件描述上發生某事件時或其超時時執行回調函數的機制
它主要用來替換事件驅動的網絡服務器上的event loop機制。
目前來說, libevent支持/dev/poll、kqueue、select、poll、epoll及Solaris的event ports。
centos源不能安裝libmcrypt-devel,由于版權的原因沒有自帶mcrypt的包
可以使用第三方源,這樣還可以使用yum來安裝
安裝第三方yum源
wget http://www.atomicorp.com/installers/atomic
sh ./atomic
使用yum命令安裝
yum install php-mcrypt libmcrypt libmcrypt-devel mhash mhash-devel libevent libevent-devel
2)支持xml的相關包
支持xml的rpm包
bzip2 是一個基于Burrows-Wheeler 變換的無損壓縮軟件能夠高效的完成文件數據的壓縮
libcurl主要功能就是用不同的協議連接和溝通不同的服務器,也就是相當封裝了的sockPHP
libcurl允許你用不同的協議連接和溝通不同的服務器
yum install libxml2 libxml2-devel bzip2-devel libcurl-devel
3)圖形相關的rpm包
yum install libjpeg-devel libpng-devel freetype-devel
#可復制批量安裝,中間加了一些常用的包,可檢查是否安裝,否則后面配置時會報錯
wget http://www.atomicorp.com/installers/atomic
sh ./atomic
yum -y install zlib libxml libjpeg freetype libpng gd curl libiconv zlib-devel gd-devel curl-devel openssl-devel libxslt-devel* php-mcrypt libmcrypt libmcrypt-devel mhash mhash-devel libevent libevent-devel libxml2 libxml2-devel bzip2-devel libcurl-devel libjpeg-devel libpng-devel freetype-devel
如yum安裝有問題可以編譯安裝mcrypt、libmcrypt、mhash庫:
下載地址: wget http://downloads.sourceforge.net/mcrypt/mcrypt-2.6.8.tar.gz wget http://downloads.sourceforge.net/mcrypt/libmcrypt-2.5.8.tar.gz wget http://downloads.sourceforge.net/mhash/mhash-0.9.9.9.tar.gz tar zxvf libmcrypt-2.5.8.tar.gz cd libmcrypt-2.5.8 ./configure --prefix=/usr/local/libmcrypt make && make install cd .. tar -zxvf mhash-0.9.9.9.tar.gz cd mhash-0.9.9.9 ./configure make && make install cd .. tar zxvf mcrypt-2.6.8.tar.gz cd mcrypt-2.6.8 ./configure --with-libmcrypt-prefix=/usr/local/libmcrypt/ make && make install cd .. echo "/usr/local/libmcrypt/lib" >>/etc/ld.so.conf.d/lib.conf echo "/usr/local/lib" >>/etc/ld.so.conf.d/lib.conf #配置額外的庫文件路徑,也就是上面安裝的庫文件需要指定路徑重新加載 ldconfig -v #重新加載庫文件 注意:此處源碼只安裝了在國內yum庫中無法安裝的庫文件,如PHP配置時缺少包文件需要yum安裝。
#安裝PHP
wget http://219.238.7.71/files/1007000009B9E9D0/cn2.php.net/distributions/php-5.6.30.tar.gztar zxvf php-5.6.30.tar.gz
cd php-5.6.30
./configure \
--prefix=/usr/local/php \
--with-config-file-path=/usr/local/php/etc \
--with-apxs2=/usr/local/httpd/bin/apxs \
--enable-inline-optimization \
--enable-fpm \
--with-mysql=/usr/local/mysql \
--with-mysqli=/usr/local/mysql/bin/mysql_config \
--with-pdo-mysql=/usr/local/mysql \
--with-gettext \
--enable-mbstring \
--with-iconv=/usr/local/libiconv \
--with-mcrypt \
--with-mhash \
--with-openssl \
--enable-bcmath \
--enable-soap \
--with-libxml-dir \
--enable-sockets \
--with-curl \
--with-zlib \
--enable-zip \
--with-bz2 \
--with-gd \
--with-freetype-dir \
--with-jpeg-dir \
--with-png-dir \
--enable-ctype \
--enable-xml
echo $?
make
make install
cp php.ini-production /usr/local/php/etc/php.ini
#檢查apache和PHP整合
grep modules/libphp5.so /usr/local/httpd/conf/httpd.conf
修改apache配置文件:
vim /usr/local/httpd/conf/httpd.conf
ServerName 127.0.0.1:80
#增加:
AddType application/x-httpd-php .php
AddType application/x-httpd-php-source .phps
#修改用戶:
User www
Group www
#修改主頁文件:
<IfModule dir_module>
DirectoryIndex index.php index.html
</IfModule>
#檢查apache配置文件:
/usr/local/httpd/bin/apachectl -t
Syntax OK
#編寫測試頁,測試PHP是否正常解析
vim /usr/local/apache/htdocs/index.php
<?php
phpinfo();
?>
#重新加載apache配置文件
/usr/local/apache/bin/apachectl graceful
測試訪問正常!
#編寫測試代碼,測試數據庫鏈接是否正常
vim /usr/local/apache/htdocs/mysql-test.php
<?php
//$link_id=mysql_connect('主機名','用戶','密碼');
$link_id=mysql_connect('localhost','root','123.com') or mysql_error();
if($link_id){
echo "mysql is ok!\n";
}else{
echo "mysql_error()";
}
?>
#到此LAMP安裝完成!
5、zabbix安裝配置
wget https://jaist.dl.sourceforge.net/project/zabbix/ZABBIX%20Latest%20Stable/3.0.8/zabbix-3.0.8.tar.gz
#安裝支持監控snmp包監控交換機等
yum install net-snmp-devel
tar zxvf zabbix-3.0.8.tar.gz
cd zabbix-3.0.8
./configure --prefix=/usr/local/zabbix --enable-server --enable-agent --with-mysql --with-net-snmp --with-libcurl --with-libxml2
make && make install
echo $?
#配置數據庫導入數據
mysql>create database zabbix;
mysql>grant all on zabbix.* to 'zabbixuser'@'localhost' identified by '123.com';
Query OK, 0 rows affected, 1 warning (0.00 sec)
mysql> flush privileges;
Query OK, 0 rows affected (0.01 sec)
mysql> use zabbix;
mysql> source /root/tools/zabbix-3.0.8/database/mysql/schema.sql
mysql> source /root/tools/zabbix-3.0.8/database/mysql/p_w_picpaths.sql
mysql> source /root/tools/zabbix-3.0.8/database/mysql/data.sql
#初始化sql文件在源碼包/root/zabbix-3.0.4/database/mysql目錄下
#配置zabbix_server配置文件修改如下:
vim /usr/local/zabbix/etc/zabbix_server.conf
LogFile=/usr/local/zabbix/logs/zabbix_server.log
DBHost=localhsot
DBName=zabbix
DBUser=zabbixuser
DBPassword=123.com #zabbixuser的密碼
LogSlowQueries=3000
cp misc/init.d/fedora/core/* /etc/init.d/
chmod +x /etc/init.d/zabbix_server
chmod +x /etc/init.d/zabbix_agentd
sed -i 's#BASEDIR=/usr/local#BASEDIR=/usr/local/zabbix#g' /etc/init.d/zabbix_agentd
sed -i 's#BASEDIR=/usr/local#BASEDIR=/usr/local/zabbix#g' /etc/init.d/zabbix_server
useradd -s /sbin/nologin -M zabbix
mkdir /usr/local/zabbix/logs
chown -R zabbix.zabbix /usr/local/zabbix/
/etc/init.d/zabbix_agentd start
/etc/init.d/zabbix_server start
netstat -lntup|grep 1005
tcp 0 0 0.0.0.0:10050 0.0.0.0:* LISTEN 28005/zabbix_agentd
tcp 0 0 0.0.0.0:10051 0.0.0.0:* LISTEN 27916/zabbix_server
#拷貝代碼文件到apache發布目錄下修改名為zabbix:
cp -a frontends/php /usr/local/httpd/htdocs/zabbix
sed -i 's#;date.timezone =#date.timezone = Asia/Shanghai#g' /usr/local/php/etc/php.ini
sed -i 's#post_max_size = 8M#post_max_size = 16M#g' /usr/local/php/etc/php.ini
sed -i 's#max_execution_time = 30#max_execution_time = 300#g' /usr/local/php/etc/php.ini
sed -i 's#max_input_time = 60#max_input_time = 300#g' /usr/local/php/etc/php.ini
#去掉前面的#號即可,糾結了半天。
sed -i 's#;always_populate_raw_post_data = -1#always_populate_raw_post_data = -1#g' /usr/local/php/etc/php.ini
#重新加載apache
/usr/local/httpd/bin/apachectl graceful
最后一步(install)會報錯,無法創建配置文件。
下載配置文件,保存到/usr/local/httpd/htdocs/zabbix/conf/zabbix.conf.php
重新登陸即可:usename:admin password:zabbix
修改中文:administration>>users>>admin>>language(chinese(zh_CN)) 更新網頁即可。
解決圖形界面中文亂碼的問題:
從windows下控制面板->字體->選擇一種中文字庫例如“楷體”
cd /usr/local/httpd/htdocs/zabbix/fonts
mv DejaVuSans.ttf DejaVuSans.ttf.bak
rz 上傳字體文件simkai.ttf到當前目錄
ls
DejaVuSans.ttf.bak simkai.ttf
vim ../include/defines.inc.php
在VIM編輯中使用替換功能將DejaVuSans替換成simkai,不添加后綴。
:%s/DejaVuSans/simkai
問題1:
./zabbix_server
./zabbix_server: error while loading shared libraries: libmysqlclient.so.20: cannot open shared object file: No such file or directory
解決:
# find / -name "libmysqlclient.so.20"
/usr/local/mysql-5.7.17/lib/libmysqlclient.so.20
ln -s /usr/local/mysql/lib/libmysqlclient.so.20 /usr/lib
ldconfig
看完上述內容,你們掌握怎樣進行LAMP源碼安裝以及如何搭建zabbix監控的方法了嗎?如果還想學到更多技能或想了解更多相關內容,歡迎關注億速云行業資訊頻道,感謝各位的閱讀!
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。