参考:
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.d mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup wget http://mirrors.163.com/.help/CentOS6-Base-163.repo mv CentOS6-Base-163.repo CentOS6-Base.repo yum clean all yum makecache
2. 配置python2.7源码安装编译环境
yum groupinstall "Development tools" yum install zlib-devel yum install bzip2-devel yum install openssl-devel yum install ncurses-devel yum install sqlite-devel
3. 下载并编译安装python2.7
cd /opt wget --no-check-certificate https://www.python.org/ftp/python/2.7.11/Python-2.7.11.tar.xz tar xf Python-2.7.11.tar.xz cd Python-2.7.11 ./configure --prefix=/usr/local make && make altinstall
注意, 是 make altinstall 而不是 make install
安装完成后, /usr/bin/python 和 /usr/local/bin/python 应该如下
root@lg1:/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/python lrwxrwxrwx 1 root root 16 Oct 24 15:39 /usr/bin/python-config -> python2.6-config root@lg1:/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之前
root@openstack 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.py python get-pip.py
2. 安装virtualenv
pip install virtualenv
安装mysql
1. 安装mysql客户端和服务端
yum install mysql yum install mysql-server yum install mysql-devel
2. 配置mysql默认charset
/etc/my.cnf中加入default-character-set=utf8
3. 启动mysql服务和设置开机启动
service mysqld start chkconfig --add mysqld chkconfig mysqld on
4. 创建mysql root用户
mysqladmin -u root password 123456