1. 环境搭建LAMP
1.1 搭建之前的操作
1.1.1 升级系统组件到最新的版本
yum -y update
1.1.2 关闭selinux
首先查看选项
[root@localhost ~]# cat /etc/selinux/config
# This file controls the state of SELinux on the system.
# SELINUX= can take one of these three values:
# enforcing - SELinux security policy is enforced.
# permissive - SELinux prints warnings instead of enforcing.
# disabled - No SELinux policy is loaded.
SELINUX=enforcing
# SELINUXTYPE= can take one of three values:
# targeted - Targeted processes are protected,
# minimum - Modification of targeted policy. Only selected processes are protected.
# mls - Multi Level Security protection.
SELINUXTYPE=targeted
利用sed更改配置文件
[root@localhost ~]# sed -i 's/SELINUX=enforcing/SELINUX=disable/' /etc/selinux/config
确认结果
[root@localhost ~]# cat /etc/selinux/config
# This file controls the state of SELinux on the system.
# SELINUX= can take one of these three values:
# enforcing - SELinux security policy is enforced.
# permissive - SELinux prints warnings instead of enforcing.
# disabled - No SELinux policy is loaded.
SELINUX=disable
# SELINUXTYPE= can take one of three values:
# targeted - Targeted processes are protected,
# minimum - Modification of targeted policy. Only selected processes are protected.
# mls - Multi Level Security protection.
SELINUXTYPE=targeted
setenforce 0 #临时关闭命令
getenforce #检测selinux是否关闭,Disabled 为关闭
1.1.3 关闭防火墙
[root@localhost ~]# firewall-cmd --state #查看默认防火墙状态,关闭后显示not running,开启后显示running
running
systemctl stop firewalld #临时关闭firewall
systemctl disable firewalld #禁止firewall开机启动
1.2 搭建LAMP环境
1.2.1 安装所需所有软体仓库
Zabbix是建立在LAMP或者LNMP环境之上,在此为了方便就使用yum安装LAMP环境
yum install -y httpd mariadb-server mariadb php php-mysql php-gd libjpeg* php-ldap php-odbc php-pear php-xml php-xmlrpc php-mhash
rpm -qa httpd php mariadb #安装完成后检查应用版本
1.2.2 编辑httpd
vi /etc/httpd/conf/httpd.conf
1.2.3 编辑配置php,配置中国时区
vi /etc/php.ini
date.timezone = PRC # 配置时区
1.2.4 启动httpd,mysqld
systemctl start httpd #启动并加入开机自启动httpd
systemctl enable httpd
systemctl start mariadb #启动并加入开机自启动mysqld
systemctl enable mariadb
ss -anplt | grep httpd #查看httpd启动情况,80端口监控表示httpd已启动
ss -naplt | grep mysqld #查看mysqld启动情况,3306端口监控表示mysqld已启动
1.2.5 创建一个测试页,测试LAMP是否搭建成功
vi /var/www/html/index.php #创建一个测试页,并编辑
<?php
phpinfo()
?>
1.2.6 初始化mysql数据库,并配置root用户密码
mysqladmin -u root password admin123 #设置数据库root密码
mysql -u root -p #root用户登陆数据库
CREATE DATABASE zabbix character set utf8 collate utf8_bin; #创建zabbix数据库(中文编码格式)
GRANT all ON zabbix.* TO 'zabbix'@'%' IDENTIFIED BY 'admin123'; #授予zabbix用户zabbix数据库的所有权限,密码admin123
flush privileges; #刷新权限
quit #退出数据库
vi /var/www/html/index.php #修改测试页内容,测试zabbix用户是否能够登陆数据库,这个环节很重要
<?php
$link=mysql_connect('192.168.100.211','zabbix','admin123');
if($link) echo "<h1>Success!!</h1>"; #显示Success表示连接数据库成功
else echo "Fail!!";
mysql_close();
?>
为保证zabbix用户也可以登录数据库,若出现本地无法登录情况,解决方式如下:
mysql -u root -p #使用root账户登录数据库;
select user,host from mysql.user; #有空用户名称占用导致本地无法登录远程可登录
drop user ''@localhost; #删除空用户
至此LAMP配置并验证完成