LAMP+Zabbix课程总结
第1章 Apache环境安装1.1环境
# cat /etc/redhat-release
CentOS release 6.7 (Final)
# uname -a
Linux backup 2.6.32-573.el6.x86_64 #1 SMP Thu Jul23 15:44:03 UTC 2015 x86_64 x86_64 x86_64 GNU/Linux
# uname -r
2.6.32-573.el6.x86_64
# uname -m
x86_64
# uname -n
backup
#
1.2软件包存放目录
# mkdir /home/oldboy/tools
# ls -l /home/oldboy/
total 4
drwxr-xr-x 2 root root 4096 Jul 23 21:43 tools
#
1.3上传Apache源码文件
# ls
httpd-2.2.31.tar.gz
#
1.4安装apache依赖包
# yum -y installzlib-devel
1.5解压并编译安装apache
# tar xf httpd-2.2.31.tar.gz
# ls
httpd-2.2.31 httpd-2.2.31.tar.gz
# cd httpd-2.2.31
#
# ./configure \
> --prefix=/application/apache2.2.31 \
> --enable-deflate \
> --enable-expires \
> --enable-headers \
> --enable-modules=most \
> --enable-so \
> --with-mpm=worker \
> --enable-rewrite
正常编译结果:
config.status: creating build/config_vars.sh
config.status: creating include/ap_config_auto.h
config.status: executing default commands
#make
make正常结果:
erver/mpm/worker/libworker.la os/unix/libos.la -lm/home/oldboy/tools/httpd-2.2.31/srclib/pcre/libpcre.la /home/oldboy/tools/httpd-2.2.31/srclib/apr-util/libaprutil-1.la/home/oldboy/tools/httpd-2.2.31/srclib/apr-util/xml/expat/libexpat.la/home/oldboy/tools/httpd-2.2.31/srclib/apr/libapr-1.la -lrt -lcrypt -lpthread
make: Leaving directory`/home/oldboy/tools/httpd-2.2.31'
#make install
1.6创建软连接
1.6.1软件目录软连接
# ln -s/application/apache2.2.31/ /application/apache
1.6.2启动命令软连接
# ln -s/application/apache/bin/apachectl /sbin/apachectl
1.7启动apache服务,测试安装是否成功
# apachectl start
httpd:Could not reliably determine the server's fully qualified domain name, using172.16.1.41 for ServerName
#
# lsof -i :80
COMMANDPID USER FDTYPE DEVICE SIZE/OFF NODE NAME
httpd83086 root 4u IPv667709 0t0 TCP *:http (LISTEN)
httpd 83088daemon 4uIPv6 67709 0t0TCP *:http (LISTEN)
httpd 83089daemon 4uIPv6 67709 0t0TCP *:http (LISTEN)
httpd 83090daemon 4uIPv6 67709 0t0TCP *:http (LISTEN)
# netstat -tunlp|grep :80
tcp 0 0 :::80 :::* LISTEN 83086/httpd
#
1.8前端页面测试
http://s4.运维网.com/wyfs02/M01/84/8B/wKiom1eUGvXipnAfAAB8kjufwwQ120.png-wh_500x0-wm_3-wmp_4-s_2944425333.png
apache安装没有错误
第2章 安装mysql5.5.49
2.1上传二进制包并解压安装
# tar xfmysql-5.5.49-linux2.6-x86_64.tar.gz
# mvmysql-5.5.49-linux2.6-x86_64 /application/mysql-5.5.49
# ln -s/application/mysql-5.5.49/ /application/mysql
2.2创建mysql配置文件
# \cp/application/mysql/support-files/my-small.cnf /etc/my.cnf
2.3创建mysql启动文件
# cp/application/mysql/support-files/mysql.server /etc/init.d/mysqld
2.4修改mysqld启动文件和mysqld_salf
# sed -i 's#/usr/local/mysql#/application/mysql#g'/application/mysql/bin/mysqld_safe /etc/init.d/mysqld
2.5创建mysql用户
# useradd -s /sbin/nologin -Mmysql
# id mysql
uid=501(mysql) gid=501(mysql) groups=501(mysql)
#
2.6初始化数据库
# /application/mysql/scripts/mysql_install_db--basedir=/application/mysql/ --datadir=/application/mysql/data/ --user=mysql
Installing MySQL system tables...
160723 22:37:20 /application/mysql//bin/mysqld (mysqld 5.5.49) starting as process 92575 ...
OK
Filling help tables...
160723 22:37:21 /application/mysql//bin/mysqld (mysqld 5.5.49) starting as process 92582 ...
OK
To start mysqld at boot time you have to copy
support-files/mysql.server to the right place foryour system
PLEASE REMEMBER TO SET A PASSWORD FOR THE MySQLroot USER !
To do so, start the server, then issue thefollowing commands:
/application/mysql//bin/mysqladmin -u root password'new-password'
/application/mysql//bin/mysqladmin -u root -hbackup password 'new-password'
Alternatively you can run:
/application/mysql//bin/mysql_secure_installation
which will also give you the option of removing thetest
databases and anonymous user created bydefault.This is
strongly recommended for production servers.
See the manual for more instructions.
You can start the MySQL daemon with:
cd /application/mysql/ ;/application/mysql//bin/mysqld_safe &
You can test the MySQL daemon withmysql-test-run.pl
cd /application/mysql//mysql-test ; perlmysql-test-run.pl
Please report any problems athttp://bugs.mysql.com/
#
2.7递归修改mysql软件权限
# chown -R mysql.mysql/application/mysql
# ls -l /application/mysql
lrwxrwxrwx 1 mysql mysql 26 Jul 23 22:29/application/mysql -> /application/mysql-5.5.49/
#
2.8修改mysql环境变量
# echo 'exportPATH=/application/mysql/bin/:$PATH' >>/etc/profile
# source /etc/profile
# echo $PATH
/application/mysql/bin/:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin
#
2.9添加开机自启动
# chkconfig --add mysqld
# chkconfig --level 3 mysqld on
# chkconfig --list|grep mysqld
mysqld 0:off1:off2:on 3:on 4:on 5:on 6:off
#
2.10启动mysql数据库
# /etc/init.d/mysqld start
Starting MySQL.. SUCCESS!
# lsof -i :3306
COMMANDPIDUSER FDTYPE DEVICE SIZE/OFF NODE NAME
mysqld92868mysql 10uIPv4 90169 0t0TCP *:mysql (LISTEN)
# netstat -tunlp|grep 3306
tcp 0 0 0.0.0.0:3306 0.0.0.0:* LISTEN 92868/mysqld
#
2.11优化mysql数据库
# mysqladmin -uroot password"oldboy123"
# mysql -u root -poldboy123 -e"show databases;"
# mysql -u root -poldboy123 -e"drop user 'root'@'::1';"
# mysql -u root -poldboy123 -e"drop user ''@'localhost';"
# mysql -u root -poldboy123 -e"drop user ''@backup;"
# mysql -u root -poldboy123 -e"drop user root@backup;"
# mysql -u root -poldboy123 -e"select user,host from mysql.user;"
+------+-----------+
| user | host |
+------+-----------+
| root | 127.0.0.1 |
| root | localhost |
+------+-----------+
#
# mysql -u root -poldboy123 -e"flush privileges;"
第3章 php安装
3.1上传php
# ls
httpd-2.2.31 httpd-2.2.31.tar.gz php-5.5.32.tar.gz
#
3.2安装php依赖包
3.2.1yum安装依赖包
# yum -y install zlib-devellibxml2 libxml2-devel libjpeg-turbo-devel freetype-devel libpng-devel gd-devel libcurl-devel libxslt-devellibmcrypt-devel mhash mcrypt
#yum -y install openssl-developenssl
3.2.2libiconv包只能源码安装
# ls -l libiconv-1.14.tar.gz
-rw-r--r-- 1 root root 4984397 Aug82011libiconv-1.14.tar.gz
#cd libiconv-1.14
# ./configure--prefix=/usr/local/libiconv
# make
# make install
3.3编译安装php
# tar xf php-5.5.32.tar.gz
# cd php-5.5.32
#
./configure \
--prefix=/application/php5.5.32 \
--with-apxs2=/application/apache/bin/apxs \
--with-mysql=/application/mysql/ \
--with-pdo-mysql=mysqlnd \
--with-mysqli=mysqlnd \
--with-iconv-dir=/usr/local/libiconv \
--with-freetype-dir \
--with-jpeg-dir \
--with-png-dir \
--with-zlib \
--with-libxml-dir=/usr \
--enable-xml \
--disable-rpath \
--enable-bcmath \
--enable-shmop \
--enable-sysvsem \
--enable-inline-optimization \
--with-curl \
--enable-mbregex \
--enable-mbstring \
--with-mcrypt \
--with-gd \
--enable-gd-native-ttf \
--with-openssl \
--with-mhash \
--enable-pcntl \
--enable-sockets \
--with-xmlrpc \
--enable-zip \
--enable-soap \
--enable-short-tags \
--enable-static \
--with-xsl \
--enable-ftp \
--enable-opcache=no \
--with-gettext
正常编译结果:
Generating files
configure: creating ./config.status
creating main/internal_functions.c
creating main/internal_functions_cli.c
+--------------------------------------------------------------------+
| License: |
| This software is subject to the PHP License, availablein this |
| distribution in the file LICENSE.By continuing this installation |
| process, you are bound by the terms of thislicense agreement. |
| If you do not agree with the terms of thislicense, you must abort |
| the installation process at this point. |
+--------------------------------------------------------------------+
Thank you for using PHP.
config.status: creating php5.spec
config.status: creating main/build-defs.h
config.status: creating scripts/phpize
config.status: creating scripts/man1/phpize.1
config.status: creating scripts/php-config
config.status: creating scripts/man1/php-config.1
config.status: creating sapi/cli/php.1
config.status: creating sapi/cgi/php-cgi.1
config.status: creating ext/phar/phar.1
config.status: creating ext/phar/phar.phar.1
config.status: creating main/php_config.h
config.status: executing default commands
#
# ln -s/application/mysql/lib/libmysqlclient.so.18 /usr/lib64/
# touch ext/phar/phar.phar
#make
编译正常结果:
#make install
正常结果:
You may want to add: /application/php5.5.32/lib/phpto your php.ini include_path
/home/oldboy/tools/php-5.5.32/build/shtool install-c ext/phar/phar.phar /application/php5.5.32/bin
ln -s -f phar.phar /application/php5.5.32/bin/phar
Installing PDO headers: /application/php5.5.32/include/php/ext/pdo/
3.4创建软连接
# ln -s/application/php5.5.32/ /application/php
# cp php.ini-production/application/php/lib/php.ini
#
第4章 安装zabbix
4.1上传zabiix3.0
# ls -l zabbix-3.0.3.tar.gz
-rw-r--r-- 1 root root 15407273 Jul 15 14:19zabbix-3.0.3.tar.gz
#
4.2安装zabbix依赖环境
# yum -y install mysql-devellibxml2-devel net-snmp-devel libcurl-devel
4.3解压并编译安装zabbix
# tar xf zabbix-3.0.3.tar.gz
# ./configure--prefix=/application/zabbix-server --enable-server --with-mysql--with-net-snmp --with-libcurl --with-libxml2
错误总结:
checkingfor mysql_config... /application/mysql/bin//mysql_config
checkingfor main in -lmysqlclient... no
configure:error: Not found mysqlclient library
# cd ../
解决方法:
sed -i 's#/usr/local/mysql#/application/mysql#g'/application/mysql/bin/mysql_config
正常编译结果:
Enable Javagateway: no
LDAPsupport: no
IPv6support: no
***********************************************************
* Now run 'make install' *
* *
* Thank you for using Zabbix! *
* *
***********************************************************
#
# make install
make: Leaving directory`/home/oldboy/tools/zabbix-3.0.3'
make: Leaving directory`/home/oldboy/tools/zabbix-3.0.3'
#
第5章 lamp+zabbix环境整合
5.1apache+php整合
5.1.1创建apache软件管理用户
# useradd -s /sbin/nologin -Mwww
apache修改
100 ServerName127.0.0.1:80
168 DirectoryIndex index.php index.html
311 AddType application/x-httpd-php .php .phtml
312 AddType application/x-httpd-php-source .phps
398 Includeconf/extra/httpd-vhosts.conf
# vim/application/apache/conf/extra/httpd-vhosts.conf
ServerAdmin webmaster@dummy-host.example.com
DocumentRoot "/application/apache2.2.31/htdocs/zabbix"
ServerName zabbix.etiantian.org
ServerAlias etiantian.org
ErrorLog"logs/zabbix-error_log"
CustomLog"logs/zabbix-access_log" common
5.1.2创建phpinfo文件
# cat phpinfo.php
#
5.1.3检测apache+php
http://s3.运维网.com/wyfs02/M02/84/8B/wKiom1eUGzCykzUGAAECmeb8XSM946.png-wh_500x0-wm_3-wmp_4-s_354503886.png
5.2测试apache+php+mysql
5.2.1创建zabbix库
# mysql -uroot -p
Enter password:
Welcome to the MySQL monitor.Commands end with ; or \g.
Your MySQL connection id is 1
Server version: 5.5.49 MySQL Community Server (GPL)
Copyright (c) 2000, 2016, Oracle and/or itsaffiliates. All rights reserved.
Oracle is a registered trademark of OracleCorporation and/or its
affiliates. Other names may be trademarks of theirrespective
owners.
Type 'help;' or '\h' for help. Type '\c' to clearthe current input statement.
mysql> create database zabbix_server defaultcharset utf8;
Query OK, 1 row affected (0.00 sec)
mysql> grant all privileges on zabbix_server.*to zabbix@localhost identified by 'zabbix';
Query OK, 0 rows affected (0.00 sec)
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
mysql>
5.2.2创建php测试文件
# cat mysqltest.php
#
5.2.3测试apache+php+mysql
http://s1.运维网.com/wyfs02/M00/84/8B/wKioL1eUG0Xw1lJGAAA5bfpBpq4283.png-wh_500x0-wm_3-wmp_4-s_1954106392.png
5.3apache+mysql+php+zabbix
5.3.1导入zabbix库表
# pwd
/home/oldboy/tools/zabbix-3.0.3/database/mysql
#
# mysql -uzabbix -pzabbixzabbix_serverProcessing Dependency: libodbc.so.2()(64bit)for package: zabbix-agent-3.0.3-1.el6.x86_64
--> Running transaction check
---> Package unixODBC.x86_64 0:2.2.14-14.el6will be installed
--> Finished Dependency Resolution
Dependencies Resolved
========================================================================================
Package Arch Version Repository Size
========================================================================================
Installing:
zabbix-agent x86_64 3.0.3-1.el6 zabbix 319 k
Installing for dependencies:
unixODBC x86_64 2.2.14-14.el6 base 378 k
Transaction Summary
========================================================================================
Install 2 Package(s)
Total download size: 697 k
Installed size: 2.2 M
Downloading Packages:
(1/2): unixODBC-2.2.14-14.el6.x86_64.rpm | 378 kB 00:00
(2/2): zabbix-agent-3.0.3-1.el6.x86_64.rpm | 319 kB 00:00
----------------------------------------------------------------------------------------
Total 642 kB/s | 697 kB 00:01
warning: rpmts_HdrFromFdno: Header V4 DSA/SHA1Signature, key ID 79ea5ed4: NOKEY
Retrieving key fromfile:///etc/pki/rpm-gpg/RPM-GPG-KEY-ZABBIX
Importing GPG key 0x79EA5ED4:
Userid :Zabbix SIA
Package:zabbix-release-3.0-1.el6.noarch (installed)
From : /etc/pki/rpm-gpg/RPM-GPG-KEY-ZABBIX
Running rpm_check_debug
Running Transaction Test
Transaction Test Succeeded
Running Transaction
Warning: RPMDB altered outside of yum.
Installing: unixODBC-2.2.14-14.el6.x86_64 1/2
Installing: zabbix-agent-3.0.3-1.el6.x86_64 2/2
Verifying:zabbix-agent-3.0.3-1.el6.x86_64 1/2
Verifying:unixODBC-2.2.14-14.el6.x86_64 2/2
Installed:
zabbix-agent.x86_64 0:3.0.3-1.el6
Dependency Installed:
unixODBC.x86_64 0:2.2.14-14.el6
Complete!
#
5.4.4启动zabbixserver
root@backup application]#/application/zabbix-server/sbin/zabbix_server -c/application/zabbix-server/etc/zabbix_server.conf
# lsof -i :10051
COMMAND PID USER FDTYPE DEVICE SIZE/OFF NODE NAME
zabbix_se 76653 zabbix 4u IPv4 185179 0t0TCP *:zabbix-trapper (LISTEN)
zabbix_se 76658 zabbix 4u IPv4 185179 0t0TCP *:zabbix-trapper (LISTEN)
zabbix_se 76659 zabbix 4u IPv4 185179 0t0TCP *:zabbix-trapper (LISTEN)
zabbix_se 76660 zabbix 4u IPv4 185179 0t0TCP *:zabbix-trapper (LISTEN)
zabbix_se 76661 zabbix 4u IPv4 185179 0t0TCP *:zabbix-trapper (LISTEN)
zabbix_se 76662 zabbix 4u IPv4 185179 0t0TCP *:zabbix-trapper (LISTEN)
zabbix_se 76663 zabbix 4u IPv4 185179 0t0TCP *:zabbix-trapper (LISTEN)
zabbix_se 76664 zabbix 4u IPv4 185179 0t0TCP *:zabbix-trapper (LISTEN)
zabbix_se 76665 zabbix 4u IPv4 185179 0t0TCP *:zabbix-trapper (LISTEN)
zabbix_se 76666 zabbix 4u IPv4 185179 0t0TCP *:zabbix-trapper (LISTEN)
zabbix_se 76667 zabbix 4u IPv4 185179 0t0TCP *:zabbix-trapper (LISTEN)
zabbix_se 76668 zabbix 4u IPv4 185179 0t0TCP *:zabbix-trapper (LISTEN)
zabbix_se 76669 zabbix 4u IPv4 185179 0t0TCP *:zabbix-trapper (LISTEN)
zabbix_se 76670 zabbix 4u IPv4 185179 0t0TCP *:zabbix-trapper (LISTEN)
zabbix_se 76671 zabbix 4u IPv4 185179 0t0TCP *:zabbix-trapper (LISTEN)
zabbix_se 76672 zabbix 4u IPv4 185179 0t0TCP *:zabbix-trapper (LISTEN)
zabbix_se 76673 zabbix 4u IPv4 185179 0t0TCP *:zabbix-trapper (LISTEN)
# netstat -tunlp|grepzabbix
tcp 0 0 0.0.0.0:10051 0.0.0.0:* LISTEN 76653/zabbix_server
#
5.4.5
http://s3.运维网.com/wyfs02/M01/84/8B/wKioL1eUG4-BPLLyAAC2xKmgECk297.png-wh_500x0-wm_3-wmp_4-s_112252783.png
5.4.6
http://s1.运维网.com/wyfs02/M02/84/8B/wKioL1eUG6vzc9RzAADOBCny1Gs852.png-wh_500x0-wm_3-wmp_4-s_2919498806.png
http://s1.运维网.com/wyfs02/M01/84/8B/wKiom1eUG6uBgS74AACB8gnVSzM306.png-wh_500x0-wm_3-wmp_4-s_1672040499.png
http://s3.运维网.com/wyfs02/M02/84/8B/wKioL1eUG6yhWseJAAAuGx2Zg-4780.png-wh_500x0-wm_3-wmp_4-s_1713837635.png
5.4.7
http://s1.运维网.com/wyfs02/M02/84/8B/wKiom1eUHLvz24CmAADQQA4186o795.png-wh_500x0-wm_3-wmp_4-s_3734883918.png
5.4.8
http://s2.运维网.com/wyfs02/M01/84/8B/wKiom1eUHNTyNnpRAACzGPPElGo895.png-wh_500x0-wm_3-wmp_4-s_2093711796.png
5.4.9
http://s1.运维网.com/wyfs02/M00/84/8B/wKioL1eUHPPhK2QmAADRRlIdHBE899.png-wh_500x0-wm_3-wmp_4-s_3908642336.png
http://s2.运维网.com/wyfs02/M00/84/8B/wKiom1eUHQPR7UE8AAC9YQ965KU758.png-wh_500x0-wm_3-wmp_4-s_3102054553.png
http://s5.运维网.com/wyfs02/M02/84/8B/wKiom1eUHWLC2PuuAAB-U7rIZkc477.png-wh_500x0-wm_3-wmp_4-s_3631511038.png
5.4.10zabbix中文界面显示
http://s5.运维网.com/wyfs02/M01/84/8B/wKiom1eUHWLDF-6kAAEWVIAUayo186.png-wh_500x0-wm_3-wmp_4-s_729500580.png
http://s4.运维网.com/wyfs02/M02/84/8B/wKioL1eUHWPwD_LoAADVfklS43U814.png-wh_500x0-wm_3-wmp_4-s_1511719485.png
http://s4.运维网.com/wyfs02/M02/84/8B/wKioL1eUHWPhD_1qAACYmSqw-VQ156.png-wh_500x0-wm_3-wmp_4-s_2467099954.png
http://s1.运维网.com/wyfs02/M02/84/8B/wKiom1eUHWSgHcq6AADaR66YZGI445.png-wh_500x0-wm_3-wmp_4-s_845135906.png
页:
[1]