CentOS6.5+python2.7+nginx+mysql配置

CentOS6.5安装

VMware+CentOS6.5(默认路径安装)

Python2.7安装

CentOS6.5系统默认Python版本是Python2.6.6,但目前主流是Python2.7,因此有必要进行配置。
参考链接:https://blog.csdn.net/Seven__Lau/article/details/79309349

python升级

1.下载新python安装包

  • 下载安装依赖的相关
[root@localhost ~]# yum install vim gcc make wget -y
[root@localhost ~]# yum install openssl-devel zlib-devel readline-devel sqlite-devel -y 
  • 下载
[root@localhost ~]# wget https://www.python.org/ftp/python/2.7.10/Python-2.7.10.tgz
  • 解压
[root@localhost ~]# tar -zxvf Python-2.7.10.tgz

2.编译安装

[root@localhost ~]# cd Python-2.7.10
[root@localhost python27]# ./configure --enable-shared --enable-loadable-sqlite-extensions \ --prefix=/usr/local/python27(指定的python安装目录) --with-zlib --with-ssl
[root@localhost python27]# vim ./Modules/Setup    
# 这一行内容,去掉注释
#zlib zlibmodule.c -I$(prefix)/include -L$(exec_prefix)/lib -lz
[root@localhost python27]# make && make install

3.查看python版本信息是否更新 python -V
4.python2.7替换旧版本

[root@localhost python27]# cd /usr/bin/
[root@localhost bin]# ls python* -l
-rwxr-xr-x. 2 root root 9032 Nov 22  2013 python
lrwxrwxrwx. 1 root root    6 Jul 20 07:18 python2 -> python
-rwxr-xr-x. 2 root root 9032 Nov 22  2013 python2.6

[root@localhost bin]# mv /usr/bin/python /usr/bin/python2.6.6
[root@localhost bin]# ln -s /home/monkey/hou/python27/bin/python2.7 /usr/bin/python

[root@localhost bin]# ls python* -l
lrwxrwxrwx. 1 root root   40 Jul 20 09:49 python -> /home/monkey/hou/python27/bin/python2.7
lrwxrwxrwx. 1 root root    6 Jul 20 07:18 python2 -> python
-rwxr-xr-x. 2 root root 9032 Nov 22  2013 python2.6
-rwxr-xr-x. 2 root root 9032 Nov 22  2013 python2.6.6

5.再次验证python2.7是否安装成功

