Linux 安装 centos7 系统

本文介绍CentOS7的系统配置,包括防火墙、SELINUX、IPV6的关闭,以及设置静态IP和域名配置的方法。同时,提供从传统服务管理到systemctl命令的过渡指南,涵盖服务的启动、停止、重启、状态检查和自动启动设置。

centos7 下载地址:

http://mirrors.aliyun.com/centos/7/isos/x86_64/

1.systemctl命令用法

对比表,以 httpd(apache) 为例

任务旧指令新指令
使某服务自动启动chkconfig --level 3 httpd onsystemctl enable httpd.service
使某服务不自动启动chkconfig --level 3 httpd offsystemctl disable httpd.service
检查服务状态service httpd status

systemctl status httpd.service (服务详细信息)

systemctl is-active httpd.service (仅显示是否 Active)

显示所有已启动的服务chkconfig --listsystemctl list-units --type=service
启动某服务service httpd startsystemctl start httpd.service
停止某服务service httpd stopsystemctl stop httpd.service
重启某服务service httpd restartsystemctl restart httpd.service


服务


一、防火墙 CentOS 7.0默认使用的是firewall作为防火墙,这里改为iptables防火墙。

1、关闭firewall:

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


2、安装iptables防火墙

yum install iptables-services #安装

vi /etc/sysconfig/iptables #编辑防火墙配置文件

# 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
-A INPUT -m state --state NEW -m tcp -p tcp --dport 3306 -j ACCEPT
-A INPUT -j REJECT --reject-with icmp-host-prohibited
-A FORWARD -j REJECT --reject-with icmp-host-prohibited
COMMIT
:wq! #保存退出
systemctl restart iptables.service #最后重启防火墙使配置生效
systemctl enable iptables.service #设置防火墙开机启动


二、关闭SELINUX

vi /etc/selinux/config

#SELINUX=enforcing #注释掉
#SELINUXTYPE=targeted #注释掉
SELINUX=disabled #增加
:wq! #保存退出
setenforce 0 #使配置立即生效


三、常用包

yum install net-tools.x86_64
vi


四、关闭IPV6

vi /etc/sysctl.conf

添加下面的行:
net.ipv6.conf.all.disable_ipv6 =1
net.ipv6.conf.default.disable_ipv6 =1

sysctl -p

cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime

客户机只装 yum install ntpdate
yum install ntp
systemctl start ntpd
systemctl enable ntpd
chkconfig ntpd on

ntpdate -u 10.18.3.150

yum install wget bind-utils deltarpm
yum install mysql-connector-java.noarch

service cloudera-scm-server restart

sudo -u hdfs hdfs dfsadmin -safemode leave

yum -y install epel-release

yum -y install python-pip


yum install nmap-ncat.x86_64  NC服务

rpm -qa|grep mariadb 

五、设置静态IP

1、vim /etc/sysconfig/network-scripts/ifcfg-ens33

TYPE=Ethernet
PROXY_METHOD=none
BROWSER_ONLY=no
BOOTPROTO=static #将dhcp改为static
DEFROUTE=yes
IPV4_FAILURE_FATAL=no
IPV6INIT=yes
IPV6_AUTOCONF=yes
IPV6_DEFROUTE=yes
IPV6_FAILURE_FATAL=no
IPV6_ADDR_GEN_MODE=stable-privacy
NAME=ens33
UUID=3ae629c8-72a4-488b-9772-90caf8639ec7
DEVICE=ens33
ONBOOT=yes  #将no改为yes
IPADDR=192.168.157.135 #静态IP地址
NETMASK=255.255.255.0  #网络掩码
GATEWAY=192.168.157.2  #网关

service httpd restart  #使刚刚的修改生效

如果报错Failed to restart httpd.service:Unit not found. 则使用 service network restart

2、ip addr 查看是否更改

3、测试网络是否连通

[root@localhost ~]# curl www.baidu.com
curl: (6) Could not resolve host: www.baidu.com; 未知的错误

报这个错误是因为DNS的问题,所以需要修改一下DNS的配置

[root@localhost ~]# vim /etc/resolv.conf
 
// 原先的DNS
# Generated by NetworkManager
nameserver 8.8.8.8
 
// 修改后的DNS
# Generated by NetworkManager
nameserver 114.114.114.114
nameserver 8.8.8.8

六、设置域名配置

vim /etc/httpd/conf/httpd.conf

#在文件末尾添加引用
Include vhost-conf.d/*.conf
cd /etc/httpd/
mkdir vhost-conf.d
vim default.conf

#配置
<VirtualHost *:80>
    ServerName wwww.test.gm
    ServerAlias www.test.gm
    DocumentRoot /var/www/www.test.gm
    <Directory /var/www/www.test.gm>
        Require all granted
        AllowOverride All
    </Directory>
</VirtualHost>

:php的扩展配置路径为 /etc/php.d/*.ini

七、修改主机名

hostnamectl set-hostname 主机名【可永久生效】

cat /etc/hostname 【查看主机名是否设置成功,然后重新连接主机就可以看到最新的】

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值