歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
Linux教程網 >> Linux基礎 >> Linux技術 >> centos7的變化

centos7的變化

日期:2017/3/3 12:41:28   编辑:Linux技術
找了一個下午都不知道為什麼找不到一些命令,終於在一個地方看到了。
地址:http://www.sa-log.com/276.html
王, 帥 2015年09月24日 於
運維日志 發表
CentOS7變化很多.
首先,在安裝過程中,操作方式變化很大,mini安裝也沒有了base這個選項.也就導致非常多在CentOS6裡面的命令在7並沒法使用.
再就是,非常多的命令,也逐漸的走出了CentOS的舞台,雖然可以yum來安裝,但是,他們確實老了(ifconfig變成了ip addr,route變成了ip -route,arp變成了ip neighbor,ifconfig eth1 up變成了ip l set eth1 up,ifconfig eth1 down變成了ip l set eth1 down,netstat變成了ss).
關於命令和操作系統簡單優化的步驟如下:
———————————-大家好,我是分割線,雖然我並不華麗———————————-
網絡命令參考
ip [選項] 操作對象{link|addr|route…}
# ip link show # 顯示網絡接口信息
# ip link set eth0 upi # 開啟網卡
# ip link set eth0 down # 關閉網卡
# ip link set eth0 promisc on # 開啟網卡的混合模式
# ip link set eth0 promisc offi # 關閉網卡的混個模式
# ip link set eth0 txqueuelen 1200 # 設置網卡隊列長度
# ip link set eth0 mtu 1400 # 設置網卡最大傳輸單元
# ip addr show # 顯示網卡IP信息
# ip addr add 192.168.0.1/24 dev eth0 # 設置eth0網卡IP地址192.168.0.1
# ip addr del 192.168.0.1/24 dev eth0 # 刪除eth0網卡IP地址
# ip route list # 查看路由信息
# ip route add 192.168.4.0/24 via 192.168.0.254 dev eth0 # 設置192.168.4.0網段的網關為192.168.0.254,數據走eth0接口
# ip route add default via 192.168.0.254 dev eth0 # 設置默認網關為192.168.0.254
# ip route del 192.168.4.0/24 # 刪除192.168.4.0網段的網關
# ip route del default # 刪除默認路由
# 查看網絡接口信息
[root@test ~]# ip link
1: lo: <LOOPBACK,UP,LOWER_UP> mtu
65536 qdisc noqueue state UNKNOWN mode DEFAULT
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
2: eno16777736: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu
1500 qdisc pfifo_fast state UP mode DEFAULT qlen
1000
link/ether 00:0c:29:e9:5d:7f brd ff:ff:ff:ff:ff:ff
# 查看網卡信息
[root@test ~]# ip addr
1: lo: <LOOPBACK,UP,LOWER_UP> mtu
65536 qdisc noqueue state UNKNOWN
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
valid_lft forever preferred_lft forever
inet6 ::1/128 scope host
valid_lft forever preferred_lft forever
2: eno16777736: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu
1500 qdisc pfifo_fast state UP qlen 1000
link/ether 00:0c:29:e9:5d:7f brd ff:ff:ff:ff:ff:ff
inet 192.168.23.131/24 brd 192.168.23.255 scope global dynamic eno16777736
valid_lft 1383sec preferred_lft 1383sec
inet6 fe80::20c:29ff:fee9:5d7f/64 scope
link
valid_lft forever preferred_lft forever
# 查看路由表
[root@test ~]# ip route list
default via 192.168.23.2 dev eno16777736 proto static metric
100
192.168.23.0/24 dev eno16777736 proto kernel scope
link src 192.168.23.131 metric 100
# 添加靜態路由,因為路由已經存在了.就僅供參考吧
[root@test ~]# ip route add 192.168.23.0/24 via 192.168.23.2 dev eno16777736
RTNETLINK answers: File exists
[root@test ~]# ip route list
default via 192.168.23.2 dev eno16777736 proto static metric
100
192.168.23.0/24 dev eno16777736 proto kernel scope
link src 192.168.23.131
192.168.23.0/24 dev eno16777736 proto kernel scope
link src 192.168.23.131 metric 100
# ip route 指令對路由的修改不能保存,重啟就沒了.把 ip route 添加到 /etc/rc.local 也沒用.
# 永久靜態路由需要寫到 /etc/sysconfig/network-scripts/route-interface 文件中,比如添加兩條靜態路由:
[root@centos7 ~]echo
"10.15.150.0/24 via 192.168.150.253 dev eno16777736"
> /etc/sysconfig/network-scripts/route-eno16777736
# 系統自帶的另外一個網絡設置工具,詳細命令請自行搜索.
[root@test ~]# nmcli
Usage: nmcli [OPTIONS] OBJECT
{ COMMAND | help
}
OPTIONS
-t[erse] terse output
-p[retty] pretty output
-m[ode] tabular|multiline output mode
-f[ields] <field1,field2,...>|all|common specify fields to output
-e[scape] yes|no escape columns separators
in values
-n[ocheck] don't check nmcli and NetworkManager versions
-a[sk] ask for missing parameters
-w[ait] <seconds> set timeout waiting for finishing operations
-v[ersion] show program version
-h[elp] print this help
OBJECT
g[eneral] NetworkManager's general status and operations
n[etworking] overall networking control
r[adio] NetworkManager radio switches
c[onnection] NetworkManager's connections
d[evice] devices managed by NetworkManager
a[gent] NetworkManager secret agent or polkit agent
# 查看接口信息
[root@test ~]# nmcli con show
NAME UUID TYPE DEVICE
eno16777736 10bb4ba5-df5f-4d06-8955-e7ba28f86508
802-3-ethernet eno16777736
# 在CentOS7下面,也有tui的命令
# nmtui 命令要小心.在編輯的時候千萬別禁用了網卡.不然就慘了. 一定小心
# CentOS7重啟網卡的命令如下
systemctl restart network.service
# 在CentOS7裡面,默認是沒有network命令的,可以用如下命令來添加network服務 用於重啟網卡
yum install NetworkManager
———————————-大家好,我是分割線,雖然我並不華麗———————————-
服務的控制
CentOS 7 已經切換到 systemd,系統指令也有所變化.之前用於啟動、重啟、停止各種服務的 service 作為向後兼容的指令還能使用,但是將來可能會消失.同時,chkconfig 也改成了 systemctl 了.這裡列舉了一些常用的對應於 service 和 chkconfig 的新的 systemctl 指令.
在目前的 CentOS 7(或 RHEL 7)系統中,依然可以使用 service 指令.例如,
[root@localhost ~]# service network restart
Restarting network (via systemctl):
[ OK ]
[root@localhost ~]# service httpd restart
Redirecting to /bin/systemctl restart httpd.service
[root@localhost ~]# service sshd restart
Redirecting to /bin/systemctl restart sshd.service
但是系統會自動重定向該指令到新的指令 /bin/systemctl 來執行,並給出提示.
啟動服務:
systemctl start httpd
停止服務:
systemctl stop httpd
重啟服務(先停止,後啟動):
systemctl restart httpd
重新加載(使用新的配置文件):
systemctl reload httpd
顯示服務狀態:
systemctl status httpd
與此同時,之前用於設定系統啟動時自動運行某服務的指令 chkconfig 也改了,還是用 systemctl.
chkconfig service on
改成了,
systemctl enable httpd
掃描改動過的服務
systemctl daemon-reload
chkconfig service off
改成了,
systemctl disable httpd
檢查服務狀態的
chkconfig service
改成了,
systemctl is-enabled httpd
列舉出所有服務的指令,
chkconfig –list
改成了,
systemctl list-unit-files --type=service
以前能指定服務 runlevel 的 –levels 也沒有了.慢慢適應吧.
———————————-大家好,我是分割線,雖然我並不華麗———————————-
# 修改CentOS7網卡名稱的方法如下.
# 關於CentOS7網卡名稱的詳細介紹,請看文章底部.
# 首先,讓我們來禁用該可預測命名規則.對於這一點,你可以在啟動時傳遞”net.ifnames=0″的內核參數.這是通過編輯/etc/default/grub並加入”net.ifnames=0″到GRUBCMDLINELINUX變量來實現的.
# 還可以在 GRUB_CMDLINE_LINUX 加入ipv6.disable=1 用於關閉ipv6
# 操作步驟如下
[root@test ~]# cat /etc/default/grub
GRUB_TIMEOUT=5
GRUB_DEFAULT=saved
GRUB_DISABLE_SUBMENU=true
GRUB_TERMINAL_OUTPUT="console"
GRUB_CMDLINE_LINUX="rd.lvm.lv=centos/root rd.lvm.lv=centos/swap rhgb quiet net.ifnames=0"
GRUB_DISABLE_RECOVERY="true"
[root@test ~]# grub2-mkconfig -o /boot/grub2/grub.cfg
Generating grub configuration file ...
Found linux image: /boot/vmlinuz-3.10.0-229.el7.x86_64
Found initrd image: /boot/initramfs-3.10.0-229.el7.x86_64.img
Found linux image: /boot/vmlinuz-0-rescue-be58931139f24432a5795998159371f9
Found initrd image: /boot/initramfs-0-rescue-be58931139f24432a5795998159371f9.img
done
# 編輯 /etc/udev/rules.d/70-persistent-net.rules 文件 內容如下
[root@test ~]# cat /etc/udev/rules.d/70-persistent-ipoib.rules
# This is a sample udev rules file that demonstrates how to get udev to
# set the name of IPoIB interfaces to whatever you wish. There is a
# 16 character limit on network device names though, so don't go too nuts
#
# Important items to note: ATTR{type}=="32" is IPoIB interfaces, and the
# ATTR{address} match must start with ?* and only reference the last 8
# bytes of the address or else the address might not match on any given
# start of the IPoIB stack
#
# Note: as of rhel7, udev is case sensitive on the address field match
# and all addresses need to be in lower case.
#
# ACTION=="add", SUBSYSTEM=="net", DRIVERS=="?*", ATTR{type}=="32", ATTR{address}=="?*00:02:c9:03:00:31:78:f2", NAME="mlx4_ib3"
ACTION=="add",
SUBSYSTEM=="net", DRIVERS=="?*", ATTR{type}=="32", ATTR{address}=="?*00:02:c9:03:00:31:78:f2",
NAME="eth0"
# 重啟操作系統.
# 剩下的操作,就和CentOS6一樣了.記得修改/etc/sysconfig/network-scripts相關文件
———————————-大家好,我是分割線,雖然我並不華麗———————————-
# 如果還想使用 ifconfig 等網絡命令,可以使用yum來安裝
yum install net-tools
# 安裝系統常用的軟件包
yum -y
install strace sysstat
gcc gcc-c++ make lrzsz ntp iptraf openssl-devel libtool-ltdl unixODBC ncurses-devel bind-utils
unzip \
pcre-devel libevent-devel vim-common vim-enhanced e4fsprogs OpenIPMI OpenIPMI-tools perl-devel telnet lftp dos2unix
wget traceroute
# 把vim加入到環境變量
echo alias
vi='vim' >>
/etc/bashrc
# 添加lib目錄到 共享庫
echo "/usr/local/lib/"
>> /etc/ld.so.conf
# 修改記錄格式
echo 'export HISTTIMEFORMAT="%F %T `whoami` "'
>> /etc/profile
# 修改記錄條數
sed -i
"s/HISTSIZE=1000/HISTSIZE=999999999/"
/etc/profile
# 關閉ssh的反解
echo 'UseDNS no'
>> /etc/ssh/sshd_config
# 優化ulimit
echo -e
"*\tsoft\tnofile\t65535"
>> /etc/security/limits.conf
echo -e "*\thard\tnofile\t65535"
>> /etc/security/limits.conf
echo -e "*\tsoft\tnofile\t65535"
>> /etc/security/limits.d/20-nproc.conf
echo -e "*\thard\tnofile\t65535"
>> /etc/security/limits.d/20-nproc.conf
# 優化內核參數
echo "#-------------insert-------------"
>> /etc/sysctl.conf
echo "net.core.netdev_max_backlog = 32768"
>> /etc/sysctl.conf
echo "net.core.rmem_default = 8388608"
>> /etc/sysctl.conf
echo "net.core.rmem_max = 16777216"
>> /etc/sysctl.conf
echo "net.core.somaxconn = 32768"
>> /etc/sysctl.conf
echo "net.core.wmem_default = 8388608"
>> /etc/sysctl.conf
echo "net.core.wmem_max = 16777216"
>> /etc/sysctl.conf
echo "net.ipv4.ip_local_port_range = 5000 65000"
>> /etc/sysctl.conf
echo "net.ipv4.tcp_fin_timeout = 30"
>> /etc/sysctl.conf
echo "net.ipv4.tcp_keepalive_time = 300"
>> /etc/sysctl.conf
echo "net.ipv4.tcp_max_orphans = 3276800"
>> /etc/sysctl.conf
echo "net.ipv4.tcp_max_syn_backlog = 65536"
>> /etc/sysctl.conf
echo "net.ipv4.tcp_max_tw_buckets = 5000"
>> /etc/sysctl.conf
echo "net.ipv4.tcp_mem = 94500000 915000000 927000000"
>> /etc/sysctl.conf
echo "net.ipv4.tcp_syn_retries = 2"
>> /etc/sysctl.conf
echo "net.ipv4.tcp_synack_retries = 2"
>> /etc/sysctl.conf
echo "net.ipv4.tcp_syncookies = 1"
>> /etc/sysctl.conf
echo "net.ipv4.tcp_timestamps = 0"
>> /etc/sysctl.conf
echo "net.ipv4.tcp_tw_recycle = 1"
>> /etc/sysctl.conf
echo "net.ipv4.tcp_tw_reuse = 1"
>> /etc/sysctl.conf
/sbin/sysctl
-p
# 關閉系統不需要的服務
systemctl disable auditd.service
systemctl disable irqbalance.service
systemctl disable lvm2-monitor.service
systemctl disable postfix.service
———————————-大家好,我是分割線,雖然我並不華麗———————————-
在CentOS7,我想將分配的網絡接口名更改為別的名字.有什麼合適的方法來來重命名CentOS或RHEL7的網絡接口?
傳統上,Linux的網絡接口被枚舉為eth[0123...],但這些名稱並不一定符合實際的硬件插槽,PCI位置,USB接口數量等,這引入了一個不可預知的命名問題(例如,由於不確定的設備探測行為),這可能會導致不同的網絡配置錯誤(例如,由無意的接口改名引起的禁止接口或者防火牆旁路).基於MAC地址的udev規則在虛擬化的環境中並不有用,這裡的MAC地址如端口數量一樣無常.
CentOS/RHEL6引入了一致和可預測的網絡設備命名網絡接口的方法.這些特性可以唯一地確定網絡接口的名稱以使定位和區分設備更容易,並且在這樣一種方式下,無論是否重啟機器、過了多少時間、或者改變硬件,其名字都是持久不變的.然而,這種命名規則並不是默認在CentOS/RHEL6上開啟.
從CentOS/RHEL7起,這種可預見的命名規則變成了默認.根據這一規則,接口名稱被自動基於固件,拓撲結構和位置信息來確定.現在,即使添加或移除網絡設備,接口名稱仍然保持固定,而無需重新枚舉,和壞掉的硬件可以無縫替換.
* 基於接口類型的兩個字母前綴:
* en -- 以太網
* sl -- 串行線路IP
(slip)
* wl -- wlan
* ww -- wwan
*
* 名字類型:
* b<number>
-- BCMA總線和新書
* ccw<name>
-- CCW總線組名
* o<index>
-- 車載設備的索引號
* s<slot>[f<function>][d<dev_port>]
-- 熱插拔插槽索引號
* x<MAC>
-- MAC 地址
* [P<domain>]p<bus>s<slot>[f<function>][d<dev_port>]
*
-- PCI 位置
* [P<domain>]p<bus>s<slot>[f<function>][u<port>][..]1[i<interface>]
*
-- USB端口號鏈
新的命名方案的一個小的缺點是接口名稱相比傳統名稱有點難以閱讀.例如,你可能會發現像enp0s3名字.再者,你再也無法來控制接口名了.
如果由於某種原因,你喜歡舊的方式,並希望能夠選擇任意名稱分配給CentOS/ RHEL7的設備,你需要重寫默認的可預測的命名規則,定義基於MAC地址udev規則.
Copyright © Linux教程網 All Rights Reserved