当前位置:   article > 正文

部署centos8及安装python2.7(dolphinscheduler1.2.1执行datax报python2.7不存在)_centos8安装python2.7

centos8安装python2.7

背景

通过海豚调度执行datax任务的时候,报错python2.7命令不存在。
原因是代码指定的版本是2.7,而centos8自带的是python3 版本。
解决方案有两种:
一:替换成python3
需要修改替换datax/bin下面的python文件,同事说比较简单,修改下datax.py中print语法就行了,加下括号,另外的py文件
用不到。
二:安装python2.7
尝试安装了下,本来也很简单,但是一直报错,所以本文也是仿照生产环境安装centos8虚拟机,复现该问题,并尝试解决。

报错
在这里插入图片描述
操作系统及python版本
输入python报命令不存在,/usr/bin下面没有python软链接,只有python3和python3.6链接
在这里插入图片描述
1.2.1代码
在这里插入图片描述

安装centos8.0.1905

下载地址

8.0.1905 64位
很明显下载最大的iso文件
在这里插入图片描述

通过VirtualBox进行安装

新建机器
在这里插入图片描述

默认在C盘,建议放其它盘,我这边C盘比较大,就放C盘,到时候安装好,导出一份做备份也一样的。
在这里插入图片描述
后续可能会在上面部署dolphinscheduler2.0,所以内存就尽可能搞大点了,可以就设1G,后面也是可以再修改的。
在这里插入图片描述
一直下一步,大小建议设置大于10G
iso文件比较大,有6G
在这里插入图片描述
设置-镜像文件
在这里插入图片描述
在这里插入图片描述
网络选择桥接模式
在这里插入图片描述

启动创建用户
点击启动,过个几分钟来到设置页面,按照提示一步步配置即可
在这里插入图片描述
请问在哪点击确认
在这里插入图片描述
关闭重新进去试试
在这里插入图片描述
关闭后,结果又重新来了一遍,不过这次显示正常
在这里插入图片描述
重启后又继续安装,没完没了…
后面直接强制退出了,移除光驱,再次启动,总算结束了死循环

在这里插入图片描述
然后弹出许可认证,点击,安装提示,选择光驱,完成配置
在这里插入图片描述
登录进来
看着图形界面好陌生…
在这里插入图片描述

配置静态IP

Ctrl+Alt+F3切换到命令行页面(Ctrl+Alt+F1切回图形界面)
在这里插入图片描述
virbr0网卡,是因为安装系统的时候附带了libvirt服务,自动生成的,它有一个固定的默认IP 地址192.168.122.1,保险起见,最后删掉libvirt服务,防止IP冲突。
删除命令

yum remove libvirt-*
  • 1

移除libvirt后,配置静态IP
在这里插入图片描述
在这里插入图片描述

BOOTPROTO=static
ONBOOT=yes
PREFIX=24
IPADDR=192.168.1.66
GATEWAY=192.168.1.1
NETMASK=255.255.255.0
DNS1=114.114.114.114
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7

重启
在这里插入图片描述
验证
在这里插入图片描述

配置xshell连接工具

在这里插入图片描述

安装python2.7

测试是否通互联网

方式一

curl https://www.baidu.com/
  • 1

curl https://www.baidu.com/
方式二

ping www.baidu.com
  • 1

在这里插入图片描述
网络是通的,可惜用不了,因为生产环境不通互联网的…现在强迫症愈发严重了!!!!!

验证环境是否和生产环境一致

在这里插入图片描述