[root@localhost ~]# python
python: error while loading shared libraries: libpython2.7.so.1.0: cannot open shared object file: No such file or directory
[root@localhost ~]# vim /etc/ld.so.conf
> include ld.so.conf.d/*.conf
> python的目录/lib
yum兼容问题

1.问题

[root@localhost ~]# yum
 There was a problem importing one of the Python modules
 required to run yum. The error leading to this problem was:
 No module named yum
 Please install a package which provides this module, or verify that the module is installed correctly.
 ... ... ...

2.解决

[root@localhost ~]# vim /usr/bin/yum
#!/usr/bin/python   =》#!/usr/bin/python2.6.6

3.验证

[root@localhost ~]# yum repolist
Loaded plugins: fastestmirror, refresh-packagekit, security
Loading mirror speeds from cached hostfile
pip安装

1.下载

[root@localhost ~]# wget https://bootstrap.pypa.io/get-pip.py
[root@localhost ~]# python get-pip.py

2.建立软链接

[root@localhost ~]# ln -s /home/monkey/hou/python27/bin/pip2.7 /usr/bin/pip

Nginx安装

1.安装依赖

yum install gcc-c++  
yum -y install pcre*  
yum -y install openssl*

2.下载nginx

[root@localhost ~]# wget http://nginx.org/download/nginx-1.14.0.tar.gz

3.解压&编译

[root@localhost ~]# tar -zxvf nginx-1.14.0.tar.gz 

4.进入nginx目录&设置安装目录

1. nginx-1.14.0
2. ./configure --with-http_stub_status_module --prefix=【/usr/local/nginx】(安装目录)

其中参数 –with-http_stub_status_module 是为了启用 nginx 的 NginxStatus 功能,用来监控 Nginx 的当前状态。

5.编译

[root@localhost nginx-1.14.0]# make
[root@localhost nginx-1.14.0]# make install

6.启动

安装成功后 /opt/nginx 目录下有四个子目录分别是:conf、html、logs、sbin。

cd /usr/local/nginx/sbin
./nginx

7.测试

其中 Nginx 的配置文件存放于 conf/nginx.conf,Nginx 只有一个程序文件位于 sbin 目录下的 nginx 文件。确保系统的 80 端口没被其他程序占用,运行 sbin/nginx 命令来启动 Nginx,打开浏览器访问此机器的 IP,如果浏览器出现 Welcome to nginx! 则表示 Nginx 已经安装并运行成功。

CentOS6.5+python2.7+nginx+mysql配置_第1张图片

8.配置命令,添加nginx为系统服务(service)
- 在/etc/init.d/目录下编写脚本,新建名为nginx的文件,内容如下,注意==安装目录==

#!/bin/sh 
# 
# nginx - this script starts and stops the nginx daemon 
# 
# chkconfig:   - 85 15 
# description: Nginx is an HTTP(S) server, HTTP(S) reverse \ 
#               proxy and IMAP/POP3 proxy server 
# processname: nginx 
# config:      /etc/nginx/nginx.conf 
# config:      /etc/sysconfig/nginx 
# pidfile:     /var/run/nginx.pid 

# Source function library. 
. /etc/rc.d/init.d/functions 

# Source networking configuration. 
. /etc/sysconfig/network 

# Check that networking is up. 
[ "$NETWORKING" = "no" ] && exit 0 

nginx="/usr/local/nginx/sbin/nginx" 
prog=$(basename $nginx) 

NGINX_CONF_FILE="/usr/local/nginx/conf/nginx.conf" 

[ -f /etc/sysconfig/nginx ] && . /etc/sysconfig/nginx 

lockfile=/var/lock/subsys/nginx 

start() { 
    [ -x $nginx ] || exit 5 
    [ -f $NGINX_CONF_FILE ] || exit 6 
    echo -n $"Starting $prog: " 
    daemon $nginx -c $NGINX_CONF_FILE 
    retval=$? 
    echo 
    [ $retval -eq 0 ] && touch $lockfile 
    return $retval 
} 

stop() { 
    echo -n $"Stopping $prog: " 
    killproc $prog -QUIT 
    retval=$? 
    echo 
    [ $retval -eq 0 ] && rm -f $lockfile 
    return $retval 
killall -9 nginx 
} 

restart() { 
    configtest || return $? 
    stop 
    sleep 1 
    start 
} 

reload() { 
    configtest || return $? 
    echo -n $"Reloading $prog: " 
    killproc $nginx -HUP 
RETVAL=$? 
    echo 
} 

force_reload() { 
    restart 
} 

configtest() { 
$nginx -t -c $NGINX_CONF_FILE 
} 

rh_status() { 
    status $prog 
} 

rh_status_q() { 
    rh_status >/dev/null 2>&1 
} 

case "$1" in 
    start) 
        rh_status_q && exit 0 
    $1 
        ;; 
    stop) 
        rh_status_q || exit 0 
        $1 
        ;; 
    restart|configtest) 
        $1 
        ;; 
    reload) 
        rh_status_q || exit 7 
        $1 
        ;; 
    force-reload) 
        force_reload 
        ;; 
    status) 
        rh_status 
        ;; 
    condrestart|try-restart) 
        rh_status_q || exit 0 
            ;; 
    *)    
      echo $"Usage: $0 {start|stop|status|restart|condrestart|try-restart|reload|force-reload|configtest}" 
        exit 2 

esac
  • chmod 755 /etc/init.d/nginx
  • chkconfig –add nginx
启动 service nginx start
停止 service nginx stop
重启 service nginx reload

问题【403 forbidden——一般为权限问题】

打开nginx.conf文件所在的目录,查看文件的属性 (root root)
在nginx.conf文件的第一行加上 user root root;
[root@linuxidc nginx]# vim conf/nginx.conf
user root root;

MySQL安装

参考链接1:编译安装 https://blog.csdn.net/swing2008/article/details/51190518
参考链接2:yum安装 https://www.cnblogs.com/lzj0218/p/5724446.html

win7访问VMware 虚拟机

  1. 网络适配器配置为NAT模式,可在win7下访问nginx
  2. Navicat连接虚拟机mysql

redis

安装参考
1. log data run /var/redis/
2. 配置 /etc/redis/
3. 安装 /usr/local/bin

问题

  1. mysql-python【mysql—config not found】
python -m pip install --upgrade --force pip

你可能感兴趣的:(环境配置)