分类目录归档:CentOS

CentOS7网卡桥接

系统版本:CentOS 7.1 x64

# cat /etc/redhat-release 
CentOS Linux release 7.1.1503 (Core) 
# uname -a
Linux localhost.localdomain 3.10.0-229.el7.x86_64 #1 SMP Fri Mar 6 11:36:42 UTC 2015 x86_64 x86_64 x86_64 GNU/Linux

 桥接前配置:

# cat /etc/sysconfig/network-scripts/ifcfg-enp2s4 
BOOTPROTO=dhcp
DEFROUTE=yes
PEERDNS=yes
PEERROUTES=yes
IPV4_FAILURE_FATAL=no
IPV6INIT=yes
IPV6_AUTOCONF=yes
IPV6_DEFROUTE=yes
IPV6_PEERDNS=yes
IPV6_PEERROUTES=yes
IPV6_FAILURE_FATAL=no
IPV6_FAILURE_FATAL=no
TYPE=Ethernet
NAME=enp2s4
UUID=65b1d8b3-2214-45ec-987f-d0f1cc0004cb
DEVICE=enp2s4
ONBOOT=yes

# cat /etc/sysconfig/network-scripts/ifcfg-enp3s5 
BOOTPROTO=dhcp
DEFROUTE=yes
PEERDNS=yes
PEERROUTES=yes
IPV4_FAILURE_FATAL=no
IPV6INIT=yes
IPV6_AUTOCONF=yes
IPV6_DEFROUTE=yes
IPV6_PEERDNS=yes
IPV6_PEERROUTES=yes
IPV6_FAILURE_FATAL=no
IPV6_FAILURE_FATAL=no
TYPE=Ethernet
NAME=enp3s5
UUID=65b1d8b3-2214-45ec-987f-d0f1cc0004cb
DEVICE=enp3s5
ONBOOT=yes

通过配置文件配置桥接:

# cd /etc/sysconfig/network-scripts

# cat ifcfg-br0      #桥接口名称为br0
TYPE=Bridge
BOOTPROTO=static
IPADDR=192.168.1.82
PREFIX=24
IPV4_FAILURE_FATAL=no
NAME=br0
DEVICE=br0
ONBOOT=yes
BRIDGE_STP=yes

# cat ifcfg-enp2s4 
TYPE=Ethernet
NAME=enp2s4
UUID=30a9efb8-2594-4596-9cde-d87c1ac06003
#HWADDR=00:1c:c4:df:db:e4
DEVICE=enp2s4
ONBOOT=yes
BRIDGE=br0

# cat ifcfg-enp3s5 
TYPE=Ethernet
NAME=enp3s5
#HWADDR=00:1c:c4:df:db:e6
UUID=65b1d8b3-2214-45ec-987f-d0f1cc0004cb
DEVICE=enp3s5
ONBOOT=yes
BRIDGE=br0

# systemctl status network.service  #重启网络服务

