CentOS7环境搭建

本机环境: windows 10 专业版 。 
linux环境:
VMware-workstation-full-12.5.7.20721.exe
CentOS-7-x86_64-DVD-1511.iso
Xshell_5.0.1339p.exe
Xftp-5.0.1233.exe

----------------------------------------本章重点网络环境配置-------------------------------------------
CentOS安装参考:https://www.jianshu.com/p/e5497f8faf03
CentOS网络配置参考:https://blog.csdn.net/Alen_xiaoxin/article/details/58716577

--------------------------------目的在于,为了保证多台虚拟机通讯----------------------------------
依赖命令安装:
 gcc
安装nginx需要先将官网下载的源码进行编译,编译依赖gcc环境,如果没有gcc环境,需要安装gcc。
命令:yum -y install gcc-c++ 或者 yum -y install gcc gcc-c++
 PCRE
PCRE(Perl Compatible Regular Expressions)是一个Perl库,包括 perl 兼容的正则表达式库。nginx的http模块使用pcre来解析正则表达式,所以需要在linux上安装
pcre库。
命令:yum install -y pcre pcre-devel
 zlib
zlib库提供了很多种压缩和解压缩的方式,nginx使用zlib对http包的内容进行gzip,所以需要在linux上安装zlib库。
命令:yum install -y zlib zlib-devel
 openssl
OpenSSL 是一个强大的安全套接字层密码库,囊括主要的密码算法、常用的密钥和证书封装管理功能及SSL协议,并提供丰富的应用程序供测试或其它目的使用。
nginx不仅支持http协议,还支持https(即在ssl协议上传输http),所以需要在linux安装openssl库。
命令:yum install -y openssl openssl-devel

防火墙设置:CentOS 7.0默认使用的是firewall作为防火墙
1.编辑防火墙配置文件,开启22端口(远程登录端口)、80端口、3306端口。
  1.1或者在firewall正常运行的情况下输入以下命令。
  命令:firewall-cmd --zone=public --add-port=80/tcp --permanent #添加80端口
  命令:firewall-cmd --zone=public --add-port=3306/tcp --permanent #添加3306端口
------------显示success的话就代表已成功加入,重启VPS既可-----------------------
  1.2如果想检查相应端口是否开启,先重启firewalld
  命令:systemctl restart firewalld #重启firewalld,要不然下一步查询会返回NO
  命令:firewall-cmd --query-port=80/tcp --zone=public #查询80端口是否开启
------------返回no既未开启,显示Yes为已开启-----------------------------------
  1.3启动firewall
  命令:systemctl start firewalld
  1.4 开机启动firewall
  命令:systemctl enable firewalld

详细参考:https://www.5yun.org/10074.html

如果想换iptables防火墙,操作如下
2关闭firewall,禁止firewall开机启动:
命令:systemctl stop firewalld.service (关闭firewall)
命令:systemctl disable firewalld.service (禁止firewall开机启动)
  2.1安装iptables防火墙
  命令:yum install iptables-services
  2.2编辑防火墙配置文件,开启22端口(远程登录端口)、80端口、3306端口。
  # Firewall configuration written by system-config-firewall
  # Manual customization of this file is not recommended.
  *filter
  :INPUT ACCEPT [0:0]
  :FORWARD ACCEPT [0:0]
  :OUTPUT ACCEPT [0:0]
  -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
  -A INPUT -p icmp -j ACCEPT
  -A INPUT -i lo -j ACCEPT
  -A INPUT -m state --state NEW -m tcp -p tcp --dport 22 -j ACCEPT
  -A INPUT -m state --state NEW -m tcp -p tcp --dport 80 -j ACCEPT ---添加在22端口下面
  -A INPUT -m state --state NEW -m tcp -p tcp --dport 3306 -j ACCEPT ---添加在22端口下面
  -A INPUT -j REJECT --reject-with icmp-host-prohibited
  -A FORWARD -j REJECT --reject-with icmp-host-prohibited
  COMMIT
-------------------按esc键,再输入 :wq! 保存退出-----------------
  2.3最后重启防火墙使配置生效
  命令:systemctl restart iptables.service
  2.4设置防火墙开机启动
  命令:systemctl enable iptables.service
  2.5特别注意:装了千万不要卸载:可以关闭,再停掉服务,再禁用开机启动
  2.5.1关闭iptables防火墙
  命令:systemctl stop iptables.service
  2.5.2停掉服务
  命令:chkconfig iptables off
  2.5.3设置开机不启动
  命令:systemctl disable iptables.service
  2.5.4要想开启,反着来一遍,把disable改为enable,off改为on,stop改为start即可

posted @ 2018-12-17 11:47  mvp_cyh  阅读(197)  评论(0编辑  收藏  举报