x86_64
[root@localhost ~]# ifconfig
enp0s3: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.1.66  netmask 255.255.255.0  broadcast 192.168.1.255
        inet6 fe80::cf9b:a0e3:955b:4cff  prefixlen 64  scopeid 0x20<link>
        ether 08:00:27:ae:4d:ad  txqueuelen 1000  (Ethernet)
        RX packets 483  bytes 60582 (59.1 KiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 278  bytes 28454 (27.7 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

lo: flags=73<UP,LOOPBACK,RUNNING>  mtu 65536
        inet 127.0.0.1  netmask 255.0.0.0
        inet6 ::1  prefixlen 128  scopeid 0x10<host>
        loop  txqueuelen 1000  (Local Loopback)
        RX packets 0  bytes 0 (0.0 B)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 0  bytes 0 (0.0 B)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

[root@localhost ~]# 
[root@localhost ~]# cat /etc/redhat-release 
CentOS Linux release 8.0.1905 (Core) 
[root@localhost ~]# uname -m
x86_64
[root@localhost ~]# python
bash: python: 未找到命令...
[root@localhost ~]# python3
Python 3.6.8 (default, May 21 2019, 23:51:36) 
[GCC 8.2.1 20180905 (Red Hat 8.2.1-3)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> quit()
[root@localhost ~]# 

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34

安装python2.7

下载python2.7

python2.7.6
在这里插入图片描述
太慢了…
在这里插入图片描述
上传到服务器
在这里插入图片描述
在这里插入图片描述

安装python2.7

解压-配置-编译

[root@localhost ~]# #创建编译目录
[root@localhost ~]# mkdir -p /usr/local/python2.7
[root@localhost ~]# #解压安装包
[root@localhost ~]# tar xf /tmp/Python-2.7.6.tgz 
[root@localhost ~]# #进入解压目录,配置,指定编译目录
[root@localhost ~]# cd Python-2.7.6/
[root@localhost Python-2.7.6]#  ./configure --prefix=/usr/local/python2.7
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7

在这里插入图片描述
结果报错了,生产环境可没报错,生产环境安装很顺利,就是执行命令时候报错

报错
no acceptable C compiler found in $PATH
[root@localhost Python-2.7.6]#  ./configure --prefix=/usr/local/python2.7 
checking build system type... x86_64-unknown-linux-gnu
checking host system type... x86_64-unknown-linux-gnu
checking for --enable-universalsdk... no
checking for --with-universal-archs... 32-bit
checking MACHDEP... linux2
checking EXTRAPLATDIR... 
checking for --without-gcc... no
checking for gcc... no
checking for cc... no
checking for cl.exe... no
configure: error: in `/root/Python-2.7.6':
configure: error: no acceptable C compiler found in $PATH
See `config.log' for more details
[root@localhost Python-2.7.6]# less config.log 
[root@localhost Python-2.7.6]# 
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16

解决办法,安装gcc

yum -y install gcc
  • 1
缓存失败

在这里插入图片描述
解决办法
备份,然后将地址放开并且修改为阿里云地址,三个文件都要改

[root@localhost Python-2.7.6]# cd /etc/yum.repos.d/
[root@localhost yum.repos.d]# cp CentOS-Base.repo CentOS-Base.repo.bak
[root@localhost yum.repos.d]# cp CentOS-AppStream.repo CentOS-AppStream.repo.bak
[root@localhost yum.repos.d]# cp CentOS-Extras.repo CentOS-Extras.repo.bak
[root@localhost yum.repos.d]# vi CentOS-Base.repo
[root@localhost yum.repos.d]# vi CentOS-AppStream.repo
[root@localhost yum.repos.d]# vi CentOS-Extras.repo

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8

例:

name=CentOS-$releasever - Base
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=BaseOS&infra=$infra
#baseurl=http://mirror.centos.org/$contentdir/$releasever/BaseOS/$basearch/os/
baseurl=https://mirrors.aliyun.com/centos/$releasever/BaseOS/$basearch/os/
gpgcheck=1
enabled=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-centosofficial
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7

Base
在这里插入图片描述
APP
在这里插入图片描述
Extras
在这里插入图片描述

缓存失败,忽略这个 repo。元数据缓存已建立。

在这里插入图片描述
原因都是地址不对,首先确认地址正确,然后替换重试

https://mirrors.aliyun.com/centos/8-stream/BaseOS/x86_64/os/
  • 1

在这里插入图片描述
替换地址

[root@localhost yum.repos.d]# grep aliyun CentOS-*
CentOS-AppStream.repo:baseurl=https://mirrors.aliyun.com/centos/8-stream/AppStream/x86_64/os/
CentOS-Base.repo:baseurl=https://mirrors.aliyun.com/centos/8-stream/BaseOS/x86_64/os/
CentOS-Extras.repo:baseurl=https://mirrors.aliyun.com/centos/8-stream/extras/x86_64/os/
  • 1
  • 2
  • 3
  • 4

在这里插入图片描述

再次验证
[root@localhost yum.repos.d]# #清除缓存
[root@localhost yum.repos.d]# yum clean all
0 文件已删除
[root@localhost yum.repos.d]# #建立缓存
[root@localhost yum.repos.d]# yum makecache
  • 1
  • 2
  • 3
  • 4
  • 5

在这里插入图片描述

安装依赖

环境就像树叶,根本不存在相同的环境,连网搞 都头大…
安装成功

yum install -y openssl-devel bzip2-devel expat-devel gdbm-devel readline-devel sqlite-devel libffi-devel  
  • 1
未找到匹配的参数: gcc

yum install -y epel-release
没找到epel资源,指定IP即可

yum install -y https://mirrors.aliyun.com/epel/epel-release-latest-8.noarch.rpm
  • 1

再次安装gcc

yum install -y gcc
  • 1

在这里插入图片描述

重新配置python2.7

配置
[root@localhost yum.repos.d]# cd 
[root@localhost ~]# cd Python-2.7.6/
[root@localhost Python-2.7.6]# 
[root@localhost Python-2.7.6]# 
[root@localhost Python-2.7.6]# 
[root@localhost Python-2.7.6]#  ./configure --prefix=/usr/local/python2.7
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6

在这里插入图片描述

编译
[root@localhost Python-2.7.6]# make && make install 
  • 1
找不到make命令(太难了)

在这里插入图片描述
直接 yum install -y make安装成功,总算顺利了一下!!!!

make失败
./python -E -S -m sysconfig --generate-posix-vars
Could not find platform dependent libraries <exec_prefix>
Consider setting $PYTHONHOME to <prefix>[:<exec_prefix>]
make: *** [Makefile:468: pybuilddir.txt] 段错误 (core dumped)
  • 1
  • 2
  • 3
  • 4

查看日志,怀疑还是依赖安装不全
在这里插入图片描述
安装依赖g++ (c++),还是make失败

yum install -y  gcc-c++
  • 1

在这里插入图片描述

最后的挣扎

凌晨两点了,太伤了,下载2.7最新版本试一下,行不行都这最后一下了
在这里插入图片描述
解压、配置
在这里插入图片描述
配置
在这里插入图片描述
苍天有眼,编译结束,只不过貌似…在这里插入图片描述
看样子要到400,好想终止,但是我不敢
在这里插入图片描述
复制查看日志结果,还好是测试失败
在这里插入图片描述
终于可以安装了
在这里插入图片描述

最终结果

配置选择了./configure --enable-optimizations所以没有安装到指定目录,应该在后面把--prefix=/usr/local/python2.7拼接上去的,--enable-optimizations参数的作用就是不用自己再去建立软连接了
在这里插入图片描述

mkdir -p /usr/local/python2.7 
/configure --enable-optimizations --prefix=/usr/local/python2.7 
  • 1
  • 2

如果指定了安装目录,则需要配置环境变量,/etc/profile是针对所有用户的,单独用户配置在.bash_profile中

export PYTHON_HOME=/usr/local/python2.7
export PATH=$PYTHON_HOME/bin:$PATH
  • 1
  • 2

在这里插入图片描述

python3也未受影响
在这里插入图片描述
太难了,一个是找镜像,花了很长时间,然后就是python make花了太长时间,最终解决办法是下载最新的2.7版本,呵呵了!

声明:本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:【wpsshop博客】
推荐阅读
相关标签
  

闽ICP备14008679号