#查看是否失效
# ifconfig 
br0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.1.82  netmask 255.255.255.0  broadcast 192.168.71.255
        inet6 fe80::21c:c4ff:fedf:dbe4  prefixlen 64  scopeid 0x20<link>
        ether 00:1c:c4:df:db:e4  txqueuelen 0  (Ethernet)
        RX packets 1438  bytes 182390 (178.1 KiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 8  bytes 592 (592.0 B)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

enp2s4: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        ether 00:1c:c4:df:db:e4  txqueuelen 1000  (Ethernet)
        RX packets 669318  bytes 968188165 (923.3 MiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 87613  bytes 7615798 (7.2 MiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

enp3s5: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        ether 00:1c:c4:df:db:e6  txqueuelen 1000  (Ethernet)
        RX packets 87597  bytes 7613914 (7.2 MiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 666707  bytes 967793844 (922.9 MiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

# brctl show
bridge name     bridge id               STP enabled     interfaces
br0             8000.001cc4dfdbe4       no              enp2s4
                                                        enp3s5

 通过brctl配置桥接:

#安装brctl
yum install bridge-utils

# ifconfig enp2s4 down
# ifconfig enp3s5 down
# ifconfig enp2s4 0.0.0.0
# ifconfig enp3s5 0.0.0.0

# brctl addbr br0
# brctl addif br0 enp2s4
# brctl addif br0 enp3s5

# ifconfig br0 192.168.1.82 up

# brctl stp br0 off  #关闭生成树协议
# brctl show

#brctl 命令配置重启后失效,可以把相关命令添加到/etc/rc.d/rc.local 即可。

 

参考:

CentOS 6桥接网卡配置

CentOS mini版安装后基本设置

使用CentOS mini版,安装后一般做一些基本设置才能更好的使用。

版本:
http://mirrors.aliyun.com/centos/7.1.1503/isos/x86_64/CentOS-7-x86_64-Minimal-1503-01.iso

# cat /etc/redhat-release 
CentOS Linux release 7.1.1503 (Core) 

# uname -a
Linux localhost.localdomain 3.10.0-229.el7.x86_64 #1 SMP Fri Mar 6 11:36:42 UTC 2015 x86_64 x86_64 x86_64 GNU/Linux


/etc/sysconfig/network-scripts/ifcfg-enp5s0  #开机启动网卡
ONBOOT=yes

systemctl restart network.service      #重启网络服务
#或
/etc/rc.d/init.d/network restart




yum -y install wget    #安装wget

#更换阿里云yum源
mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup

wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo

#第三方源
yum install http://dl.fedoraproject.org/pub/epel/7/x86_64/e/epel-release-7-5.noarch.rpm
#或
yum install http://mirrors.ustc.edu.cn/epel/7/x86_64/e/epel-release-7-5.noarch.rpm

#生成缓存
yum makecache

#安装常用软件、工具
yum -y install vim htop

#add command ifconfig
yum -y net-tools 

#add command nslookup、dig
yum -y install bind-utils

#设置vim 别名
vi .bashrc  
alias vi='vim'

 

 

CentOS增加新硬盘

环境:
在正常运行CentOS 7.1的机器上添加一块80G的新硬盘.

系统:

# cat /etc/redhat-release 
CentOS Linux release 7.1.1503 (Core) 

# uname -a
Linux localhost.localdomain 3.10.0-229.el7.x86_64 #1 SMP Fri Mar 6 11:36:42 UTC 2015 x86_64 x86_64 x86_64 GNU/Linux

步骤:
1、关机、加硬盘、开机
2、查看硬盘是否识别到

# fdisk -l

Disk /dev/sda: 500.1 GB, 500107862016 bytes, 976773168 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk label type: dos
Disk identifier: 0xf0b1ebb0

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *        4096   209723391   104859648    7  HPFS/NTFS/exFAT
/dev/sda2       209723392   210747391      512000   83  Linux
/dev/sda3       210747392   976773119   383012864   8e  Linux LVM

Disk /dev/sdb: 80.0 GB, 80026361856 bytes, 156301488 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk label type: dos
Disk identifier: 0x947748e0

3、fdisk /dev/sdb 硬盘分区

 

# fdisk /dev/sdb
Welcome to fdisk (util-linux 2.23.2).

Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.


Command (m for help): m  #帮助
Command action
   a   toggle a bootable flag
   b   edit bsd disklabel
   c   toggle the dos compatibility flag
   d   delete a partition
   g   create a new empty GPT partition table
   G   create an IRIX (SGI) partition table
   l   list known partition types
   m   print this menu
   n   add a new partition
   o   create a new empty DOS partition table
   p   print the partition table
   q   quit without saving changes
   s   create a new empty Sun disklabel
   t   change a partition's system id
   u   change display/entry units
   v   verify the partition table
   w   write table to disk and exit
   x   extra functionality (experts only)

Command (m for help): p  #查看分区

Disk /dev/sdb: 80.0 GB, 80026361856 bytes, 156301488 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk label type: dos
Disk identifier: 0x947748e0

   Device Boot      Start         End      Blocks   Id  System

Command (m for help): n   #新建分区
Partition type:
   p   primary (0 primary, 0 extended, 4 free)
   e   extended
Select (default p): p    #主分区
Partition number (1-4, default 1): 1    #分区个数
First sector (2048-156301487, default 2048):     #使用所有,直接回车
Using default value 2048
Last sector, +sectors or +size{K,M,G} (2048-156301487, default 156301487): #直接回车
Using default value 156301487
Partition 1 of type Linux and of size 74.5 GiB is set

Command (m for help): w
The partition table has been altered!

Calling ioctl() to re-read partition table.
Syncing disks.

4、查看分区是否成功

# ll /dev/sdb*
brw-rw----. 1 root disk 8, 16 Apr 15 22:11 /dev/sdb
brw-rw----. 1 root disk 8, 17 Apr 15 22:11 /dev/sdb1

5、格式化分区

# mkfs    #系统支持的文件系统格式
mkfs         mkfs.btrfs   mkfs.cramfs  mkfs.ext2    mkfs.ext3    mkfs.ext4    mkfs.minix   mkfs.xfs 

# mkfs.xfs /dev/sdb1   #CentOS7.1 默认的文件系统为xfs,保存同系统一致

6、挂载新硬盘,并添加到 /etc/fstab自动挂载

mkdir /newdisk
mount /dev/sdb1 /newdisk

# vi /etc/fstab 

# /etc/fstab
# Created by anaconda on Wed Apr 15 18:50:24 2015
#
# Accessible filesystems, by reference, are maintained under '/dev/disk'
# See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info
#
/dev/sdb1               /newdisk            xfs     defaults        0 0

7、重启验证一下

# df -hT
Filesystem              Type      Size  Used Avail Use% Mounted on
/dev/mapper/centos-root xfs        50G  1.1G   49G   3% /
devtmpfs                devtmpfs  927M     0  927M   0% /dev
tmpfs                   tmpfs     937M     0  937M   0% /dev/shm
tmpfs                   tmpfs     937M  8.5M  928M   1% /run
tmpfs                   tmpfs     937M     0  937M   0% /sys/fs/cgroup
/dev/sdb1               xfs        75G   33M   75G   1% /newdisk
/dev/mapper/centos-home xfs       312G   33M  312G   1% /home
/dev/sda2               xfs       497M  121M  377M  25% /boot

参考文档:
http://www.linuxidc.com/Linux/2011-02/31868.htm

重置CentOS/RHEL 7中遗忘的根用户帐户密码

转自:http://netsecurity.51cto.com/art/201504/470540_all.htm

你有没有遇到过这种情况:想不起来Linux系统上的用户帐户密码?要是你忘了根用户密码,情况就更为糟糕。你无法执行任何面向整个系统的变更。要是你忘了用户密码,很容易使用根帐户来重置密码。

可要是你忘了根帐户密码,那该如何是好?你无法使用用户帐户来重置根帐户密码,因为用户帐户通常无权执行这种任务。

如何重置CentOS/RHEL 7中遗忘的根用户帐户密码?

重置CentOS 7和RHEL 7中遗忘的根用户帐户密码

万一你遇到了这种情况,这篇指南文章可以帮助你摆脱此类困境。本文将介绍如何重置RHEL 7和CentOS 7根帐户密码。

今天一大早,我打开了RHEL 7 Linux服务器,结果却发现它被锁住了。不是我搞砸了前一晚更改的密码,就是确确实实忘了密码。

如何重置CentOS/RHEL 7中遗忘的根用户帐户密码?

遗忘的根帐户密码

那么,我现在该如何是好?我应该使用用户帐户登录,试着更改根帐户密码吗?

如何重置CentOS/RHEL 7中遗忘的根用户帐户密码?

只有根用户才能设置密码

糟糕的是,我看到的信息是“Only root can specify a user name”(“只有根帐户才能指定用户名称”),我对根帐户失去了控制权。于是我打算引导进入到单一用户模式。为此,重启服务器;一旦你看到下列屏幕,就按键盘上的“e”(代表编辑)。

如何重置CentOS/RHEL 7中遗忘的根用户帐户密码?

按“e”进入编辑引导菜单

在你按了键盘上的“e”后,你会看到许多文本,文本内容会根据屏幕尺寸来缩短。

如何重置CentOS/RHEL 7中遗忘的根用户帐户密码?

Grub配置

搜寻文本“rhgb quiet”,将它换成“init=/bin/bash”,不要引号。

如何重置CentOS/RHEL 7中遗忘的根用户帐户密码?

启用外壳

一旦完成了编辑,按“ctrl+x”组合键,它会开始以指定的参数来引导。你会获得bash提示符。

如何重置CentOS/RHEL 7中遗忘的根用户帐户密码?

引导系统

现在,在单一用户模式上运行下列命令,检查根分区的状态。

# mount | grep root

如何重置CentOS/RHEL 7中遗忘的根用户帐户密码?

检查根分区挂载状态

你可能注意到,根分区被报告为“ro”(只读)。我们需要对根分区拥有读写权限,才能更改根帐户密码。

# mount -o remount,rw /

另外反复检查一下,看看根分配是否以读写权限模式来挂载。

# mount | grep root

如何重置CentOS/RHEL 7中遗忘的根用户帐户密码?

对根分区设置权限

现在你可以更改根帐户密码了,只要键入passwd命令。但这还没完。我们需要重新标记SELinux上下文。如果我们跳过重新标记整个SELinux上下文这一步,就能够使用using password来登录了。

# passwd root
[输入新密码]
[重新输入新密码]
# touch /.autorelabel

如何重置CentOS/RHEL 7中遗忘的根用户帐户密码?

重置根帐户密码

重启,再次登录进入到根帐户,看看一切是不是正常了?

# exec /sbin/init

如何重置CentOS/RHEL 7中遗忘的根用户帐户密码?

登录根用户

上图清楚地显示,我们已通过从单一用户模式重置根帐户密码,成功登录进入到RHEL 7系统。

上述几个步骤清楚地显示了如何通过从单一用户模式重置根帐户密码,登录到RHEL 7和CentOS 7机器。

英文:Single User Mode: Resetting/Recovering Forgotten Root User Account Password in RHEL/CentOS 7