RHEL 8 配置Yum源及测试thefuck
1. 配置Yum源
RHEL系统安装完成之后,如果没有注册并购买红帽服务是无法连接到官方的Yum源的,也就无法直接使用Yum命令来安装软件包及更新系统。
[root@wuhan2020 /]# hostnamectl Static hostname: wuhan2020 Icon name: computer-laptop Chassis: laptop Machine ID: 601eca308ef84823a9e0a775d944fa23 Boot ID: 2b616f1426814536b6cd7a469718f588 Operating System: Red Hat Enterprise Linux 8.1 (Ootpa) CPE OS Name: cpe:/o:redhat:enterprise_linux:8.1:GA Kernel: Linux 4.18.0-147.el8.x86_64 Architecture: x86-64 [root@wuhan2020 /]# yum install thefuck Updating Subscription Management repositories. Unable to read consumer identity This system is not registered to Red Hat Subscription Management. You can use subscription-manager to register. Error: There are no enabled repositories in "/etc/yum.repos.d", "/etc/yum/repos.d", "/etc/distro.repos.d". [root@wuhan2020 /]# [root@wuhan2020 /]# yum update Updating Subscription Management repositories. Unable to read consumer identity This system is not registered to Red Hat Subscription Management. You can use subscription-manager to register. Error: There are no enabled repositories in "/etc/yum.repos.d", "/etc/yum/repos.d", "/etc/distro.repos.d". [root@wuhan2020 /]#
但是,我们可以禁用“Subscription Management”,然后配置成我们自己定义的Yum源,也就是Repository库。
可以自定义本地Yum源, 这个很简单,可参考之前的文档。这里我们使用阿里云开源镜像。
阿里云开源镜像
https://mirrors.aliyun.com/repo/
https://mirrors.aliyun.com/repo/
下载CentOS-Base.repo 到/etc/yum.repos.d/
cd /etc/yum.repos.d/
wget https://mirrors.aliyun.com/repo/Centos-8.repo
cd /etc/yum.repos.d/
wget https://mirrors.aliyun.com/repo/Centos-8.repo
[root@wuhan2020 /]# cd /etc/yum.repos.d/ [root@wuhan2020 yum.repos.d]# wget https://mirrors.aliyun.com/repo/Centos-8.repo --2020-02-17 15:17:20-- https://mirrors.aliyun.com/repo/Centos-8.repo Resolving mirrors.aliyun.com (mirrors.aliyun.com)... 47.246.28.228, 47.246.28.229, 47.246.28.224, ... Connecting to mirrors.aliyun.com (mirrors.aliyun.com)|47.246.28.228|:443... connected. HTTP request sent, awaiting response... 200 OK Length: 2595 (2.5K) [application/octet-stream] Saving to: ‘Centos-8.repo’ Centos-8.repo 100%[===========================================>] 2.53K --.-KB/s in 0s 2020-02-17 15:17:22 (40.7 MB/s) - ‘Centos-8.repo’ saved [2595/2595] [root@wuhan2020 yum.repos.d]# ls Centos-8.repo redhat.repo [root@wuhan2020 yum.repos.d]# mv redhat.repo redhat.repo_bak
####修改以下两个文件的Enable=0来禁用Subscription Management的提示。
[root@wuhan2020 yum.repos.d]# vi /etc/yum/pluginconf.d/product-id.conf
[root@wuhan2020 yum.repos.d]# vi /etc/yum/pluginconf.d/subscription-manager.conf
[root@wuhan2020 yum.repos.d]# vi /etc/yum/pluginconf.d/product-id.conf
[root@wuhan2020 yum.repos.d]# vi /etc/yum/pluginconf.d/subscription-manager.conf
[root@wuhan2020 yum.repos.d]# yum clean all
[root@wuhan2020 yum.repos.d]# yum makecache
[root@wuhan2020 yum.repos.d]# yum makecache
[root@wuhan2020 yum.repos.d]# yum repolist Last metadata expiration check: 0:00:25 ago on Mon 17 Feb 2020 03:21:58 PM +04. repo id repo name status AppStream CentOS-8 - AppStream - mirrors.aliyun.com 5,093 base CentOS-8 - Base - mirrors.aliyun.com 2,080 extras CentOS-8 - Extras - mirrors.aliyun.com 3 [root@wuhan2020 yum.repos.d]# yum grouplist Last metadata expiration check: 0:00:31 ago on Mon 17 Feb 2020 03:21:58 PM +04. Available Environment Groups: Server Minimal Install Workstation Custom Operating System Virtualization Host Installed Environment Groups: Server with GUI Installed Groups: Legacy UNIX Compatibility Container Management Development Tools Graphical Administration Tools Headless Management Network Servers Security Tools System Tools Available Groups: .NET Core Development RPM Development Tools Scientific Support Smart Card Support [root@wuhan2020 yum.repos.d]#
2. 安装并测试thefuck应用
需要先安装Python, Pip, Python-Devel
RHEL8默认已安装了Python3.6。
[root@wuhan2020 bin]# find /usr/bin/ -name python* /usr/bin/python3.6 /usr/bin/python3.6m /usr/bin/python3 /usr/bin/python-argcomplete-check-easy-install-script /usr/bin/python-argcomplete-tcsh [root@wuhan2020 bin]# ln -s /usr/bin/python3.6 /usr/bin/python [root@wuhan2020 /]# python -V Python 3.6.8
需要手动安装python3-devel
[root@wuhan2020 ~]# yum install python3-devel
安装Pip
[root@wuhan2020 /]# python get-pip.py Collecting pip Downloading pip-20.0.2-py2.py3-none-any.whl (1.4 MB) |████████████████████████████████| 1.4 MB 1.3 MB/s Collecting wheel Downloading wheel-0.34.2-py2.py3-none-any.whl (26 kB) Installing collected packages: pip, wheel Attempting uninstall: pip Found existing installation: pip 9.0.3 Uninstalling pip-9.0.3: Successfully uninstalled pip-9.0.3 Successfully installed pip-20.0.2 wheel-0.34.2 After the preparation environment is ready, start installing "Thefuck": Install python pip [root@wuhan2020 log]# pip -V pip 20.0.2 from /usr/local/lib/python3.6/site-packages/pip (python 3.6) Install the setuptools module [root@wuhan2020 log]# pip install -U setuptools Requirement already up-to-date: setuptools in /usr/local/lib/python3.6/site-packages (45.2.0)
安装thefuck
root@wuhan2020 ~]# python3 -m pip install thefuck Collecting thefuck Using cached thefuck-3.29-py2.py3-none-any.whl (109 kB) Collecting psutil Using cached psutil-5.6.7.tar.gz (448 kB) Requirement already satisfied: six in /usr/lib/python3.6/site-packages (from thefuck) (1.11.0) Requirement already satisfied: colorama in /usr/local/lib/python3.6/site-packages (from thefuck) (0.4.3) Requirement already satisfied: decorator in /usr/lib/python3.6/site-packages (from thefuck) (4.2.1) Requirement already satisfied: pyte in /usr/local/lib/python3.6/site-packages (from thefuck) (0.8.0) Requirement already satisfied: wcwidth in /usr/local/lib/python3.6/site-packages (from pyte->thefuck) (0.1.8) Building wheels for collected packages: psutil Building wheel for psutil (setup.py) ... done Created wheel for psutil: filename=psutil-5.6.7-cp36-cp36m-linux_x86_64.whl size=282020 sha256=d257a6b535f7e092f19dcb2e28d3940232bb33ecf2c960998c05bdcade73ff74 Stored in directory: /root/.cache/pip/wheels/b2/b3/a3/551db06cebc9141c437c6b58aa751d3670471494e9f6d1428d Successfully built psutil Installing collected packages: psutil, thefuck Successfully installed psutil-5.6.7 thefuck-3.29
配置环境变量
可以添加到bashrc或者/etc/profile文件都行。
[root@wuhan2020 /]# vi /etc/profile
###修改profile文件,在末尾下面一行内容
alias fuck='eval $(thefuck $(fc -ln -1)); history -r'
[root@wuhan2020 /]# hostnamectl Static hostname: wuhan2020 Icon name: computer-laptop Chassis: laptop Machine ID: 601eca308ef84823a9e0a775d944fa23 Boot ID: 2b616f1426814536b6cd7a469718f588 Operating System: Red Hat Enterprise Linux 8.1 (Ootpa) CPE OS Name: cpe:/o:redhat:enterprise_linux:8.1:GA Kernel: Linux 4.18.0-147.el8.x86_64 Architecture: x86-64 [root@wuhan2020 /]# hostnamcl bash: hostnamcl: command not found... [root@wuhan2020 /]# fuck hostnamectl [enter/↑/↓/ctrl+c] Static hostname: wuhan2020 Icon name: computer-laptop Chassis: laptop Machine ID: 601eca308ef84823a9e0a775d944fa23 Boot ID: 2b616f1426814536b6cd7a469718f588 Operating System: Red Hat Enterprise Linux 8.1 (Ootpa) CPE OS Name: cpe:/o:redhat:enterprise_linux:8.1:GA Kernel: Linux 4.18.0-147.el8.x86_64 Architecture: x86-64 [root@wuhan2020 /]#
=====
在安装thefuck时,有遇到如下错误,原因是未安装Python3-devel.
[root@wuhan2020 ~]# python3 -m pip install thefuck Collecting thefuck Using cached thefuck-3.29-py2.py3-none-any.whl (109 kB) Collecting psutil Using cached psutil-5.6.7.tar.gz (448 kB) Requirement already satisfied: six in /usr/lib/python3.6/site-packages (from thefuck) (1.11.0) Requirement already satisfied: decorator in /usr/lib/python3.6/site-packages (from thefuck) (4.2.1) Requirement already satisfied: colorama in /usr/local/lib/python3.6/site-packages (from thefuck) (0.4.3) Requirement already satisfied: pyte in /usr/local/lib/python3.6/site-packages (from thefuck) (0.8.0) Requirement already satisfied: wcwidth in /usr/local/lib/python3.6/site-packages (from pyte->thefuck) (0.1.8) Building wheels for collected packages: psutil Building wheel for psutil (setup.py) ... error ERROR: Command errored out with exit status 1: command: /usr/bin/python3 -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-a1ke_1aj/psutil/setup.py'"'"'; __file__='"'"'/tmp/pip-install-a1ke_1aj/psutil/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', creating build/temp.linux-x86_64-3.6 creating build/temp.linux-x86_64-3.6/psutil gcc -pthread -Wno-unused-result -Wsign-compare -DDYNAMIC_ANNOTATIONS_ENABLED=1 -DNDEBUG -O2 -g -pipe -Wall -Werror=format-security -Wp,-D_FORTIFY_SOURCE=2 -Wp,-D_GLIBCXX_ASSERTIONS -fexceptions -fstack-protector-strong -grecord-gcc-switches -m64 -mtune=generic -fasynchronous-unwind-tables -fstack-clash-protection -fcf-protection -D_GNU_SOURCE -fPIC -fwrapv -fPIC -DPSUTIL_POSIX=1 -DPSUTIL_VERSION=567 -DPSUTIL_LINUX=1 -I/usr/include/python3.6m -c psutil/_psutil_common.c -o build/temp.linux-x86_64-3.6/psutil/_psutil_common.o psutil/_psutil_common.c:9:10: fatal error: Python.h: No such file or directory #include <Python.h> ^~~~~~~~~~ compilation terminated. error: command 'gcc' failed with exit status 1 ---------------------------------------- ERROR: Failed building wheel for psutil Running setup.py clean for psutil Failed to build psutil Installing collected packages: psutil, thefuck Running setup.py install for psutil ... error ERROR: Command errored out with exit status 1: command: /usr/bin/python3 -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-a1ke_1aj/psutil/setup.py'"'"'; __file__='"'"'/tmp/pip-install-a1ke_1aj/psutil/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' install --record /tmp/pip-record-w70uqb0g/install-record.txt --single-version-externally-managed --compile --install-headers /usr/local/include/python3.6m/psutil cwd: /tmp/pip-install-a1ke_1aj/psutil/ Complete output (44 lines): …… creating build/temp.linux-x86_64-3.6 creating build/temp.linux-x86_64-3.6/psutil gcc -pthread -Wno-unused-result -Wsign-compare -DDYNAMIC_ANNOTATIONS_ENABLED=1 -DNDEBUG -O2 -g -pipe -Wall -Werror=format-security -Wp,-D_FORTIFY_SOURCE=2 -Wp,-D_GLIBCXX_ASSERTIONS -fexceptions -fstack-protector-strong -grecord-gcc-switches -m64 -mtune=generic -fasynchronous-unwind-tables -fstack-clash-protection -fcf-protection -D_GNU_SOURCE -fPIC -fwrapv -fPIC -DPSUTIL_POSIX=1 -DPSUTIL_VERSION=567 -DPSUTIL_LINUX=1 -I/usr/include/python3.6m -c psutil/_psutil_common.c -o build/temp.linux-x86_64-3.6/psutil/_psutil_common.o psutil/_psutil_common.c:9:10: fatal error: Python.h: No such file or directory #include <Python.h> ^~~~~~~~~~ compilation terminated. error: command 'gcc' failed with exit status 1 ---------------------------------------- ERROR: Command errored out with exit status 1: /usr/bin/python3 -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-a1ke_1aj/psutil/setup.py'"'"'; __file__='"'"'/tmp/pip-install-a1ke_1aj/psutil/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' install --record /tmp/pip-record-w70uqb0g/install-record.txt --single-version-externally-managed --compile --install-headers /usr/local/include/python3.6m/psutil Check the logs for full command output.
参考以下安装文档
https://github.com/nvbn/thefuck
*******VICTORY LOVES PREPARATION*******