第1章 Apache环境安装
1.1环境
[root@backup ~]# cat /etc/redhat-release
CentOS release 6.7 (Final)
[root@backup ~]# 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
[root@backup ~]# uname -r
2.6.32-573.el6.x86_64
[root@backup ~]# uname -m
x86_64
[root@backup ~]# uname -n
backup
[root@backup ~]#
1.2软件包存放目录
[root@backup ~]# mkdir /home/oldboy/tools
[root@backup ~]# ls -l /home/oldboy/
total 4
drwxr-xr-x 2 root root 4096 Jul 23 21:43 tools
[root@backup ~]#
1.3上传Apache源码文件
[root@backup tools]# ls
httpd-2.2.31.tar.gz
[root@backup tools]#
1.4安装apache依赖包
[root@backup httpd-2.2.31]# yum -y installzlib-devel
1.5解压并编译安装apache
[root@backup tools]# tar xf httpd-2.2.31.tar.gz
[root@backup tools]# ls
httpd-2.2.31 httpd-2.2.31.tar.gz
[root@backup tools]# cd httpd-2.2.31
[root@backup httpd-2.2.31]#
[root@backup 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
[root@backup httpd-2.2.31]#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[1]: Leaving directory`/home/oldboy/tools/httpd-2.2.31‘
[root@backup httpd-2.2.31]#make install
1.6创建软连接
1.6.1软件目录软连接
[root@backup httpd-2.2.31]# ln -s/application/apache2.2.31/ /application/apache
1.6.2启动命令软连接
[root@backup httpd-2.2.31]# ln -s/application/apache/bin/apachectl /sbin/apachectl
1.7启动apache服务,测试安装是否成功
[root@backup httpd-2.2.31]# apachectl start
httpd:Could not reliably determine the server‘s fully qualified domain name, using172.16.1.41 for ServerName[pf1]
[root@backup httpd-2.2.31]#
[root@backup httpd-2.2.31]# lsof -i :80
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
httpd 83086 root 4u IPv6 67709 0t0 TCP *:http (LISTEN)
httpd 83088daemon 4u IPv6 67709 0t0 TCP *:http (LISTEN)
httpd 83089daemon 4u IPv6 67709 0t0 TCP *:http (LISTEN)
httpd 83090daemon 4u IPv6 67709 0t0 TCP *:http (LISTEN)
[root@backup httpd-2.2.31]# netstat -tunlp|grep :80
tcp 0 0 :::80 :::* LISTEN 83086/httpd
[root@backup httpd-2.2.31]#
1.8前端页面测试
apache安装没有错误
第2章 安装mysql5.5.49
2.1上传二进制包并解压安装
[root@backup tools]# tar xfmysql-5.5.49-linux2.6-x86_64.tar.gz
[root@backup tools]# mvmysql-5.5.49-linux2.6-x86_64 /application/mysql-5.5.49
[root@backup tools]# ln -s/application/mysql-5.5.49/ /application/mysql
2.2创建mysql配置文件
[root@backup tools]# \cp/application/mysql/support-files/my-small.cnf /etc/my.cnf
2.3创建mysql启动文件
[root@backup tools]# cp/application/mysql/support-files/mysql.server /etc/init.d/mysqld
2.4修改mysqld启动文件和mysqld_salf
[root@backup bin]# sed -i ‘s#/usr/local/mysql#/application/mysql#g‘/application/mysql/bin/mysqld_safe /etc/init.d/mysqld
2.5创建mysql用户
[root@backup bin]# useradd -s /sbin/nologin -Mmysql
[root@backup bin]# id mysql
uid=501(mysql) gid=501(mysql) groups=501(mysql)
[root@backup bin]#
2.6初始化数据库
[root@backup bin]# /application/mysql/scripts/mysql_install_db--basedir=/application/mysql/ --datadir=/application/mysql/data/ --user=mysql
Installing MySQL system tables...
160723 22:37:20 [Note]/application/mysql//bin/mysqld (mysqld 5.5.49) starting as process 92575 ...
OK
Filling help tables...
160723 22:37:21 [Note]/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/
[root@backup bin]#
2.7递归修改mysql软件权限
[root@backup bin]# chown -R mysql.mysql/application/mysql
[root@backup bin]# ls -l /application/mysql
lrwxrwxrwx 1 mysql mysql 26 Jul 23 22:29/application/mysql -> /application/mysql-5.5.49/
[root@backup bin]#
2.8修改mysql环境变量
[root@backup bin]# echo ‘exportPATH=/application/mysql/bin/:$PATH‘ >>/etc/profile
[root@backup bin]# source /etc/profile
[root@backup bin]# echo $PATH
/application/mysql/bin/:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin
[root@backup bin]#
2.9添加开机自启动
[root@backup bin]# chkconfig --add mysqld
[root@backup bin]# chkconfig --level 3 mysqld on
[root@backup bin]# chkconfig --list|grep mysqld
mysqld 0:off 1:off 2:on 3:on 4:on 5:on 6:off
[root@backup bin]#
2.10启动mysql数据库
[root@backup bin]# /etc/init.d/mysqld start
Starting MySQL.. SUCCESS!
[root@backup bin]# lsof -i :3306
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
mysqld 92868mysql 10u IPv4 90169 0t0 TCP *:mysql (LISTEN)
[root@backup bin]# netstat -tunlp|grep 3306
tcp 0 0 0.0.0.0:3306 0.0.0.0:* LISTEN 92868/mysqld
[root@backup bin]#
2.11优化mysql数据库
[root@backup bin]# mysqladmin -uroot password"oldboy123"
[root@backup bin]# mysql -u root -poldboy123 -e"show databases;"
[root@backup bin]# mysql -u root -poldboy123 -e"drop user ‘root‘@‘::1‘;"
[root@backup bin]# mysql -u root -poldboy123 -e"drop user ‘‘@‘localhost‘;"
[root@backup bin]# mysql -u root -poldboy123 -e"drop user ‘‘@backup;"
[root@backup bin]# mysql -u root -poldboy123 -e"drop user root@backup;"
[root@backup bin]# mysql -u root -poldboy123 -e"select user,host from mysql.user;"
+------+-----------+
| user | host |
+------+-----------+
| root | 127.0.0.1 |
| root | localhost |
+------+-----------+
[root@backup bin]#
[root@backup bin]# mysql -u root -poldboy123 -e"flush privileges;"
第3章 php安装
3.1上传php
[root@backup tools]# ls
httpd-2.2.31 httpd-2.2.31.tar.gz php-5.5.32.tar.gz
[root@backup tools]#
3.2安装php依赖包
3.2.1yum安装依赖包
[root@backup tools]# yum -y install zlib-devellibxml2 libxml2-devel libjpeg-turbo-devel freetype-devel libpng-devel gd-devel libcurl-devel libxslt-devel libmcrypt-devel mhash mcrypt
[root@backup tools]#yum -y install openssl-developenssl
3.2.2libiconv包只能源码安装
[root@backup tools]# ls -l libiconv-1.14.tar.gz
-rw-r--r-- 1 root root 4984397 Aug 8 2011libiconv-1.14.tar.gz
[root@backup tools]#cd libiconv-1.14
[root@backup libiconv-1.14]# ./configure--prefix=/usr/local/libiconv
[root@backup libiconv-1.14]# make
[root@backup libiconv-1.14]# make install
3.3编译安装php
[root@backup tools]# tar xf php-5.5.32.tar.gz
[root@backup tools]# cd php-5.5.32
[root@backup 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
[root@backup php-5.5.32]#
[root@backup php-5.5.32]# ln -s/application/mysql/lib/libmysqlclient.so.18 /usr/lib64/
[root@backup php-5.5.32]# touch ext/phar/phar.phar
[root@backup php-5.5.32]#make
编译正常结果:
[root@backup php-5.5.32]#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创建软连接
[root@backup php-5.5.32]# ln -s/application/php5.5.32/ /application/php
[root@backup php-5.5.32]# cp php.ini-production/application/php/lib/php.ini
[root@backup php-5.5.32]#
第4章 安装zabbix
4.1上传zabiix3.0
[root@backup tools]# ls -l zabbix-3.0.3.tar.gz
-rw-r--r-- 1 root root 15407273 Jul 15 14:19zabbix-3.0.3.tar.gz
[root@backup tools]#
4.2安装zabbix依赖环境
[root@backup tools]# yum -y install mysql-devellibxml2-devel net-snmp-devel libcurl-devel
4.3解压并编译安装zabbix
[root@backup tools]# tar xf zabbix-3.0.3.tar.gz
[root@backup zabbix-3.0.3]# ./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
[root@backupzabbix-3.0.3]# 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! *
* <http://www.zabbix.com> *
***********************************************************
[root@backup zabbix-3.0.3]#
[root@backup zabbix-3.0.3]# make install
make[2]: Leaving directory`/home/oldboy/tools/zabbix-3.0.3‘
make[1]: Leaving directory`/home/oldboy/tools/zabbix-3.0.3‘
[root@backup zabbix-3.0.3]#
第5章 lamp+zabbix环境整合
5.1apache+php整合
5.1.1创建apache软件管理用户
[root@backup zabbix]# 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
[root@backup conf]# vim/application/apache/conf/extra/httpd-vhosts.conf
<VirtualHost *:80>
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
</VirtualHost>
5.1.2创建phpinfo文件
[root@backup zabbix]# cat phpinfo.php
<?php
phpinfo();
?>
[root@backup zabbix]#
5.1.3检测apache+php
5.2测试apache+php+mysql
5.2.1创建zabbix库
[root@backup conf]# 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测试文件
[root@backup zabbix]# cat mysqltest.php
<?php
$link_id=mysql_connect(‘127.0.0.1‘,‘zabbix‘,‘zabbix‘)or mysql_error();
if($link_id){
echo"mysql successful by oldboy !";
}
else{
echomysql_error();
}
?>
[root@backup zabbix]#
5.2.3测试apache+php+mysql
5.3apache+mysql+php+zabbix
5.3.1导入zabbix库表
[root@backup mysql]# pwd
/home/oldboy/tools/zabbix-3.0.3/database/mysql
[root@backup mysql]#
[root@backup mysql]# mysql -uzabbix -pzabbixzabbix_server <schema.sql
[root@backup mysql]# mysql -uzabbix -pzabbixzabbix_server <images.sql
[root@backup mysql]# mysql -uzabbix -pzabbixzabbix_server <data.sql
5.3.2修改php.ini文件
[root@backup lib]# pwd
/application/php/lib
[root@backup lib]#
[root@backup lib]# sed -i ‘s#post_max_size =8M#post_max_size = 16M#g‘ php.ini
[root@backup lib]# sed -i ‘s#max_input_time =60#max_input_time = 300#g‘ php.ini
[root@backup lib]# sed -i ‘s#max_execution_time =30#max_execution_time = 300#g‘ php.ini
[root@backup lib]# sed -i ‘911 a date.timezone =Asia/Shanghai‘ php.ini
5.4初始化zabbix
5.4.1zabbix web站点目录
[root@backup htdocs]#mkdir zabbix
[root@backup htdocs]#cd zabbix
[root@backup zabbix]# cp -a/home/oldboy/tools/zabbix-3.0.3/frontends/php/* .
[root@backup zabbix]#chown -R www.www ../zabbix/
5.4.2修改zabbix配置文件
[root@backup lib]# grep ‘^[a-Z]‘/application/zabbix-server/etc/zabbix_server.conf
LogFile=/tmp/zabbix_server.log
DBName=zabbix_server
DBUser=zabbix
DBPassword=zabbix
Timeout=4
LogSlowQueries=3000
[root@backup lib]#
5.4.3安装zabbix客户端
[root@backup application]# rpm -ivh http://repo.zabbix.com/zabbix/3.0/rhel/6/x86_64/zabbix-release-3.0-1.el6.noarch.rpm
Retrieving http://repo.zabbix.com/zabbix/3.0/rhel/6/x86_64/zabbix-release-3.0-1.el6.noarch.rpm
Preparing... ########################################### [100%]
1:zabbix-release ########################################### [100%]
[root@backup application]#
[root@backup application]# yum -y installzabbix-agent
Loaded plugins: fastestmirror, security
Setting up Install Process
Loading mirror speeds from cached hostfile
* base:mirrors.aliyun.com
* epel:ftp.cuhk.edu.hk
* extras:mirrors.aliyun.com
* updates:mirrors.aliyun.com
zabbix | 951 B 00:00
zabbix/primary | 7.7 kB 00:00
zabbix 54/54
zabbix-non-supported | 951 B 00:00
zabbix-non-supported/primary | 3.8kB 00:00
zabbix-non-supported 15/15
Resolving Dependencies
--> Running transaction check
---> Package zabbix-agent.x86_64 0:3.0.3-1.el6will be installed
--> Processing 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 <packager@zabbix.com>
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!
[root@backup application]#
5.4.4启动zabbixserver
root@backup application]#/application/zabbix-server/sbin/zabbix_server -c/application/zabbix-server/etc/zabbix_server.conf
[root@backup application]# lsof -i :10051
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
zabbix_se 76653 zabbix 4u IPv4 185179 0t0 TCP *:zabbix-trapper (LISTEN)
zabbix_se 76658 zabbix 4u IPv4 185179 0t0 TCP *:zabbix-trapper (LISTEN)
zabbix_se 76659 zabbix 4u IPv4 185179 0t0 TCP *:zabbix-trapper (LISTEN)
zabbix_se 76660 zabbix 4u IPv4 185179 0t0 TCP *:zabbix-trapper (LISTEN)
zabbix_se 76661 zabbix 4u IPv4 185179 0t0 TCP *:zabbix-trapper (LISTEN)
zabbix_se 76662 zabbix 4u IPv4 185179 0t0 TCP *:zabbix-trapper (LISTEN)
zabbix_se 76663 zabbix 4u IPv4 185179 0t0 TCP *:zabbix-trapper (LISTEN)
zabbix_se 76664 zabbix 4u IPv4 185179 0t0 TCP *:zabbix-trapper (LISTEN)
zabbix_se 76665 zabbix 4u IPv4 185179 0t0 TCP *:zabbix-trapper (LISTEN)
zabbix_se 76666 zabbix 4u IPv4 185179 0t0 TCP *:zabbix-trapper (LISTEN)
zabbix_se 76667 zabbix 4u IPv4 185179 0t0 TCP *:zabbix-trapper (LISTEN)
zabbix_se 76668 zabbix 4u IPv4 185179 0t0 TCP *:zabbix-trapper (LISTEN)
zabbix_se 76669 zabbix 4u IPv4 185179 0t0 TCP *:zabbix-trapper (LISTEN)
zabbix_se 76670 zabbix 4u IPv4 185179 0t0 TCP *:zabbix-trapper (LISTEN)
zabbix_se 76671 zabbix 4u IPv4 185179 0t0 TCP *:zabbix-trapper (LISTEN)
zabbix_se 76672 zabbix 4u IPv4 185179 0t0 TCP *:zabbix-trapper (LISTEN)
zabbix_se 76673 zabbix 4u IPv4 185179 0t0 TCP *:zabbix-trapper (LISTEN)
[root@backup application]# netstat -tunlp|grepzabbix
tcp 0 0 0.0.0.0:10051 0.0.0.0:* LISTEN 76653/zabbix_server
[root@backup application]#
5.4.5
5.4.6
5.4.7
5.4.8
5.4.9
5.4.10zabbix中文界面显示
原文地址:http://xiaofengzi.blog.51cto.com/6100327/1829271