当前位置:首页 » 编程语言 » pythonredhat

pythonredhat

发布时间: 2023-05-28 20:04:06

① redhat 怎么重新编译python

下载新版本的python

1
[root@local_redhat ~]# wget http://python.org/ftp/python/2.7.2/Python-2.7.2.tgz

压缩 以及编译

01
[root@local_redhat ~]# tar xvf Python-2.7.2.tar.bz2

02
[root@local_redhat Python-2.7.2]# ./configure --prefix=/usr/local/python27

03
[root@local_redhat Python-2.7.2]# make

04
[root@local_redhat Python-2.7.2]# make install

05
[root@local_redhat Python-2.7.2]# ls /usr/local/python27/ -al

06
total 28

07
drwxr-xr-x 6 root root 4096 Jul 14 00:21 .

08
drwxr-xr-x 20 root root 4096 Jul 14 00:17 ..

09
drwxr-xr-x 2 root root 4096 Jul 14 00:21 bin

10
drwxr-xr-x 3 root root 4096 Jul 14 00:21 include

11
drwxr-xr-x 4 root root 4096 Jul 14 00:21 lib

12
drwxr-xr-x 3 root root 4096 Jul 14 00:21 share

覆盖原来的python链接

1
[root@local_redhat Python-2.7.2]# mv /usr/bin/python /usr/bin/python_old

2
[root@local_redhat Python-2.7.2]# ln -s /usr/local/python27/bin/python /usr/bin/

3
[root@local_redhat Python-2.7.2]# python

4
Python 2.7.2 (default, Jul 14 2011, 00:20:14)

5
[GCC 4.1.2 20080704 (Red Hat 4.1.2-50)] on linux2

6
Type "help",
"right", "credits"
or "license"
for more information.

7
>>>

② Redhat的LINUX下使用Python里pyodbc模块插入SQL Server数据中文乱码

应该是数据库和python脚本编码方式不一样,你把脚本编码方式改成GBK或GB2312试试。

③ red hat怎么升级python

