Centos 中安装python,mysql

 


 

 

1,安装依赖 

yum -y install zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel gdbm-devel db4-devel libpcap-devel xz-devel python-devel

 

2,安装python

#wget https://www.python.org/ftp/python/3.6.5/Python-3.6.5.tgz
#mkdir -p /usr/local/python3
#tar zxvf Python-3.6.5.tgz
#cd Python-3.6.5
#./configure --prefix=/usr/local/python3
#make
#make install
#ln -s /usr/local/python3/bin/python3 /usr/local/bin/python3
#ln -s /usr/local/python3/bin/pip3 /usr/local/bin/pip3
#pip3 install --upgrade pip #更新pip
#pip3 install ipython #安装ipython方便调试
#python3 -v 进行调试

!!!千万别删centos中自带的python2

3、安装虚拟环境 

pip3 install virtualenv

如果出现报错参考

https://blog.csdn.net/weixin_42670402/article/details/88551804

virtualenv -p /usr/local/python/bin/python3 web

(激活)source web/bin/activate

4,pip install django==2.1.8

django-admin.py (查看命令)

django-admin.py startproject myweb

cd myweb 然后 python manage.py runserver

 

 


安装mysql

1、下载数据包

wget http://repo.mysql.com/mysql-community-release-el7-5.noarch.rpm 

2、安装包

 rpm -ivh mysql-community-release-el7-5.noarch.rpm

3、安装mysql-server

sudo yum install mysql-server

 4、如果登陆mysql报错,把文件权限更改为当前用户

 sudo chown -R openscanner:openscanner /var/lib/mysql

5、重启mysql 

service mysqld restart
mysql -u root 

6、设置登陆密码

use mysql;
update user set password=password('123456') where user='root';
flush privileges;


1、安装uwsgi(Nginx无法直接收到python的数据)

pip install uwsgi

 

2、创建配置文件

mkdir /etc/uwsgi

vim /etc/uwsgi/uwsgi.ini

 

3、编写配置文件

[uwsgi]
uid = root
gid = root
socket = 127.0.0.1:9090
master = true                            //启动主进程
vhost = true         //多站模式

no-site = true        //多站模式时不设置入口模块和文件
workers = 2          //子进程数
reload-mercy = 10       //平滑的重启
cacuum = true       //退出、重启时清楚的文件
max-requests = 1000    //开启1000个进程后,自动respawn下

limit-as = 512        //将进程的内容内存量控制在512,
buffer-size = 30000
pidfile = /var/run/uwsgi9090.pid
daemonize = /var/log/uwsgi9090.log   //pid文件,用于下面的脚本启动、停止该进程

pythonpath = /usr/local/python/bin/web/lib/python3.7/site-packages(django在虚环境下)

 

4、开始、关闭

 开 uwsgi --ini /etc/uwsgi/uwsgi.ini 

 关 cat  /var/run/uwsgi9090.pid   返回数字n

  kill -9 数字n

 

5、更改nginx配置文件

vim /usr/local/nginx/conf/nginx.conf

 

 

location / {
include uwsgi_params;
uwsgi_pass 127.0.0.1:9090;
uwsgi_param UWSGI_SCRIPT myweb.wsgi;
uwsgi_param UWSGI_CHDIR /usr/local/nginx/html/myweb;
index index.html index.htm;
client_max_body_size 35m;
}

 

6、将django项目包移至nginx,启动nginx

mv myweb /usr/local/nginx/html/

/usr/local/nginx/sbin/nginx

 

 

 


posted @ 2019-06-03 15:43  新手码农__威  阅读(1220)  评论(0编辑  收藏  举报