centos7 lnmp环境搭建+iptables服务配置

lnmp指linux系统下安装nginx服务器、mysql数据库、php服务。iptables是linux下的一种防火墙。

1.linux系统:这里选的是centos7.4版本的

安装完成后,更新RPEL包,即专门针对RHEL设计的企业版附加包,有很多实用软件。

yum install epel-release  //安装rpel包

yum update  //更新Yum仓库

2.nginx的安装和配置

yum install nginx  #安装

systemctl start nginx #启动

nginx systemctl enable nginx #设置开机启动

修改nginx配置文件:

vi /etc/nginx/nginx.conf

找到server{    },修改:

server {

listen 80;

server_name www.pmhuiyilu.com pmhuiyilu.com; #域名

index index.php index.html index.htm;

root /web/pmhuiyilu;  #网站根目录文件目录

error_page 403 404 /web/404.html;

# Load configuration files for the default server block.

include /etc/nginx/default.d/*.conf;

#设置php格式的文件给php解析解析

location ~ \.php$ {

root /web/pmhuiyilu;

fastcgi_pass 127.0.0.1:9000;

fastcgi_index index.php;

fastcgi_param SCRIPT_FILENAME /web/pmhuiyilu  $fastcgi_script_name;

include fastcgi_params;

}

#404和50x的加载文件

error_page 404 /404.html;

location = /40x.html {

}

error_page 500 502 503 504 /50x.html;

location = /50x.html {

}

}

静态页面可以把php那个location ~ \.php$ {  xxx  }  这块去掉

有子域名的只需要把把这个server{}放在/etc/nginx/conf.d下,取名为xxx.conf即可加载,同时更改此文件内的域名和目录信息

3.安装及配置php7

rpm -Uvhhttps://mirror.webtatic.com/yum/el7/webtatic-release.rpm  #rpm安装php源

yum install php70w php70w-devel php70w-fpm php70w-mysql php70w-mbstring php70w-mcrypt php70w-gd php70w-imap php70w-ldap php70w-odbc php70w-pear php70w-xml php70w-xmlrpc php70w-pdo #安装php7及扩展

php -i | grep php.ini    #查看php配置文件位置

yum -yinstallphp70w-xxx #安装其他php需要的扩展模块

systemctl start php-fpm #开启php-fpm

systemctl enable php-fpm  #开机自动启动

4.安装mysql服务

下载mysql的YUM源:

wget -P /home/lisonglin http://dev.mysql.com/get/mysql57-community-release-el7-11.noarch.rpm

安装mysql:

rpm -ivh mysql57-community-release-el7-11.noarch.rpm

检查mysql的YUM源是否安装成功:

yum repolist enabled | grep "mysql.*-community.*"

查看mysql版本,执行:

yum repolist all | grep mysql

启用,ysql5.7版本:

yum-config-manager --enable mysql57-community      #将enable缓存disable是禁用(注意:任何时候,只能启用一个版本。)

查看当前的启用的 MySQL 版本:

yum repolist enabled | grep mysql

安装mysql:

yum install mysql-community-server -y

启动mysql服务:

systemctl start mysqld

设置开机自启:

systemctl enable mysqld

进入数据库:

use mysql;(如果进不去先查看默认密码:grep 'temporary password' /var/log/mysqld.log )

选择数据库:

use mysql;

修改root用户密码:

alter user '用户名'@'%' identified by '密码';

%代表允许远程登录,如果只能本地登录换成localhost

完毕,退出数据库:

quit

以上是lnmp环境的搭建。

5.iptables服务的搭建

首先检查并关闭firewall

systemctl status firewall    #查看firewall运行状态

systemctl stop firewall          #若开启则关闭firewall

systemctl disable firewall        #若开启则关闭开启自启

安装iptables

yum install iptables-services

配置iptables:vim /etc/sysconfig/iptables,在22端口那一行下加入下面3行,代表允许这几个端口开放,21端口是ftp,22端口是ssh,80端口是服务器,3306端口是mysql数据库。

-A INPUT -p tcp -m state --state NEW -m tcp --dport 22 -j ACCEPT

-A INPUT -p tcp -m state --state NEW -m tcp --dport 21 -j ACCEPT

-A INPUT -p tcp -m state --state NEW -m tcp --dport 80 -j ACCEPT

-A INPUT -p tcp -m state --state NEW -m tcp --dport 3306 -j ACCEPT

配置完,保存退出,启动iptables

systemctl start iptables

设置开启自启动:

systemctl enable iptables


最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容