Centos7.5安装LAMP+Zabbix4.0服务
一、环境描述:
1)软件版本:httpd-2.4.25.tar.gz、mysql-5.7.22-linux-glibc2.12-x86_64.tar.gz、php-7.2.22.tar.gz、zabbix-4.0.12.tar.gz
2)操作系统:linux-Centos7.5
3)硬件情况:cpu——2颗、内存——4G、硬盘——30G
4)网络情况:能通外网
软件包链接:
HTTP:http://httpd.apache.org/download.cgi
MySQL:https://dev.mysql.com/downloads/
PHP:https://www.php.net/downloads.php
Zabbix:https://www.zabbix.com/download_sources#tab:40LTS
二、准备工作
1.关闭防火墙
[root@linuxMA ~]# systemctl stop firewalld
[root@linuxMA ~]# iptables -F
[root@linuxMA ~]# setenforce 0
setenforce: SELinux is disabled
三、开始环境部署
http部署
1.安装依赖包
[root@linuxMA ~]# yum -y install pcre pcre-devel apr apr-devel cyrus-sasl-devel expat-devel libdb-devel openldap-devel apr-util apr-util-devel
2.解压 httpd-2.4.25.tar.gz
[root@linuxMA ~]# tar xf httpd-2.4.25.tar.gz -C /usr/src/
[root@linuxMA ~]# cd /usr/src/httpd-2.4.25/
3.编译安装
[root@linuxMA httpd-2.4.25]# ./configure --prefix=/usr/local/httpd --enable-so --enable-rewrite && make && make install
4.开启httpd服务
[root@linuxMA ~]# /usr/local/httpd/bin/apachectl start
5.查看端口是否正常开启
[root@linuxMA ~]# netstat -lnpt |grep httpd
tcp6 0 0 :::80 :::* LISTEN 39125/http
Mysql部署
本次使用二进制方法部署
1.查看是否存在libaio安装包
[root@linuxMA ~]# rpm -q libaio
libaio-0.3.109-13.el7.x86_64
2.解压安装包
[root@linuxMA ~]# tar xf mysql-5.7.22-linux-glibc2.12-x86_64.tar.gz -C /usr/local/
[root@linuxMA ~]# ls /usr/local/
bin etc games httpd include lib lib64 libexec mysql-5.7.22-linux-glibc2.12-x86_64 sbin share src
3.进行配置
[root@linuxMA ~]# ln -s mysql-5.7.22-linux-glibc2.12-x86_64.tar.gz mysql
[root@linuxMA ~]# useradd -M -s /sbin/nologin mysql
[root@linuxMA ~]# cd /usr/local/
[root@linuxMA local]# cd mysql
[root@linuxMA mysql]# chown -R mysql:mysql ./
[root@linuxMA mysql]# ./bin/mysqld --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data --initialize
2019-03-05T03:47:57.538695Z 1 [Note] A temporary password is generated for root@localhost: wAmJ3xDNpK?#
4.编辑my.cnf配置文件
[root@linuxMA mysql]# vim /etc/my.cnf
[mysqld]
datadir=/usr/local/mysql/data
socket=/tmp/mysql.sock
[mysqld_safe]
log-error=/usr/local/mysql/data/mysql.log
pid-file=/usr/local/mysql/data/mysql.pid
5.开启mysql并查看端口
[root@linuxMA mysql]#./support-files/mysql.server start
Starting MySQL.Logging to '/usr/local/mysql/data/mysql.log'.
SUCCESS!
[root@linuxMA mysql]# netstat -lnpt |grep :3306
tcp6 0 0 :::3306 :::* LISTEN 82323/mysqld
6.配置mysql启动
[root@linuxMA mysql]# cp support-files/mysql.server /etc/init.d/mysqld
[root@linuxMA mysql]# ls -l /etc/init.d/mysqld
-rwxr-xr-x. 1 root root 10576 3月 5 11:50 /etc/init.d/mysqld
[root@linuxMA mysql]# service mysqld restart
Shutting down MySQL.. SUCCESS!
Starting MySQL. SUCCESS!
7.修改mysql数据库密码
[root@linuxMA mysql]# ./bin/mysqladmin -u root -p'wAmJ3xDNpK?#' password '123456'
[root@linuxMA mysql]# ln -s /usr/local/mysql/bin/* /usr/local/bin/
[root@linuxMA mysql]# cd
[root@linuxMA ~]# mysql -u root -p123456
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql> exit
Bye
php部署
1.安装依赖包
[root@linuxMA ~]# yum -y install mysql-devel httpd-manual mysql-connector-odbc libdbi-dbd-mysql net-snmp-devel curl-devel unixODBC-devel java-devel openldap openldap-devel freetype-devel libxml2* gd php-gd libpng libpng-devel libjpeg libjpeg-devel libevnet-devel
2.解压php-7.2.22.tar.gz安装包
[root@linuxMA ~]# tar xf php-7.2.22.tar.gz -C /usr/src/
root@linuxMA ~]# ls /usr/src/
debug httpd-2.4.25 kernels php-7.2.22
[root@linuxMA ~]# cd /usr/src/php-7.2.22/
3.配置编译安装
[root@linuxMA php-7.2.22]# ./configure --prefix=/usr/local/php7 --with-apxs2=/usr/local/httpd/bin/apxs --with-mysql=/usr/local/mysql --with-openssl --enable-sockets --enable-sysvshm --with-mysqli --enable-mbstring --with-freetype-dir --with-jpeg-dir --with-png-dir --with-zlib-dir --with-libxml-dir=/usr --enable-xml --with-mhash --with-config-file-path=/etc --with-config-file-scan-dir=/etc/php.d --with-curl --with-gd --with-gettext --enable-bcmath --enable-opcache
[root@linuxMA php-7.2.22]# make && make install
4.修改php.ini配置文件
[root@linuxMA php-7.2.22]# cp php.ini-development /etc/php.ini
#修改php.ini 因为zabbix的运行环境要求,否则zabbix 的环境检测室无法通过的
sed -i "s@;date.timezone =@date.timezone = Asia/Shanghai@g" /etc/php.ini
sed -i "s@max_execution_time = 30@max_execution_time = 300@g" /etc/php.ini
sed -i "s@post_max_size = 8M@post_max_size = 32M@g" /etc/php.ini
sed -i "s@max_input_time = 60@max_input_time = 300@g" /etc/php.ini
sed -i "s@memory_limit = 128M@memory_limit = 128M@g" /etc/php.ini
sed -i "s@;mbstring.func_overload = 0@ambstring.func_overload = 2@g" /etc/php.ini
5.http结合apache
#配置httpd
[root@linuxMA ~]# vim /usr/local/httpd/conf/httpd.conf
# 第55行加入 AddType application/x-httpd-php .php .phtml
# 第167行添加 DirectoryIndex index.html index.php
zabbix部署
1.创建zabbix用户以及日志文件与授权
[root@linuxMA ~]# useradd -s /sbin/nologin zabbix
[root@linuxMA ~]# mkdir /etc/zabbix /var/log/zabbix
[root@linuxMA ~]# chown -R zabbix.zabbix /var/log/zabbix/
2.解压 zabbix-4.0.12.tar.gz
[root@linuxMA ~]# tar xf zabbix-4.0.12.tar.gz -C /usr/src/
[root@linuxMA ~]# ls /usr/src/
debug httpd-2.4.25 kernels mysql-5.7.22-linux-glibc2.12-x86_64 php-7.2.22 zabbix-4.0.12
3.配置编译
[root@linuxMA ~]# cd /usr/src/zabbix-4.0.12/
[root@linuxMA zabbix-4.0.12]# ./configure --prefix=/usr/local/zabbix --sysconfdir=/etc/zabbix/ --enable-server --enable-proxy --enable-agent --enable-ipv6 --with-mysql=/usr/bin/mysql_config --with-net-snmp --with-libcurl --with-unixodbc --with-ldap --enable-java
[root@linuxMA zabbix-4.0.12]# make && make install
4.备份配置文件
[root@linuxMA ~]# cd /etc/zabbix/
[root@linuxMA zabbix]# cp zabbix_server.conf zabbix_server.conf.bak
[root@linuxMA zabbix]# cp zabbix_agentd.conf zabbix_agentd.conf.bak
[root@linuxMA zabbix]# ls
zabbix_agentd.conf zabbix_agentd.conf.d zabbix_proxy.conf zabbix_server.conf zabbix_server.conf.d
zabbix_agentd.conf.bak zabbix_agentd.conf.origin zabbix_proxy.conf.d zabbix_server.conf.bak zabbix_server.conf.origin
5.修改主配置文件
sed -i "s@DBUser=root@DBUser=zabbix@g" /etc/zabbix/zabbix_server.conf
sed -i "s@# DBPassword=@DBPassword=zabbix@g" /etc/zabbix/zabbix_server.conf
sed –i "s@#DBSocket=/tmp/mysql.sock@ DBSocket=/tmp/mysql.sock@g" /etc/zabbix/zabbix_server.conf
sed -i "s@# DBPort=3306@DBPort=3306 @g" /etc/zabbix/zabbix_server.conf
sed -i "s@# DBHost=localhost@DBHost=localhost@g" /etc/zabbix/zabbix_server.conf
#启动zabbix服务
[root@linuxMA ~]# /usr/local/zabbix/sbin/zabbix_server
[root@linuxMA ~]# netstat -anpt |grep zabbix_server
tcp 0 0 0.0.0.0:10051 0.0.0.0:* LISTEN 1844/zabbix_server
tcp6 0 0 :::10051 :::* LISTEN 1844/zabbix_serv
6.进入mysql数据库授权zabbix
mysql> create database zabbix character set utf8;
Query OK, 1 row affected (0.02 sec)
mysql> grant all on zabbix.* to 'zabbix'@localhost identified by 'zabbix';
Query OK, 0 rows affected (0.03 sec)
mysql> flush privileges; #刷新权限
Query OK, 0 rows affected (0.00 sec)
7.退出数据库导入数据
[root@linuxMA ~]# cd /usr/src/zabbix-4.0.12/
[root@linuxMA zabbix-4.0.12]# mysql -uzabbix -pzabbix zabbix < database/mysql/schema.sql
[root@linuxMA zabbix-4.0.12]# mysql -uzabbix -pzabbix zabbix < database/mysql/images.sql
[root@linuxMA zabbix-4.0.12]# mysql -uzabbix -pzabbix zabbix < database/mysql/data.sql
8.部署zabbix到php页面
[root@linuxMA zabbix-4.0.12]# cp -rf frontends/php/ /usr/local/httpd/htdocs/zabbix/
[root@linuxMA zabbix-4.0.12]# chown -R apache:apache /usr/local/httpd/htdocs/zabbix/
9.重启http服务
[root@linuxMA ~]# /usr/local/httpd/bin/apachectl restart
四、前台操作
1.使用浏览器登陆zabbix