GVKun编程网logo

centos7.0之Lnmp和Lamp(centos lnmp)

26

这篇文章主要围绕centos7.0之Lnmp和Lamp和centoslnmp展开,旨在为您提供一份详细的参考资料。我们将全面介绍centos7.0之Lnmp和Lamp的优缺点,解答centoslnmp

这篇文章主要围绕centos7.0之Lnmp和Lampcentos lnmp展开,旨在为您提供一份详细的参考资料。我们将全面介绍centos7.0之Lnmp和Lamp的优缺点,解答centos lnmp的相关问题,同时也会为您带来Aliyun-Centos 7 LNMP 安装(最新版 LNMP)、Aliyun-Centos 7 LNMP安装(最新版LNMP)、CentOS 6_LAMP/LNMP--mysql的免编译安装、centos 快速搭建lnmp、lamp+zabbix3.2监控系统的实用方法。

本文目录一览:

centos7.0之Lnmp和Lamp(centos lnmp)

centos7.0之Lnmp和Lamp(centos lnmp)

首先配置防火墙
CentOS 7.0默认使用的是firewall作为防火墙
1.关闭firewall:

systemctl stop firewalld.service #停止firewall 
    systemctl disable firewalld.service #禁止firewall开机启动 

2.关闭SELINUX

vi /etc/selinux/config  
#SELINUX=enforcing #注释掉 
SELINUX=disabled #增加 
:wq! #保存退出 
setenforce 0 #使配置立即生效

Lnmp安装

1.安装Nginx

yum install yum-priorities -y  
wget http://Nginx.org/packages/centos/7/noarch/RPMS/Nginx-release-centos-7-0.el7.ngx.noarch.rpm  
rpm -ivh Nginx-release-centos-7-0.el7.ngx.noarch.rpm  
yum install Nginx

2.启动Nginx

systemctl start Nginx.service #启动Nginx 
systemctl stop Nginx.service #停止 
systemctl restart Nginx.service #重启 
systemctl enable Nginx.service #设置开机启动 

3.更改Nginx端口号(根据自己需求)

cd /etc/Nginx/conf.d/  
vim default.conf  
把listen 80改成listen 81 
然后重启Nginx 
systemctl restart Nginx.service #重启Nginx 

4.访问http://ip:81即可看到Nginx首页 5.下一步安装PHP-fpm

yum install PHP-fpm  
安装完毕后
systemctl start PHP-fpm.service #启动PHP-fpm 
systemctl enable PHP-fpm.service #设置开机启动 

6.更改Nginx配置文件识别PHP vi /etc/Nginx/conf.d/default.conf,把之前的#给去掉就可以了,顺手改一下fastcgi_param

location ~ \.PHP$ {  
        root           html;  
        fastcgi_pass   127.0.0.1:9000;  
        fastcgi_index  index.PHP;  
        fastcgi_param  SCRIPT_FILENAME  /usr/share/Nginx/html/$fastcgi_script_name;  
        include        fastcgi_params;  
    }

7.访问test.PHP

在 /usr/share/Nginx/html中新建一个test.PHP  <?PHP echo 123;?>

访问http://ip:81/test.PHP即可看到Nginx中的PHP页面

8.负载配置

进入 vi /etc/Nginx/conf.d/default.conf

