pythonredhat
下載新版本的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
如果解決了您的拍枝陵問題請搭山採納!
如果未解決襲戚請繼續追問