一.常用命令
1.查看Linux内核版本的命令
方法一:
命令: uname -a
作用: 查看系统内核版本号及系统名称
方法二:
命令: cat /proc/version
作用: 查看目录"/proc"下version的信息,也可以得到当前系统的内核版本号及系统名称
补充说明:
/proc文件系统,它不是普通的文件系统,而是系统内核的映像,也就是说,该目录中的文件是存放在系统内存之中的,它以文件系统的方式为访问系统内核数据的操作提供接口。而我们使用命令“uname -a"的信息就是从该文件获取的,当然用方法二的命令直接查看它的内容也可以达到同等效果.另外,加上参数"a"是获得详细信息,如果不加参数为查看系统名称。
2.下载文件保存当前目录命令:
wget http://mirrors.163.com/centos/7/os/x86_64/Packages/yum-metadata-parser-1.1.4-10.el7.x86_64.rpm
二.常见问题
1.linux执行开启图形界面命令,报命令未发现:
[root@localhost ~]# startx
-bash: startx: command not found
2.如何安装Linux图形界面:
[root@localhost ~]# yum -y groupinstall"Server with GUI"
3.用yum安装程序报命令未注册:
[root@localhost ~]# yum -y groupinstall"Server with GUI"
Loaded plugins: langpacks, product-id,search-disabled-repos, subscription-manager
This system is not registered to Red HatSubscription Management. You can use subscription-manager to register.
There are no enabled repos.
Run"yum repolist all" to see the repos you have.
Youcan enable repos with yum-config-manager --enable <repo>
原因:Red Hat Enterprise Linux Server(RHEL) 的yum服务是付费的,因为没有付费,所以无法使用yum安装软件,如RHEL想安装LNMP必须要先按此教程设置好yum,并可以正常使用后才可以安装LNMP一键安装包,会提示如下错误:This system is not registered to Red HatSubscription Management. You can use subscription-manager to register. 或如下错误信息:This system is not registered with RHN. RHNsupport will be disabled.
解决方法:
执行:rpm-qa|grep yum|xargs rpm -e --nodeps 将yum卸载掉
cat /etc/issue && uname -a 看一下系统版本号和系统位数
3.yum如何卸载重装
a.查看linux系统内核版本:
[root@localhost~]# uname -a
Linuxlocalhost.localdomain 3.10.0-327.el7.x86_64 #1 SMP Thu Oct 29 17:29:29 EDT 2015x86_64 x86_64 x86_64 GNU/Linux
b.找到对应的位yum安装包:
进入http://mirrors.163.com/centos网站,比如我的linux系统为redhat7:http://mirrors.163.com/centos/7/os/x86_64/Packages/
c.查看系统预装的yum rpm包:
[root@localhost~]# rpm -qa|grep yum
yum-3.4.3-132.el7.noarch
yum-langpacks-0.4.2-4.el7.noarch
yum-rhn-plugin-2.0.1-5.el7.noarch
yum-utils-1.1.31-34.el7.noarch
yum-metadata-parser-1.1.4-10.el7.x86_64
d.卸载上面预装的rpm包:
[root@localhost~]# rpm -aq|grep yum|xargs rpm -e --nodeps
warning:/etc/yum/pluginconf.d/langpacks.conf saved as/etc/yum/pluginconf.d/langpacks.conf.rpmsave
再执行yum命令,会报错表示被卸载
[root@localhost~]# yum
-bash:/usr/bin/yum: No such file or directory
e.查看yum配置:
[root@localhost~]# ls /etc/yum* -ld
drwxr-xr-x.6 root root 95 Jul 27 17:43 /etc/yum
-rw-r--r--.1 root root 970 Nov 15 2016 /etc/yum.conf
drwxr-xr-x.2 root root 4096 Jul 31 08:06 /etc/yum.repos.d
e.更改yum仓库:
[root@localhost~]# cd /etc/yum.repos.d/
[root@localhostyum.repos.d]#
wget http://mirrors.163.com/.help/CentOS7-Base-163.repo
--2017-07-2709:36:35-- http://mirrors.163.com/.help/CentOS7-Base-163.repo
Resolvingmirrors.163.com (mirrors.163.com)... 123.58.190.209, 123.58.190.228
Connectingto mirrors.163.com (mirrors.163.com)|123.58.190.209|:80... connected.
HTTPrequest sent, awaiting response... 200 OK
Length:1572 (1.5K) [application/octet-stream]
Saving to:釩entOS7-Base-163.repo?
100%[=====================================>]1,572 --.-K/s in 0s
2017-07-2709:36:35 (144 MB/s) - 釩entOS7-Base-163.repo?saved[1572/1572]
从http://mirrors.163.com/centos/7/os/x86_64/Packages/下載前面卸载的centos的rpm包:
yum-3.4.3-132.el7.noarch
yum-langpacks-0.4.2-4.el7.noarch
yum-rhn-plugin-2.0.1-5.el7.noarch
yum-utils-1.1.31-34.el7.noarch
yum-metadata-parser-1.1.4-10.el7.x86_64
命令分别如下:
wget http://mirrors.163.com/centos/7/os/x86_64/Packages/yum-3.4.3-150.el7.centos.noarch.rpm
wget http://mirrors.163.com/centos/7/os/x86_64/Packages/yum-langpacks-0.4.2-7.el7.noarch.rpm
wget http://mirrors.163.com/centos/7/os/x86_64/Packages/yum-rhn-plugin-2.0.1-6.el7.noarch.rpm
wget http://mirrors.163.com/centos/7/os/x86_64/Packages/yum-utils-1.1.31-40.el7.noarch.rpm
wget http://mirrors.163.com/centos/7/os/x86_64/Packages/yum-metadata-parser-1.1.4-10.el7.x86_64.rpm
f.检查rpm包依赖:
[root@localhostyum.repos.d]# rpm -ivh yum-*
warning:yum-langpacks-0.4.2-7.el7.noarch.rpm: Header V3 RSA/SHA256 Signature, key IDf4a80eb5: NOKEY
error:Failed dependencies:
yum >= 3.0 is needed byyum-langpacks-0.4.2-7.el7.noarch
yum >= 3.4.3-143 is needed byyum-utils-1.1.31-40.el7.noarch
yum >= 3.2.19-15 is needed byyum-rhn-plugin-2.0.1-6.el7.noarch
原因:安装yum-*需要将yum升级到yum 3.0或以上版本,本案例中yum rpm遗漏下载了:yum-3.4.3-132.el7.noarch
[root@localhostyum.repos.d]# rpm -ivh yum-*
warning:yum-3.4.3-150.el7.centos.noarch.rpm: Header V3 RSA/SHA256 Signature, key IDf4a80eb5: NOKEY
error:Failed dependencies:
python-urlgrabber >= 3.10-8 isneeded by yum-3.4.3-150.el7.centos.noarch
yum-plugin-fastestmirror is needed byyum-3.4.3-150.el7.centos.noarch
下载依赖:
python-urlgrabber-3.10-8.el7.noarch.rpm
yum-plugin-fastestmirror-1.1.31-40.el7.noarch.rpm
命令如下:
wget http://mirrors.163.com/centos/7/os/x86_64/Packages/python-urlgrabber-3.10-8.el7.noarch.rpm
wget http://mirrors.163.com/centos/7/os/x86_64/Packages/yum-plugin-fastestmirror-1.1.31-40.el7.noarch.rpm
e.安装python-urlgrabber依赖
[root@localhost yum.repos.d]# rpm -ivhpython-urlgrabber-3.10-8.el7.noarch.rpm
warning:python-urlgrabber-3.10-8.el7.noarch.rpm: Header V3 RSA/SHA256 Signature, key IDf4a80eb5: NOKEY
Preparing... ################################# [100%]
file /usr/lib/python2.7/site-packages/urlgrabber/grabber.py from installof python-urlgrabber-3.10-8.el7.noarch conflicts with file from packagepython-urlgrabber-3.10-7.el7.noarch
file /usr/lib/python2.7/site-packages/urlgrabber/grabber.pyc frominstall of python-urlgrabber-3.10-8.el7.noarch conflicts with file from packagepython-urlgrabber-3.10-7.el7.noarch
file /usr/lib/python2.7/site-packages/urlgrabber/grabber.pyo frominstall of python-urlgrabber-3.10-8.el7.noarch conflicts with file from packagepython-urlgrabber-3.10-7.el7.noarch
原因:python-urlgrabber-3.10-7安装已经存在
[root@localhost yum.repos.d]# rpm -qapython-urlgrabber
python-urlgrabber-3.10-7.el7.noarch
卸载:python-urlgrabber-3.10-7
[root@localhost yum.repos.d]# rpm-e python-urlgrabber
安装:python-urlgrabber-3.10-8
[root@localhost yum.repos.d]# rpm -ivhpython-urlgrabber-3.10-8.el7.noarch.rpm
warning:python-urlgrabber-3.10-8.el7.noarch.rpm: Header V3 RSA/SHA256 Signature, key IDf4a80eb5: NOKEY
Preparing... #################################[100%]
Updating / installing...
1:python-urlgrabber-3.10-8.el7 ################################# [100%]
f.安装yum包:
[root@localhost yum.repos.d]# rpm -ivhyum-*
warning: yum-3.4.3-150.el7.centos.noarch.rpm:Header V3 RSA/SHA256 Signature, key ID f4a80eb5: NOKEY
Preparing... ################################# [100%]
Updating / installing...
1:yum-metadata-parser-1.1.4-10.el7 ################################# [17%]
2:yum-plugin-fastestmirror-1.1.31-4################################# [33%]
3:yum-3.4.3-150.el7.centos ################################# [ 50%]
4:yum-langpacks-0.4.2-7.el7 ################################# [ 67%]
5:yum-rhn-plugin-2.0.1-6.el7 ################################# [ 83%]
6:yum-utils-1.1.31-40.el7 ################################# [100%]
g.清空与建立yum缓存:
[root@localhost yum.repos.d]# yum cleanall
Loaded plugins: fastestmirror, langpacks,product-id, search-disabled-repos, subscription-manager
This system is not registered to Red HatSubscription Management. You can use subscription-manager to register.
Repository base is listed more than oncein the configuration
Repository updates is listed more thanonce in the configuration
Repository extras is listed more thanonce in the configuration
Repository centosplus is listed more thanonce in the configuration
Cleaning repos: base extras updates
Cleaning up everything
[root@localhost yum.repos.d]# yummakecache
Loaded plugins: fastestmirror, langpacks,product-id, search-disabled-repos, subscription-manager
This system is not registered to Red HatSubscription Management. You can use subscription-manager to register.
Repository base is listed more than oncein the configuration
Repository updates is listed more thanonce in the configuration
Repository extras is listed more thanonce in the configuration
Repository centosplus is listed more thanonce in the configuration
http://mirrors.163.com/centos/%24releasever/os/x86_64/repodata/repomd.xml:[Errno 14] HTTP Error 404 - Not Found
Trying other mirror.
To address this issue please refer to thebelow knowledge base article
解决方案:
a、下载yum源:
#wget http://mirrors.163.com/.help/CentOS7-Base-163.repo
修改repo源:
[root@localhost ~]# viCentOS7-Base-163.repo
# CentOS-Base.repo
#
# The mirror system uses the connectingIP address of the client and the
# update status of each mirror to pickmirrors that are updated to and
# geographically close to theclient. You should use this for CentOSupdates
# unless you are manually picking othermirrors.
#
# If the mirrorlist= does not work foryou, as a fall back you can try the
# remarked out baseurl= line instead.
#
#
[base]
name=CentOS-$releasever - Base - 163.com
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=os
baseurl=http://mirrors.163.com/centos/$releasever/os/$basearch/
gpgcheck=1
gpgkey=http://mirrors.163.com/centos/RPM-GPG-KEY-CentOS-7
#released updates
[updates]
name=CentOS-$releasever - Updates -163.com
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=updates
baseurl=http://mirrors.163.com/centos/$releasever/updates/$basearch/
gpgcheck=1
gpgkey=http://mirrors.163.com/centos/RPM-GPG-KEY-CentOS-7
#additional packages that may be useful
[extras]
name=CentOS-$releasever - Extras -163.com
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=extras
baseurl=http://mirrors.163.com/centos/$releasever/extras/$basearch/
gpgcheck=1
gpgkey=http://mirrors.163.com/centos/RPM-GPG-KEY-CentOS-7
#additional packages that extendfunctionality of existing packages
[centosplus]
name=CentOS-$releasever - Plus - 163.com
baseurl=http://mirrors.163.com/centos/$releasever/centosplus/$basearch/
gpgcheck=1
enabled=0
gpgkey=http://mirrors.163.com/centos/RPM-GPG-KEY-CentOS-7
上面变量$releasever和$basearch其中$releasever的值表示当前Linux系统的发行版本,可以通过rpm -qicentos-release命令查看;将文件中的$releasever替換成liunx版本号。$basearch是我们的系统硬件架构(CPU指令集),使用命令arch获取;
运行yumclean all(等同于 yum cleanheaders ; yum cleanpackages):
[root@localhost yum.repos.d]# yum cleanall
Loaded plugins: fastestmirror, langpacks,product-id, search-disabled-repos, subscription-manager
This system is not registered to Red HatSubscription Management. You can use subscription-manager to register.
Cleaning repos: base extras updates
Cleaning up everything
运行makecache生成缓存:
[root@localhost yum.repos.d]# yummakecache
Loaded plugins: fastestmirror, langpacks,product-id, search-disabled-repos, subscription-manager
This system is not registered to Red HatSubscription Management. You can use subscription-manager to register.
base |3.6 kB 00:00:00
extras |3.4 kB 00:00:00
updates | 3.4 kB 00:00:00
(1/12): base/x86_64/group_gz | 155 kB 00:00:00
(2/12): base/x86_64/primary_db |5.6 MB 00:00:00
(3/12): base/x86_64/other_db |2.4 MB 00:00:00
(4/12): extras/x86_64/prestodelta | 149 kB 00:00:00
(5/12): extras/x86_64/primary_db | 191 kB 00:00:01
(6/12): extras/x86_64/other_db |903 kB 00:00:00
(7/12): extras/x86_64/filelists_db |1.1 MB 00:00:01
(8/12): updates/x86_64/prestodelta | 954 kB 00:00:00
(9/12): updates/x86_64/primary_db | 7.8 MB 00:00:01
(10/12): updates/x86_64/filelists_db |4.4 MB 00:00:01
(11/12): base/x86_64/filelists_db |6.6 MB 00:00:07
(12/12): updates/x86_64/other_db | 93 MB 00:00:15
Determining fastest mirrors
Metadata Cache Created
2.安装yum软件(更新yum软件:#yum update):
[root@localhost yum.repos.d]# yum installtelnet
Loaded plugins: fastestmirror, langpacks,product-id, search-disabled-repos, subscription-manager
This system is not registered to Red HatSubscription Management. You can use subscription-manager to register.
Loading mirror speeds from cachedhostfile
Resolving Dependencies
--> Running transaction check
---> Package telnet.x86_641:0.17-60.el7 will be installed
--> Finished Dependency Resolution
Dependencies Resolved
===============================================================================================================================================================================================
Package Arch Version Repository Size
===============================================================================================================================================================================================
Installing:
telnet x86_64 1:0.17-60.el7 base 63 k
Transaction Summary
===============================================================================================================================================================================================
Install 1 Package
Total download size: 63 k
Installed size: 113 k
Is this ok [y/d/N]: y
Downloading packages:
warning:/var/cache/yum/x86_64/$releasever/base/packages/telnet-0.17-60.el7.x86_64.rpm:Header V3 RSA/SHA256 Signature, key ID f4a80eb5: NOKEY
Public key fortelnet-0.17-60.el7.x86_64.rpm is not installed
telnet-0.17-60.el7.x86_64.rpm | 63 kB 00:00:00
Retrieving key fromhttp://mirrors.163.com/centos/RPM-GPG-KEY-CentOS-7
Importing GPG key 0xF4A80EB5:
Userid : "CentOS-7 Key (CentOS 7 Official Signing Key)<security@centos.org>"
Fingerprint: 6341 ab27 53d7 8a78 a7c2 7bb124c6 a8a7 f4a8 0eb5
From : http://mirrors.163.com/centos/RPM-GPG-KEY-CentOS-7
Is this ok [y/N]: y
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
Warning: RPMDB altered outside of yum.
Installing : 1:telnet-0.17-60.el7.x86_64 1/1
Verifying :1:telnet-0.17-60.el7.x86_64 1/1
Installed:
telnet.x86_64 1:0.17-60.el7
Complete!
3.Linux系统\Centos没有网卡eth0配置文件怎么办?
n 临时解决方案:
linux下面设置ip地址是通过ifconfig命令来临时设置IP地址。
命令格式:ifconfig 设备名 IP 地址
[root@localhost ~]# ifconfig eth0 192.168.10.187
SIOCSIFADDR: No such device
eth0: ERROR while getting interfaceflags: No such device
注意:
1)设置后会立即生效,不需要重启网卡服务(重启网卡服务临时解决方案设置会立即失 效)
2)通过ifconfig即可查看当前网卡的IP地址。
问题:ifconfig eth0 192.168.10.187如错误说明,ech0网卡不存在。
SIOCSIFADDR: No such device
eth0: ERROR while getting interfaceflags: No such device
解决方案:
进入网卡配置目: /etc/sysconfig/network-scripts/下,将 ifcfg-lo 回环接口配置文件,拷贝一份改名为ifcfg-ech0既可。
命令:
[root@localhost ~]# cd/etc/sysconfig/network-scripts/
[root@localhost network-scripts]# ls -all
total 240
drwxr-xr-x. 2 root root 4096 Aug 9 09:32 .
drwxr-xr-x. 7 root root 4096 Jul 27 10:10 ..
-rw-r--r--. 1 root root 288 Jul 27 09:09 ifcfg-eno16777736
-rw-r--r--. 1 root root 254 Sep 16 2015 ifcfg-lo
lrwxrwxrwx. 1 root root 24 Jul 27 09:03 ifdown ->../../../usr/sbin/ifdown
-rwxr-xr-x. 1 root root 627 Sep 16 2015 ifdown-bnep
-rwxr-xr-x. 1 root root 5817 Sep 16 2015 ifdown-eth
-rwxr-xr-x. 1 root root 6196 Jun 24 2015 ifdown-ib
[root@localhost network-scripts]# cpifcfg-lo ifcfg-ech0
[root@localhost network-scripts]# ls -all
total 244
drwxr-xr-x. 2 root root 4096 Aug 10 07:31 .
drwxr-xr-x. 7 root root 4096 Jul 27 10:10 ..
-rw-r--r--. 1 root root 254 Aug 10 07:31 ifcfg-ech0
-rw-r--r--. 1 root root 288 Jul 27 09:09 ifcfg-eno16777736
-rw-r--r--. 1 root root 254 Sep 16 2015 ifcfg-lo
n 永久解决方案:
1.编辑网卡配置文件:/etc/sysconfig/network-scripts/ifcfg-ech0 设置网卡配置
修改前:
[root@localhost network-scripts]# more/etc/sysconfig/network-scripts/ifcfg-ech0
DEVICE=lo
IPADDR=127.0.0.1
NETMASK=255.0.0.0
NETWORK=127.0.0.0
# If you're having problems with gatedmaking 127.0.0.0/8 a martian,
# you can change this to something else(255.255.255.255, for example)
BROADCAST=127.255.255.255
ONBOOT=yes
NAME=loopback
修改后:
[root@localhost network-scripts]# more/etc/sysconfig/network-scripts/ifcfg-ech0
TYPE=Ethernet
BOOTPROTO=static
DEFROUTE=yes
IPADDR=192.168.10.187
NETMASK=255.255.255.0
GATEWAY=192.168.10.1
NETWORK=192.168.10.1
BROADCAST=127.255.255.255
IPV4_FAILURE_FATAL=no
IPV6INIT=yes
IPV6_AUTOCONF=yes
IPV6_DEFROUTE=yes
IPV6_FAILURE_FATAL=no
NAME=eno16777736
UUID=6367ea5f-bba0-4a20-819d-9255d8200177
DEVICE=ech0
ONBOOT=yes
PEERDNS=yes
PEERROUTES=yes
IPV6_PEERDNS=yes
IPV6_PEERROUTES=yes
(该图转载jingyan.baidu.com)
2.设置好网卡配置之后,需要把网络服务重启一下。输入如下命令:
service network restart