標籤:
參考:
https://github.com/h2oai/h2o-2/wiki/Installing-python-2.7-on-centos-6.3.-Follow-this-sequence-exactly-for-centos-machine-only
http://toomuchdata.com/2012/06/25/how-to-install-python-2-7-3-on-centos-6-2/
背景:
生產環境下使用的是centos 6.3, 系統預設python2.6, 在不改變系統預設的前提下, 想額外的安裝python2.7.
所有步驟基本都複製於參考文章, 此篇僅作為筆記備查.
安裝Python2.7
步驟:
1. 配置yum國內源
cd /etc/yum.repos.dmv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backupwget http://mirrors.163.com/.help/CentOS6-Base-163.repomv CentOS6-Base-163.repo CentOS6-Base.repoyum clean allyum makecache
2. 配置python2.7源碼安裝編譯環境
yum groupinstall "Development tools"yum install zlib-develyum install bzip2-develyum install openssl-develyum install ncurses-develyum install sqlite-devel
3. 下載並編譯安裝python2.7
cd /optwget --no-check-certificate https://www.python.org/ftp/python/2.7.11/Python-2.7.11.tar.xztar xf Python-2.7.11.tar.xzcd Python-2.7.11./configure --prefix=/usr/localmake && make altinstall
注意, 是 make altinstall 而不是 make install
安裝完成後, /usr/bin/python 和 /usr/local/bin/python 應該如下
[email protected]:/opt/Python-2.7.11 ] ls -ltr /usr/bin/python*
lrwxrwxrwx 1 root root 6 Nov 16 2002 /usr/bin/python2 -> python-rwxr-xr-x 1 root root 1418 Jul 10 2013 /usr/bin/python2.6-config-rwxr-xr-x 2 root root 4864 Jul 10 2013 /usr/bin/python2.6-rwxr-xr-x 2 root root 4864 Jul 10 2013 /usr/bin/pythonlrwxrwxrwx 1 root root 16 Oct 24 15:39 /usr/bin/python-config -> python2.6-config[email protected]:/opt/Python-2.7.11 ] ls -ltr /usr/local/bin/python*-rwxr-xr-x 1 root root 6214533 Mar 19 22:46 /usr/local/bin/python2.7-rwxr-xr-x 1 root root 1674 Mar 19 22:46 /usr/local/bin/python2.7-config
4. 檢查一下$PATH, /usr/local/bin的位置應該在/usr/bin之前
[email protected] h2o]# echo $PATH/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin
5. 建立軟連結, 把 /usr/local/bin/python2.7 連結到 /usr/local/bin/python
ln -s /usr/local/bin/python2.7 /usr/local/bin/python
6. 斷開ssh, 重新ssh到伺服器, python已預設為2.7.11, yum可以正常使用
安裝pip, virtualenv
1. 安裝pip 8.1.2
因為所有的環境都在virtualenv中配置, 所以pip沒有修改, 如果預設的pip是2.6版本, 建立軟連結到/usr/local/bin/pip即可
wget https://bootstrap.pypa.io/get-pip.pypython get-pip.py
2. 安裝virtualenv
pip install virtualenv
安裝mysql
1. 安裝mysql用戶端和服務端
yum install mysqlyum install mysql-serveryum install mysql-devel
2. 配置mysql預設charset
/etc/my.cnf中加入default-character-set=utf8
3. 啟動mysql服務和設定開機啟動
service mysqld startchkconfig -add mysqldchkconfig mysqld on
4. 建立mysql root使用者
mysqladmin -u root password 123456
centos6.3安裝python2.7, pip2.7, mysql