Zabbix LAMP搭建zabbix

本文涉及的产品
RDS MySQL Serverless 基础系列,0.5-2RCU 50GB
云数据库 RDS MySQL,集群系列 2核4GB
推荐场景:
搭建个人博客
云数据库 RDS PostgreSQL,集群系列 2核4GB
简介: sed -i 's/SELINUX=enabled/SELINUX=disabled/g' /etc/selinux/configgetenforce 0/etc/init.

sed -i 's/SELINUX=enabled/SELINUX=disabled/g' /etc/selinux/config

getenforce 0

/etc/init.d/iptables stop

cat /etc/redhat-release

uname -r

uname -m


#su -

#chmod 777 /usr/local/src

yum -y install gcc wget libtool expat-devel pcre-devel zlib-devel openssl-devel


#安装apache

cd /usr/local/src

useradd -s /sbin/nologin -M www

wget -c http://mirrors.cnnic.cn/apache//apr/apr-1.6.3.tar.gz  

wget -c http://archive.apache.org/dist/apr/apr-util-1.5.2.tar.gz

wget -c http://mirrors.aliyun.com/apache/httpd/httpd-2.4.29.tar.gz 

#编译安装apr

tar xf apr-1.6.3.tar.gz

cd apr-1.6.3

./configure --prefix=/usr/local/apr-1.6.3

make && make install

echo $?

ln -s /usr/local/apr-1.6.3/ /usr/local/apr

cd ..


tar zvxf apr-util-1.5.2.tar.gz  

cd apr-util-1.5.2

./configure --prefix=/usr/local/apr-util-1.5.2--with-apr=/usr/local/apr-1.6.3/

echo $?

make && make install

echo $?

ln -s /usr/local/apr-util-1.5.2/ /usr/local/apr-util

cd ..


tar zxvf httpd-2.4.29.tar.gz

cd httpd-2.4.29

./configure --prefix=/usr/local/httpd-2.4.29 --with-expat=builtin--with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util --enable-so--enable-deflate --enable-expires --enable-headers --enable-ssl--enable-rewrite --enable-mpms-shared=all --with-mpm=prefork --enable-mods-shared=most

echo $?

make

make install

ln -s /usr/local/httpd-2.4.29/ /usr/local/httpd


#配置http环境变量

echo "export PATH=/usr/local/httpd/bin:$PATH">>/etc/profile

. /etc/profile


#查看安装的模块、

apachectl -t -D DUMP_MODULES


#apache配置文件位置

#/usr/local/httpd/conf/httpd.conf


#启动apache服务

apachectl start


#配置启动脚本

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





#搭建MYSQL

useradd -s /sbin/nologin -M mysql

wget http://mirrors.sohu.com/mysql/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 = 1

skip-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


#修改root密码

mysql -uroot

#mysql -uroot -pk8008.com -e "use mysql;update user set

authentication_string=password('新密码') where user='root';"

update mysql.user set authentication_string=password("geeboo")where user='root';



#安装PHP

#安装第三方yum源

wget http://www.atomicorp.com/installers/atomic

sh ./atomic

#使用yum命令安装

yum -y install zlib libxml libjpeg freetype libpng gd curl libiconvzlib-devel gd-devel curl-devel openssl-devel libxslt-devel* php-mcryptlibmcrypt libmcrypt-devel mhash mhash-devel libevent libevent-devel libxml2libxml2-devel bzip2-devel libcurl-devel libjpeg-devel libpng-develfreetype-devel


wget http://mirrors.sohu.com/php/php-5.6.30.tar.gz

tar 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-iconv \

--with-png-dir


make

make install

cp php.ini-production /usr/local/php/etc/php.ini


修改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

#修改主页文件:

DirectoryIndex index.php index.html



/usr/local/httpd/bin/apachectl -t

Syntax OK



vim /usr/local/httpd/htdocs/index.php


phpinfo();

?>

#重新加载apache配置文件

/usr/local/httpd/bin/apachectl graceful


测试访问正常!


#编写测试代码,测试数据库链接是否正常

vim /usr/local/httpd/htdocs/mysql-test.php


//$link_id=mysql_connect('主机名','用户','密码');

$link_id=mysql_connect('localhost','root','k8008.com') or mysql_error();

if($link_id){

echo "mysql is ok!\n";

}else{

echo "mysql_error()";

}

?>


#到此LAMP安装完成!




#安装ZABBIX

wget https://jaist.dl.sourceforge.net/project/zabbix/ZABBIX%20Latest%20Stable/3.0.4/zabbix-3.0.4.tar.gz

yum install net-snmp-devel

tar zxvf zabbix-3.0.4.tar.gz

cd zabbix-3.0.4

./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

grant all on zabbix.* to 'zabbixuser'@'localhost' identified by'k8008.com';

flush privileges;

use zabbix;

source /usr/local/src/zabbix-3.0.4/database/mysql/schema.sql

source /usr/local/src/zabbix-3.0.4/database/mysql/images.sql

source /usr/local/src/zabbix-3.0.4/database/mysql/data.sql


#配置zabbix_server配置文件修改如下:

LogFile=/usr/local/zabbix/logs/zabbix_server.log

DBHost=127.0.0.1

DBName=zabbix

DBUser=zabbixuser

DBPassword=k8008.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


#拷贝代码文件到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


#zabbix登录

账号:admin

密码:zabbix

相关实践学习
如何在云端创建MySQL数据库
开始实验后,系统会自动创建一台自建MySQL的 源数据库 ECS 实例和一台 目标数据库 RDS。
全面了解阿里云能为你做什么
阿里云在全球各地部署高效节能的绿色数据中心,利用清洁计算为万物互联的新世界提供源源不断的能源动力,目前开服的区域包括中国(华北、华东、华南、香港)、新加坡、美国(美东、美西)、欧洲、中东、澳大利亚、日本。目前阿里云的产品涵盖弹性计算、数据库、存储与CDN、分析与搜索、云通信、网络、管理与监控、应用服务、互联网中间件、移动服务、视频服务等。通过本课程,来了解阿里云能够为你的业务带来哪些帮助 &nbsp; &nbsp; 相关的阿里云产品:云服务器ECS 云服务器 ECS(Elastic Compute Service)是一种弹性可伸缩的计算服务,助您降低 IT 成本,提升运维效率,使您更专注于核心业务创新。产品详情: https://www.aliyun.com/product/ecs
目录
相关文章
|
监控 Kubernetes 数据库
K8S搭建zabbix
K8S搭建zabbix
197 0
|
缓存 监控 前端开发
zabbix搭建
zabbix搭建
114 0
|
监控 安全 前端开发
zabbix5.0安装及配置
zabbix5.0安装及配置
zabbix5.0安装及配置
|
监控 前端开发 关系型数据库
ZABBIX4.4 安装及配置
ZABBIX4.4 安装及配置
ZABBIX4.4 安装及配置
|
监控 前端开发 关系型数据库
配置zabbix
zabbix是一个基于WEB界面的提供分布式系统监视以及网络监视功能的企业级的开源解决方案。
258 0
配置zabbix
|
监控 关系型数据库 应用服务中间件
|
监控
Zabbix snmptrap 配置
服务器通过snmptrap主动上报告警,在zabbix配置snmptrap监控也是很简单的。 1.登录被监控的设备的bmc管理系统配置snmptrap地址指向我们的zabbix服务器或代理服务器。
2101 0
|
监控 关系型数据库 MySQL
|
Web App开发 监控 关系型数据库
|
SQL 监控 关系型数据库