从今天开始学习Python!看了一下虚拟机RedHat中的python,发现还是原生的2.4.3,所以决定升级一下
[root@linuxidc ~]# python
Python 2.4.3 (#1, May 5 2011, 16:39:10)
[GCC 4.1.2 20080704 (Red Hat 4.1.2-50)] on linux2
Type "help", "right", "credits" or "license" for more information.
>>>
[root@linuxidc ~]#
1.下载z最新版本的python
[root@linuxidc ~]# wget http://python.org/ftp/python/2.7.6/Python-2.7.6.tgz
2.解压及编译
[root@linuxidc ~]# tar xvf Python-2.7.2.tar.bz2
[root@linuxidc Python-2.7.6]# ./configure --prefix=/usr/local/python27
[root@linuxidc Python-2.7.6]# make
[root@linuxidc Python-2.7.6]# make install
[root@linuxidc Python-2.7.6]# ls /usr/local/python27/ -al
total 28
drwxr-xr-x 6 root root 4096 Mar 21 01:01 .
drwxr-xr-x 13 root root 4096 Mar 21 01:01 ..
drwxr-xr-x 2 root root 4096 Mar 21 01:01 bin
drwxr-xr-x 3 root root 4096 Mar 21 01:01 include
drwxr-xr-x 4 root root 4096 Mar 21 01:01 lib
drwxr-xr-x 3 root root 4096 Mar 21 01:01 share
3.覆盖原有的python链接
[root@linuxidc Python-2.7.6]# mv /usr/bin/python /usr/bin/python_old
[root@linuxidc Python-2.7.6]# ln -s /usr/local/python27/bin/python /usr/bin/
[root@linuxidc Python-2.7.6]# python
Python 2.7.6 (default, Mar 21 2014, 01:00:09)
[GCC 4.1.2 20080704 (Red Hat 4.1.2-44)] on linux2
Type "help", "right", "credits" or "license" for more information.
>>>
此时已经可以正常使用python2.7了,但是因为yum是使用的2.4的版本来用的,现在输入一下yum就会报错
[root@linuxidc Python-2.7.6]# yum
There was a problem importing one of the Python moles
required to run yum. The error leading to this problem was:
No mole named yum
Please install a package which provides this mole, or
verify that the mole is installed correctly.
It's possible that the above mole doesn't match the
current version of Python, which is:
2.7.6 (default, Mar 21 2014, 01:00:09)
[GCC 4.1.2 20080704 (Red Hat 4.1.2-44)]
If you cannot solve this problem yourself, please go to
the yum faq at:
http://wiki.linux.ke.e/YumFaq
5.修改yum
[root@linuxidc Python-2.7.6]# vim /usr/bin/yum
#!/usr/bin/python #修改此处为2.4的位置
[root@linuxidc Python-2.7.6]# vim /usr/bin/yum
#!/usr/bin/python2.4
yum 可以使用了!
[root@linuxidc Python-2.7.6]# yum
Loaded plugins: rhnplugin, security
You need to give some command
usage: yum [options] COMMAND
List of Commands:
check-update Check for available package updates
clean Remove cached data
deplist List a package's dependencies
erase Remove a package or packages from your system
groupinfo Display details about a package group
groupinstall Install the packages in a group on your system
grouplist List available package groups
groupremove Remove the packages in a group from your system
help Display a helpful usage message
info Display details about a package or group of packages
info-security Returns security data for the packages listed, that affects your system
install Install a package or packages on your system
list List a package or groups of packages
list-security Returns security data for the packages listed, that affects your system
localinstall Install a local RPM
makecache Generate the metadata cache
provides Find what package provides the given value
reinstall reinstall a package
repolist Display the configured software repositories
resolvedep Determine which package provides the given dependency
search Search package details for the given string
shell Run an interactive yum shell
update Update a package or packages on your system
update-minimal Works like update, but goes to the 'newest' package match which fixes a problem that affects your system
upgrade Update packages taking obsoletes into account

options:
-h, --help show this help message and exit
-t, --tolerant be tolerant of errors
-C run entirely from cache, don't update cache
-c [config file] config file location
-R [minutes] maximum command wait time
-d [debug level] debugging output level
--showplicates show plicates, in repos, in list/search commands
-e [error level] error output level
-q, --quiet quiet operation
-v, --verbose verbose operation
-y answer yes for all questions
--version show Yum version and exit
--installroot=[path] set install root
--enablerepo=[repo] enable one or more repositories (wildcards allowed)
--disablerepo=[repo] disable one or more repositories (wildcards allowed)
-x [package], --exclude=[package]
exclude package(s) by name or glob
--disableexcludes=[repo]
disable exclude from main, for a repo or for
everything
--obsoletes enable obsoletes processing ring updates
--noplugins disable Yum plugins
--nogpgcheck disable gpg signature checking
--disableplugin=[plugin]
disable plugins by name
--enableplugin=[plugin]
enable plugins by name
--skip-broken skip packages with depsolving problems
--security Include security relevant packages
--cve=CVE Include packages needed to fix the given CVE
--bz=BZ Include packages needed to fix the given BZ
--advisory=ADVISORY Include packages needed to fix the given advisory
[root@linuxidc Python-2.7.6]#

④ RedHat4.4.1自带的python被覆盖了,怎样才能恢复回去

下载一个2.6的安装包,覆盖回去啊

⑤ 红帽八怎么安装chtony

红帽八怎么安装chtony按如下方法。
1、–首先更新RHEL上的软件包列表,并使用以下命令安装在RedHat上安装Python的前提条件。
2、更新软件包后,可以使用以下命令安装最新的Python3。
3、–安装Python之后,可以通过检查已安装的Python版本来对其进行验证。
4、如果屏幕还显示上述输出,则表示Python3.8已成功安装在RedHat系统上。

⑥ 纯干货!python 在运维中的应用 (一):批量 ssh/sftp

日常工作中需要大量、频繁地使用ssh到服务器查看、拉取相关的信息或者对服务器进行变更。目前公司大量使用的shell,但是随着逻辑的复杂化、脚本管理的精细化,shell已经不满足日常需求,于是我尝试整合工作中的需求,制作适合的工具。 由于管理制度的缺陷,我以工作流程为核心思考适合自己的运维方式,提升工作效率,把时间留给更有价值的事情。 完整代码在最后,请大家参考。

生产:4000+物理服务器,近 3000 台虚拟机。

开发环境:python3.6、redhat7.9,除了paramiko为第三方模块需要自己安装,其他的直接import即可。

批量执行操作是一把双刃剑。批量执行操作可以提升工作效率,但是随之而来的风险不可忽略。

风险案例如下:

挂载很多数据盘,通常先格式化硬盘,再挂载数据盘,最后再写入将开机挂载信息写入/etc/fstab文件。在批量lsblk检查硬盘信息的时候发现有的系统盘在/sda有的在/sdm,如果不事先检查机器相关配置是否一致直接按照工作经验去执行批量操作,会很容易造成个人难以承受的灾难。

在执行批量操作时按照惯例:格式化硬盘->挂载->开机挂载的顺序去执行,假设有的机器因为某些故障导致格式化硬盘没法正确执行。在处理这类问题的时候通常会先提取出失败的ip,并再按照惯例执行操作。运维人员会很容易忽略开机挂载的信息已经写过了,导致复写(这都是血和泪的教训)。

所以,为了避免故障,提升工作效率,我认为应当建立团队在工作上的共识,应当遵守以下原则:

当然,代码的规范也应当重视起来,不仅是为了便于审计,同时也需要便于溯源。我认为应当注意以下几点:

1、ssh no existing session,sftp超时时间设置:

在代码无错的情况下大量ip出现No existing session,排查后定位在代码的写法上,下面是一个正确的示例。由于最开始没考虑到ssh连接的几种情况导致了重写好几遍。另外sftp的实例貌似不能直接设置连接超时时间,所以我采用了先建立ssh连接再打开sftp的方法。

2、sftp中的get()和put()方法仅能传文件,不支持直接传目录:

不能直接传目录,那换个思路,遍历路径中的目录和文件,先创建目录再传文件就能达到一样的效果了。在paramiko的sftp中sftp.listdir_attr()方法可以获取远程路径中的文件、目录信息。那么我们可以写一个递归来遍历远程路径中的所有文件和目录(传入一个列表是为了接收递归返回的值)。

python自带的os模块中的os.walk()方法可以遍历到本地路径中的目录和文件。

3、多线程多个ip使用sftp.get()方法时无法并发。

改成多进程即可。

4、多个ip需要执行相同命令或不同的命令。

由于是日常使用的场景不会很复杂,所以借鉴了ansible的playbook,读取提前准备好的配置文件即可,然后再整合到之前定义的ssh函数中。


同时,我们还衍生出一个需求,既然都要读取配置,那同样也可以提前把ip地址准备在文件里。正好也能读取我们返回的执行程序的结果。

参数说明:

密码认证:

公钥认证:

可以配合 grep,awk 等命令精准过滤。

个人认为 Python 在初中级运维工作中的性质更像是工具,以提升工作效率、减少管理成本为主。可以从当前繁琐的工作中解脱出来,去 探索 更有价值的事情。python 本质上并不会减少故障的产生,所以在不同的阶段合理利用自身掌握的知识解决当前最重要的痛点,千万不要本末倒置。

⑦ 如何在linux系统中安装python

linux系统中安装python包括以下三个步骤:

⑧ redhat 4.1.2 yum用哪个版本的python

redhat老版本都是使用的python2.4

如果解决了您的拍枝陵问题请搭山采纳!
如果未解决袭戚请继续追问

热点内容
内置存储卡可以拆吗 发布:2025-05-18 04:16:35 浏览:336
编译原理课时设置 发布:2025-05-18 04:13:28 浏览:378
linux中进入ip地址服务器 发布:2025-05-18 04:11:21 浏览:612
java用什么软件写 发布:2025-05-18 03:56:19 浏览:32
linux配置vim编译c 发布:2025-05-18 03:55:07 浏览:107
砸百鬼脚本 发布:2025-05-18 03:53:34 浏览:944
安卓手机如何拍视频和苹果一样 发布:2025-05-18 03:40:47 浏览:741
为什么安卓手机连不上苹果7热点 发布:2025-05-18 03:40:13 浏览:803
网卡访问 发布:2025-05-18 03:35:04 浏览:511
接收和发送服务器地址 发布:2025-05-18 03:33:48 浏览:372