upstream site{  
            server 172.16.170.138;  
            server 172.16.170.139;  
    }  
    server {  
        listen       80;  
        server_name  localhost;  

        #charset koi8-r; 
        #access_log /var/log/Nginx/log/host.access.log main; 

        location / {  
            root   /usr/share/Nginx/html;  
            index  index.html index.htm;  
            proxy_pass http://site; 
        }

9.域名修改 把上面site,localhost改为www.a.com

Lamp安装

1.安装apache

yum install httpd #根据提示,输入Y安装即可成功安装 
    systemctl start httpd.service #启动apache 
    systemctl stop httpd.service #停止apache 
    systemctl restart httpd.service #重启apache 
    systemctl enable httpd.service #设置apache开机启动 
  • 1
  • 2
  • 3
  • 4
  • 5

2.安装mariadb(MySQL)

yum install mariadb mariadb-server #询问是否要安装,输入Y即可自动安装,直到安装完成 
    systemctl start mariadb.service #启动MariaDB 
    systemctl stop mariadb.service #停止MariaDB 
    systemctl restart mariadb.service #重启MariaDB 
    systemctl enable mariadb.service #设置开机启动 

3.修改MysqL密码,安装后默认为空

修改MysqL密码:set password for 'root'@'localhost'=password('root');
MysqL授权远程连接(navicat等): grant all on *.* to root identified by 'root';

4.安装PHP以及组件,使PHP支持 MariaDB

yum install PHP PHP-MysqL PHP-gd libjpeg* PHP-ldap PHP-odbc PHP-pear PHP-xml PHP-xmlrpc PHP-mbstring PHP-bcmath PHP-mhash  
#这里选择以上安装包进行安装,根据提示输入Y回车 
systemctl restart mariadb.service #重启MariaDB 
systemctl restart httpd.service #重启apache

5.访问测试

cd /var/www/html
vi index.PHP #输入下面内容
 <?PHP
   PHPinfo();
?>
:wq! #保存退出

在客户端浏览器输入服务器IP地址,可以看到如下图所示相关的配置信息!

Aliyun-Centos 7 LNMP 安装(最新版 LNMP)

Aliyun-Centos 7 LNMP 安装(最新版 LNMP)

linux 装软件方式:
1. 源码安装:下载 wget--》解压 tar -zxvf --》配置 ./configure ---》编译 make
--> 安装 make install
2.yum 安装 一键安装包 centos 红帽 乌班图
3.rpm

l n m p

linux 版本 39.98.47.141
windows

centos 6.5 6.8 system nekwrok restart
centos 7.0+ systemctl

centos 7.4 7.5

systemctl status firewalld.service 查看防火墙
systemctl stop firewalld.service
systemctl disable firewalld.service 开机 防火墙 不自启

###Nginx####### 安装篇 ############
rpm -ivh http://nginx.org/packages/centos/7/noarch/RPMS/nginx-release-centos-7-0.el7.ngx.noarch.rpm
yum list nginx ## 查询更新列表
yum -y install nginx ##yum 安装命令

systemctl start nginx.service ## 开启 nginx 服务软件
systemctl enable nginx.service ## 加入开启启动项

###Nginx####### 测试篇 ######################
用 windows 浏览器 测试
http://39.98.47.141/(阿里云 IP)
看到:
Welcome to nginx!
表示:
Nginx 安装成功了
问题 1: 访问不了
阿里云: 安全组 --》配置 --》 克隆一个 端口 80
###########################################

=========================================== 接》》着》》安装》》PHP》》=================================================》》》》


###Php56####### 安装篇 ############
rpm -Uvh https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm

yum -y install php56w php56w-fpm php56w-opcache php56w-mysql php56w-gd libjpeg* php56w-ldap php56w-odbc php56w-pear php56w-xml php56w-xmlrpc php56w-mbstring php56w-bcmath

systemctl start php-fpm.service ## 启动 php-fpm 软件 用于 运行 PHP 脚本
systemctl enable php-fpm.service ## 加入 php-fpm 开启自动项

/etc/nginx/conf.d/ 目录下:虚拟机配置文件

nginx.conf
include

vim /etc/nginx/conf.d/default.conf

:set nu ##### 开启行数
### 将 30 行 - 36 行 前面 # 去掉
### 将 第 31 行 "html" 改成 /usr/share/nginx/html
### 将 第 34 行 "/scripts" 改成 $document_root

location ~ \.php$ {
root /usr/share/nginx/html;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}

:wq! ## 退出保存

systemctl restart nginx.service
systemctl restart php-fpm.service

vim /usr/share/nginx/html/index.php
### 编辑如下代码 测试环境脚本
<?php
echo phpinfo();
?>


###Nginx 关联 php 脚本 ####### 测试篇 ######################
用 windows 浏览器 测试
http://39.107.105.231/index.php (阿里云 IP)
看到:
PHP Version 5.6.36
表示:
Nginx 关联 php 成功了,也就是 PHP 安装成功了!
#####################################################

=========================================== 接》》着》》安装》》MySQL》》=================================================》》》》

###Mysql####### 安装篇 ############
rpm -qa|grep mariadb #查看阿里云默认安装的 mariadb 数据库 版本号:如:mariadb-libs-5.5.56-2.el7.x86_64
rpm -e --nodeps mariadb-libs-5.5.56-2.el7.x86_64 ## 卸载 mariadb-libs-5.5.56-2.el7.x86_64 包 (rpm -e --nodeps 后面跟是上个命令查询结果)

rpm -e --nodeps mariadb-libs-5.5.44-2.el7.centos.x86_64


rpm -ivh http://dev.mysql.com/get/mysql-community-release-el7-5.noarch.rpm
yum list mysql-community-server
yum -y install mysql-community-server

systemctl start mysqld.service
systemctl enable mysqld.service

mysql_secure_installation ### 初始化 mysql 系统数据 (安装系统数据库)

## 提示: Enter current password for root (enter for none):
空密码,回车

## 提示: Set root password? [Y/n]
y, 回车

## 提示: New password:
输入数据库密码,如:zha123456 (两次重复密码)

## 提示: Remove anonymous users? [Y/n]
y,回车

## 提示: Disallow root login remotely? [Y/n]
y,回车

## 提示: Remove test database and access to it? [Y/n]
y,回车

## 提示: Reload privilege tables now? [Y/n]
y,回车

### 提示: 看到:
Thanks for using MySQL!


mysql -h localhost -u root -p
Enter password:******** rootroot

mysql>
mysql>GRANT ALL PRIVILEGES ON *.* TO ''root''@''%'' IDENTIFIED BY''song123456'' WITH GRANT OPTION; ## 开启 mysql 远程访问权限
mysql>flush privileges; ## 刷新权限
mysql>exit;

systemctl stop firewalld.service

###MySQL####### 测试篇 ######################
### 提示:阿里云 安全组 克隆规则
允许 自定义 TCP 3306/3306 地址段访问 0.0.0.0/0 System created rule.
用 Navicat for MySQL 新建连接测试
表示:
Navicat for MySQL 连接阿里云 Ip 数据库,
外网访问正常,ok!!
#####################################################

=========================================== 接》》着》》安装》》Iwebshop》》=================================================》》》》

上传 iwebshop 压缩包:
FileZilla:

unzip iwebshop.zip

vim /etc/selinux/config

 

Aliyun-Centos 7 LNMP安装(最新版LNMP)

Aliyun-Centos 7 LNMP安装(最新版LNMP)

linux装软件方式:
1.源码安装:下载wget--》解压tar -zxvf --》配置 ./configure ---》编译make
-->安装 make install
2.yum安装 一键安装包 centos 红帽 乌班图
3.rpm

 


systemctl status firewalld.service ##查看防火墙
systemctl stop firewalld.service ##停止防火墙
systemctl disable firewalld.service ##开机自启服务 删除

###Nginx#######安装篇############
rpm -ivh http://Nginx.org/packages/centos/7/noarch/RPMS/Nginx-release-centos-7-0.el7.ngx.noarch.rpm
yum list Nginx ##查询更新列表
yum -y install Nginx ##yum安装命令

systemctl start Nginx.service ##开启Nginx服务软件
systemctl enable Nginx.service ##加入开启启动项

###Nginx#######测试篇######################
用windows浏览器 测试
http://39.107.105.231/(阿里云IP)
看到:
Welcome to Nginx!
表示:
Nginx安装成功了
问题1: 访问不了
阿里云: 安全组 --》配置 --》 克隆一个 端口 80
###########################################

===========================================接》》着》》安装》》PHP》》=================================================》》》》


###PHP56#######安装篇############
rpm -Uvh https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm

yum -y install PHP56w PHP56w-fpm PHP56w-opcache PHP56w-MysqL PHP56w-gd libjpeg* PHP56w-ldap PHP56w-odbc PHP56w-pear PHP56w-xml PHP56w-xmlrpc PHP56w-mbstring PHP56w-bcmath

systemctl start PHP-fpm.service ## 启动 PHP-fpm 软件 用于 运行PHP脚本
systemctl enable PHP-fpm.service ## 加入 PHP-fpm 开启自动项

/etc/Nginx/conf.d/ 目录下: 虚拟机配置文件

vim /etc/Nginx/conf.d/default.conf

:set nu #####开启行数
###将30行-36行 前面 # 去掉
###将 第31行 "html" 改成 /usr/share/Nginx/html
###将 第34行 "/scripts" 改成 $document_root

location ~ \.PHP$ {
root /usr/share/Nginx/html;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.PHP;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}

:wq! ##退出保存

systemctl restart Nginx.service
systemctl restart PHP-fpm.service

vim /usr/share/Nginx/html/index.PHP
###编辑如下代码 测试环境脚本
<?PHP
echo PHPinfo();
?>


###Nginx关联PHP脚本#######测试篇######################
用windows浏览器 测试
http://39.107.105.231/index.PHP (阿里云IP)
看到:
PHP Version 5.6.36
表示:
Nginx关联PHP成功了,也就是PHP安装成功了!
#####################################################

===========================================接》》着》》安装》》MysqL》》=================================================》》》》

###MysqL#######安装篇############
rpm -qa|grep mariadb #查看阿里云默认安装的mariadb数据库 版本号:如:mariadb-libs-5.5.56-2.el7.x86_64
rpm -e --nodeps mariadb-libs-5.5.56-2.el7.x86_64 ##卸载mariadb-libs-5.5.56-2.el7.x86_64包 (rpm -e --nodeps 后面跟是上个命令查询结果)

rpm -e --nodeps mariadb-libs-5.5.44-2.el7.centos.x86_64


rpm -ivh http://dev.MysqL.com/get/MysqL-community-release-el7-5.noarch.rpm
yum list MysqL-community-server
yum -y install MysqL-community-server

systemctl start MysqLd.service
systemctl enable MysqLd.service

MysqL_secure_installation ###初始化 MysqL系统数据(安装系统数据库)

##提示: Enter current password for root (enter for none):
空密码,回车

##提示: Set root password? [Y/n]
y,回车

##提示: New password:
输入数据库密码,如:zha123456 (两次重复密码)

##提示: Remove anonymous users? [Y/n]
y,回车

##提示: disallow root login remotely? [Y/n]
y,回车

##提示: Remove test database and access to it? [Y/n]
y,回车

##提示: Reload privilege tables Now? [Y/n]
y,回车

###提示: 看到:
Thanks for using MysqL!


MysqL -h localhost -u root -p
Enter password:******** test18580

MysqL>
MysqL>GRANT ALL PRIVILEGES ON *.* TO ‘root‘@‘%‘ IDENTIFIED BY ‘zha123456‘ WITH GRANT OPTION; ##开启MysqL远程访问权限
MysqL>flush privileges; ##刷新权限
MysqL>exit;

systemctl stop firewalld.service

###MysqL#######测试篇######################
###提示: 阿里云 安全组 克隆规则
允许 自定义 TCP 3306/3306 地址段访问 0.0.0.0/0 System created rule.
用Navicat for MysqL 新建连接测试
表示:
Navicat for MysqL 连接阿里云Ip数据库,
外网访问正常,ok!!
#####################################################

===========================================接》》着》》安装》》Iwebshop》》=================================================》》》》

上传iwebshop压缩包:
FileZilla:

unzip iwebshop.zip

vim /etc/selinux/config

##############################################################Nginx 显示浏览Index目录方法 # # #Nginx.conf的http下添加下面3条 # #autoindex on; #开启Nginx目录浏览功能 # #autoindex_exact_size off; #文件大小从KB开始显示 # #autoindex_localtime on; #显示文件修改时间为服务器本地时间 ###############################################################

CentOS 6_LAMP/LNMP--mysql的免编译安装

CentOS 6_LAMP/LNMP--mysql的免编译安装

LAMP/LNMP--mysql的免编译安装步骤:这里安装的5.1.73版本

1.下载免编译的二进制包cd /usr/local/src wget http://mirrors.sohu.com/mysql/MySQL-5.1/mysql-5.1.73-linux-x86_64-glibc23.tar.gz  ---这里安装的是64位 wget http://mirrors.sohu.com/mysql/MySQL-5.5/mysql-5.5.54-linux2.6-x86_64.tar.gz     --- 5.5_64位二进制包

以上任选其一即可


2.解压包 tar zxvf mysql-5.1.73-linux-x86_64-glibc23.tar.gz
3.制作程序目录 rm -fr /usr/local/mysql mv mysql-5.1.73 /usr/local/mysql
4.创建mysql运行需要的账户mysql和mysql的数据存放目录 useradd -s /sbin/nologin -M mysql mkdir -p /data/mysql chown -R mysql:mysql /data/mysql
5.mysql的初始化 cd /usr/local/mysql ./scripts/mysql_install_db --user=mysql --datadir=/data/mysql 检查初始化是否OK: echo $? 显示为 0即OK,或者是查看下面两步的状态,都显示OK即为OK Installing MySQL system tables... OK Filling help tables... OK
6.配置 cd support-files/ cp my-large.cnf /etc/my.cnf 若之前存在my.cnf,则将其覆盖
7.制作启动脚本 cp mysql.server /etc/init.d/mysqld chmod 755 /etc/init.d/mysqld vim !$ ,编辑下面两行basedir和datadir配置 basedir= /usr/local/mysql datadir= /data/mysql
8.启动服务并设为开机启动 chkconfig --add mysqld     ( chekconfig 后面跟的是两个英文状态下的减号) chkconfig mysqld on /etc/init.d/mysqld start
查看启动状态: ps aux |grep mysql netstat -lnp |grep mysql

centos 快速搭建lnmp、lamp+zabbix3.2监控系统

centos 快速搭建lnmp、lamp+zabbix3.2监控系统

centos 快速搭建lnmp、lamp+zabbix3.2监控系统

所安装版本MysqL 5.6 PHP5.5 zabbix3.2

centos7 lnmp+zabbix3.2 脚本

#!/bin/bash
if[$(rpm-qiMysqL-community-release-el7-5.noarch|wc-l)-lt2];then
rpm-Uvhhttp://repo.MysqL.com//MysqL-community-release-el7-5.noarch.rpm
if[$?-ne0];then
echo"MysqL-releaseerr"
exit
fi
fi
yuminstall-yepel-release
if[$?-ne0];then
echo"epel-releaseerr"
exit
fi
if[$(rpm-qiwebtatic-release-7-3.noarch|wc-l)-lt2];then
rpm-ivhhttps://mirror.webtatic.com/yum/el7/webtatic-release.rpm
if[$?-ne0];then
echo"webtatic-releaseerr"
exit
fi
fi
yum-yinstallopensslOpenIPMI-libsunixODBClibaioiksemelfpingnet-snmpnet-snmp-utilsMysqLMysqL-serverMysqL-develPHP55wPHP55w-gdPHP55w-xmlPHP55w-MysqLPHP55w-mbstringPHP55w-bcmathperl-DBIcurllibcurl-develnet-snmp-devellibssh2libssh2-devellibxml2libxml2-develPHP55w-fpmNginx
if[$?-ne0];then
echo"yuminstallerr"
exit
fi
if[$(rpm-qizabbix-release-3.2-1.el7.noarch|wc-l)-lt2];then
rpm-Uvhhttp://repo.zabbix.com/zabbix/3.2/rhel/7/x86_64/zabbix-release-3.2-1.el7.noarch.rpm
if[$?-ne0];then
echo"zabbix-releaseerr"
exit
fi
fi
yum-yinstallwgetzabbix-server-MysqLzabbix-web-MysqLzabbix-agentzabbix-getzabbix-sender
if[$?-ne0];then
echo"zabbixinstallerr"
exit
fi
cat>>/etc/PHP.ini<<EOF
soap.wsdl_cache_enabled=1
max_input_time=600
max_execution_time=300
date.timezone=Asia/Shanghai
post_max_size=32M
memory_limit=128M
mbstring.func_overload=1
EOF
sed-i"/symbolic-links=0/a\character_set_server=utf8"/etc/my.cnf
cat>/etc/Nginx/Nginx.conf<<EOF
userNginx;
worker_processes1;

error_log/var/log/Nginx/error.logwarn;
pid/var/run/Nginx.pid;


events{
worker_connections1024;
}


http{
include/etc/Nginx/mime.types;
default_typeapplication/octet-stream;

log_formatmain'\$remote_addr-\$remote_user[\$time_local]"\$request"'
'\$status\$body_bytes_sent"\$http_referer"'
'"\$http_user_agent""\$http_x_forwarded_for"';

access_log/var/log/Nginx/access.logmain;

sendfileon;
#tcp_nopushon;

keepalive_timeout65;

#gzipon;

include/etc/Nginx/conf.d/*.conf;
}
EOF

cat>/etc/Nginx/conf.d/default.conf<<EOF
server{
listen80;
server_namelocalhost;

#charsetkoi8-r;

#access_loglogs/host.access.logmain;

location/{
root/usr/share/zabbix;
indexindex.PHPindex.htmlindex.htm;
}

#error_page404/404.html;

#redirectservererrorpagestothestaticpage/50x.html
#
error_page500502503504/50x.html;
location=/50x.html{
roothtml;
}

#proxythePHPscriptstoApachelisteningon127.0.0.1:80
#
#location~\.PHP${
#proxy_passhttp://127.0.0.1;
#}

#passthePHPscriptstoFastCGIserverlisteningon127.0.0.1:9000
#
location~\.PHP${
root/usr/share/zabbix;
fastcgi_pass127.0.0.1:9000;
fastcgi_indexindex.PHP;
fastcgi_paramSCRIPT_FILENAME\$document_root\$fastcgi_script_name;
includefastcgi_params;
}
location~*^.+\.(jpg|jpeg|gif|png|bmp)${
access_logoff;
rootopencart;
expires30d;
break;
}
}
EOF
/bin/systemctlrestartMysqL.service
echo"createdatabasezabbixcharactersetutf8;"|MysqL
echo"grantallprivilegesonzabbix.*tozabbix@localhostidentifiedby'zabbix';"|MysqL
echo"grantallprivilegesonzabbix.*tozabbix@'%'identifiedby'zabbix';"|MysqL
cat>>/etc/services<<EOF
zabbix-agent10050/tcpZabbixAgent
zabbix-agent10050/udpZabbixAgent
zabbix-trapper10051/tcpZabbixTrapper
zabbix-trapper10051/udpZabbixTrapper
EOF
sed-i's/^DBUser=.*$/DBUser=zabbix/g'/etc/zabbix/zabbix_server.conf
sed-i's/^.*DBPassword=.*$/DBPassword=zabbix/g'/etc/zabbix/zabbix_server.conf
cd/usr/share/doc/zabbix-server-MysqL-3.2.1
zcatcreate.sql.gz|MysqL-urootzabbix
cd/tmp
wgethttp://caspian.dotconf.net/menu/Software/SendEmail/sendEmail-v1.56.tar.gz
if[$?-ne0];then
echo"wgetsendEmailerr"
exit
fi
tarxvzfsendEmail-v1.56.tar.gz
cpsendEmail-v1.56/sendEmail/usr/local/bin/
chmod+x/usr/local/bin/sendEmail
chown-Rzabbix.zabbix/usr/lib/zabbix/alertscripts
cat>/usr/lib/zabbix/alertscripts/SendEmail.sh<<EOF
#!/bin/bash

LOGFILE="/tmp/Email.log"
:>"\$LOGFILE"
exec1>"\$LOGFILE"
exec2>&1

SMTP_server='$1'#SMTP服务器
username='$2'#用户名
password='$3'#密码
from_email_address='$4'#发件人Email地址
to_email_address="\$1"#收件人Email地址,zabbix传入的第一个参数
message_subject_utf8="\$2"#邮件标题,zabbix传入的第二个参数
message_body_utf8="\$3"#邮件内容,zabbix传入的第三个参数

#转换邮件标题为GB2312,解决邮件标题含有中文,收到邮件显示乱码的问题。
message_subject_gb2312=\`iconv-tGB2312-fUTF-8<<EOF
\$message_subject_utf8
EOF\`
[\$?-eq0]&&message_subject="\$message_subject_gb2312"||message_subject="\$message_subject_utf8"

#转换邮件内容为GB2312
message_body_gb2312=\`iconv-tGB2312-fUTF-8<<EOF
\$message_body_utf8
EOF\`
[\$?-eq0]&&message_body="\$message_body_gb2312"||message_body="\$message_body_utf8"

#发送邮件
sendEmail='/usr/local/bin/sendEmail'
set-x
\$sendEmail-s"\$SMTP_server"-xu"\$username"-xp"\$password"-f"\$from_email_address"-t"\$to_email_address"-u"\$message_subject"-m"\$message_body"-omessage-content-type=text-omessage-charset=gb2312
EOF
chmod+x/usr/lib/zabbix/alertscripts/SendEmail.sh
cd/usr/share/zabbix/fonts
mvgraphfont.ttfgraphfont.ttf.back
wgethttp://qkadownload.qkagame.com/msyh.ttf
if[$?-ne0];then
echo"wgetmsyherr"
exit
fi
mvmsyh.ttfgraphfont.ttf
chmod777graphfont.ttf
systemctlstartzabbix-server
systemctlstartNginx.service
systemctlstartPHP-fpm.service
systemctlstartzabbix-agent
systemctlenablezabbix-server.service
systemctlenablezabbix-agent.service
systemctlenableNginx.service
systemctlenablePHP-fpm.service
firewall-cmd--permanent--add-port=80/tcp
firewall-cmd--permanent--add-port=10051/tcp
firewall-cmd--permanent--add-port=10050/tcp
firewall-cmd--reload

centos7 lamp+zabbix3.2 脚本

#/bin/bash
if[$(rpm-qiMysqL-community-release-el7-5.noarch|wc-l)-lt2];then
rpm-Uvhhttp://repo.MysqL.com//MysqL-community-release-el7-5.noarch.rpm
if[$?-ne0];then
echo"MysqL-releaseerr"
exit
fi
fi
yuminstall-yepel-release
if[$?-ne0];then
echo"epel-releaseerr"
exit
fi
if[$(rpm-qiwebtatic-release-7-3.noarch|wc-l)-lt2];then
rpm-ivhhttps://mirror.webtatic.com/yum/el7/webtatic-release.rpm
if[$?-ne0];then
echo"webtatic-releaseerr"
exit
fi
fi
yum-yinstallopensslOpenIPMI-libsunixODBClibaioiksemelfpingnet-snmpnet-snmp-utilshttpdMysqLMysqL-serverMysqL-develPHP55wPHP55w-gdPHP55w-xmlPHP55w-MysqLPHP55w-mbstringPHP55w-bcmathperl-DBIcurllibcurl-develnet-snmp-devellibssh2libssh2-devellibxml2libxml2-devel
if[$?-ne0];then
echo"yuminstallerr"
exit
fi
if[$(rpm-qizabbix-release-3.2-1.el7.noarch|wc-l)-lt2];then
rpm-Uvhhttp://repo.zabbix.com/zabbix/3.2/rhel/7/x86_64/zabbix-release-3.2-1.el7.noarch.rpm
if[$?-ne0];then
echo"zabbix-releaseerr"
exit
fi
fi
yum-yinstallwgetzabbix-server-MysqLzabbix-web-MysqLzabbix-agentzabbix-getzabbix-sender
if[$?-ne0];then
echo"zabbix-installerr"
exit
fi
cat>>/etc/PHP.ini<<EOF
soap.wsdl_cache_enabled=1
max_input_time=600
max_execution_time=300
date.timezone=Asia/Shanghai
post_max_size=32M
memory_limit=128M
mbstring.func_overload=1
EOF
sed-i"/symbolic-links=0/a\character_set_server=utf8"/etc/my.cnf
cat>>/etc/httpd/conf.d/zabbix.conf<<EOF
#ZabbixmonitoringsystemPHPwebfrontend
#

Alias/zabbix/usr/share/zabbix

<Directory"/usr/share/zabbix">
OptionsFollowSymLinks
AllowOverrideNone
Orderallow,deny
Allowfromall
</Directory>

<Directory"/usr/share/zabbix/conf">
Orderdeny,allow
Denyfromall
<files*.PHP>
Orderdeny,allow
Denyfromall
</files>
</Directory>

<Directory"/usr/share/zabbix/api">
Orderdeny,allow
Denyfromall
</files>
</Directory>

<Directory"/usr/share/zabbix/include">
Orderdeny,allow
Denyfromall
</files>
</Directory>

<Directory"/usr/share/zabbix/include/classes">
Orderdeny,allow
Denyfromall
</files>
</Directory>
EOF
/bin/systemctlrestartMysqL.service
echo"createdatabasezabbixcharactersetutf8;"|MysqL
echo"grantallprivilegesonzabbix.*tozabbix@localhostidentifiedby'zabbix';"|MysqL
echo"grantallprivilegesonzabbix.*tozabbix@'%'identifiedby'zabbix';"|MysqL
cat>>/etc/services<<EOF
zabbix-agent10050/tcpZabbixAgent
zabbix-agent10050/udpZabbixAgent
zabbix-trapper10051/tcpZabbixTrapper
zabbix-trapper10051/udpZabbixTrapper
EOF
sed-i's/^DBUser=.*$/DBUser=zabbix/g'/etc/zabbix/zabbix_server.conf
sed-i's/^.*DBPassword=.*$/DBPassword=zabbix/g'/etc/zabbix/zabbix_server.conf
cd/usr/share/doc/zabbix-server-MysqL-3.2.1
zcatcreate.sql.gz|MysqL-urootzabbix
cd/tmp
wgethttp://caspian.dotconf.net/menu/Software/SendEmail/sendEmail-v1.56.tar.gz
if[$?-ne0];then
echo"wgetsendEmailerr"
exit
fi
tarxvzfsendEmail-v1.56.tar.gz
cpsendEmail-v1.56/sendEmail/usr/local/bin/
chmod+x/usr/local/bin/sendEmail
chown-Rzabbix.zabbix/usr/lib/zabbix/alertscripts
cat>/usr/lib/zabbix/alertscripts/SendEmail.sh<<EOF
#!/bin/bash

LOGFILE="/tmp/Email.log"
:>"\$LOGFILE"
exec1>"\$LOGFILE"
exec2>&1

SMTP_server='$1'#SMTP服务器
username='$2'#用户名
password='$3'#密码
from_email_address='$4'#发件人Email地址
to_email_address="\$1"#收件人Email地址,zabbix传入的第一个参数
message_subject_utf8="\$2"#邮件标题,zabbix传入的第二个参数
message_body_utf8="\$3"#邮件内容,zabbix传入的第三个参数

#转换邮件标题为GB2312,解决邮件标题含有中文,收到邮件显示乱码的问题。
message_subject_gb2312=\`iconv-tGB2312-fUTF-8<<EOF
\$message_subject_utf8
EOF\`
[\$?-eq0]&&message_subject="\$message_subject_gb2312"||message_subject="\$message_subject_utf8"

#转换邮件内容为GB2312
message_body_gb2312=\`iconv-tGB2312-fUTF-8<<EOF
\$message_body_utf8
EOF\`
[\$?-eq0]&&message_body="\$message_body_gb2312"||message_body="\$message_body_utf8"

#发送邮件
sendEmail='/usr/local/bin/sendEmail'
set-x
\$sendEmail-s"\$SMTP_server"-xu"\$username"-xp"\$password"-f"\$from_email_address"-t"\$to_email_address"-u"\$message_subject"-m"\$message_body"-omessage-content-type=text-omessage-charset=gb2312
EOF
chmod+x/usr/lib/zabbix/alertscripts/SendEmail.sh
cd/usr/share/zabbix/fonts
mvgraphfont.ttfgraphfont.ttf.back
wgethttp://qkadownload.qkagame.com/msyh.ttf
if[$?-ne0];then
echo"wgetmsyherr"
exit
fi
mvmsyh.ttfgraphfont.ttf
chmod777graphfont.ttf
systemctlstartzabbix-server
systemctlstarthttpd
systemctlstartzabbix-agent
systemctlenablezabbix-server.service
systemctlenablezabbix-agent.service
systemctlenablehttpd.service
firewall-cmd--permanent--add-port=80/tcp
firewall-cmd--permanent--add-port=10051/tcp
firewall-cmd--permanent--add-port=10050/tcp
firewall-cmd--reload

使用方法:

给脚本可执行权限chmod+x脚本文件
数据默认用户名密码zabbix发邮件脚本名字:SendEmail.sh登陆zabbixweb账号密码admin:zabbix
./zabbix_lamp.shsmtp.test.comadmin123456admin@test.com
./zabbix_lnmp.shsmtp.test.comadmin123456admin@test.com
lnmp+zabbix访问lamp+zabbix访问http://ip/zabbix
centos6脚本名字zabbix_lamp_6.shzabbix_lnmp_6.sh

zabbix web配置以lamp+zabbix 为实例:

wKiom1g-KofhxutnAACPFmRK0Q0504.png-wh_50

wKioL1g-KoiQaLjTAADSN18U46w463.png-wh_50

wKiom1g-KonyL_AWAACgXC4eS50416.png-wh_50

wKioL1g-KoqiYTK_AACAMvD5ynA424.png-wh_50

wKiom1g-KorgT3WLAAC4Yewn2fY409.png-wh_50

wKioL1g-KouC1d1iAACL8fqHjDI306.png-wh_50

wKioL1g-KouhmFI3AAA-v3lscFo499.png-wh_50

中文设置默认图像微软雅黑

wKioL1g-K5DC8X_YAACp1aMFK6Q910.png-wh_50

wKiom1g-K5DShFMOAACOduoZkhc828.png-wh_50

zabbix 邮件配置

3.2邮件配置必须添加

参数{ALERT.SENDTO}

{ALERT.SUBJECT}

{ALERT.MESSAGE}

wKiom1g-MBbgvjqJAACiwumnfXs893.png-wh_50

打开默认动作测试报警

wKiom1g-MnbzVIh4AABo8rhD4GU852.png-wh_50

wKiom1g-NEfD9-ioAABXWLKegAA469.png-wh_50

wKioL1g-MnfyXYz9AADBk2EF_m8883.png-wh_50

wKiom1g-MnfzNsl5AACUIANtuoE685.png-wh_50

wKiom1g-MnezRtqfAAA0_6jS8fE731.png-wh_50

wKioL1g-MnjizESjAAA7aTs16Ho729.png-wh_50

wKioL1g-MnjyUlM6AABGO-gN1MY768.png-wh_50

关闭zabbix_agent 看是否正常发邮件

centos7/bin/systemctl stop zabbix-agent.service

centos6 servicezabbix-agent stop

所有脚本放到附件

今天关于centos7.0之Lnmp和Lampcentos lnmp的讲解已经结束,谢谢您的阅读,如果想了解更多关于Aliyun-Centos 7 LNMP 安装(最新版 LNMP)、Aliyun-Centos 7 LNMP安装(最新版LNMP)、CentOS 6_LAMP/LNMP--mysql的免编译安装、centos 快速搭建lnmp、lamp+zabbix3.2监控系统的相关知识,请在本站搜索。

本文标签: