tornado、django在linux下环境安装和配置

来源:互联网 发布:新疆英吉沙小刀淘宝店 编辑:程序博客网 时间:2024/06/05 16:29

1、激活root用户 默认是未激活

sudo passwd root

2、安装ssh服务

sudo apt-get install openssh-server/etc/init.d/ssh start   开启服务/etc/init.d/ssh stop    关闭服务/etc/init.d/ssh restart 重启服务

3、安装python2.7

sudo apt-get install python2.7which python2.7which python3python --version

4、创建软连接

ln -s 源文件  目标文件sudo ln -s /usr/bin/python2.7 /usr/bin/python

5、安装setuptools

sudo apt-get install python-setuptools

6、安装pip

(1)安装

wget http://bootstrap.pypa.io/get-pip.py --no-check-certificate

(2)执行安装pip命令

sudo python get-pip.py

(3)新建pip配置文件

mkdir ~/.pipmkdir ~/.pip/pip.conf

(4)添加内容

[list]format=columns

(5)pip配置文件可以放置的位置

Linux/Unix:/etc/pip.conf~/.pip/pip.conf~/.config/pip/pip.conf

7、安装virtualenv和virtualenvwrapper

sudo apt-get update

sudo apt-get install python-virtualenv  sudo easy_install virtualenvwrapper

工具安装好后找不到mkdirvirtualenv命令,需要执行以下环境变量设置

1.创建目录用来存放虚拟环境    mkdir $HOME/.virtualenvs2.在~/.bashrc中添加行:    export WORKON_HOME=$HOME/.virtualenvs    source /usr/local/bin/virtualenvwrapper.sh3.运行:    source ~/.bashrc3.创建python虚拟环境    mkvirtualenv [虚拟环境名称]4.切换虚拟环境    workon [虚拟环境名称]5.退出虚拟环境    deactivate6.删除虚拟环境    rmvirtualenv [虚拟环境名称]注:创建的环境是独立的,互不干扰,无需sudo权限即可使用 pip 来进行包的管理,如果在虚拟环境中使用sudo安装的包在主环境中
使用-p参数指定虚拟环境中python的版本
mkvirtualenv -p python python2_tornado

8、安装tree,树状查看目录

sudo apt-get install tree

9、动态查看log日志文件

tailf aaa.logtail -f aaa.log

10、安装python框架

pip install djangopip install tornado

11、安装mysql

sudo apt-get install mysql-serversudo apt-get install mysql-clientsudo apt-get install libmysqlclient-dev

注:安装过程中需要设置密码,不要忘了。

查看是否安装成功

sudo netstat -apn|grep mysql

登录mysql

mysql -u root -p

-u 表示选择登陆的用户名,

-p 表示登陆的用户密码,

上面命令输入之后会提示输入密码,此时输入密码就可以登录到mysql

查看mysql编码

mysql> show variables like '%char%';+--------------------------+----------------------------+| Variable_name            | Value                      |+--------------------------+----------------------------+| character_set_client     | utf8                       || character_set_connection | utf8                       || character_set_database   | latin1                     || character_set_filesystem | binary                     || character_set_results    | utf8                       || character_set_server     | latin1                     || character_set_system     | utf8                       || character_sets_dir       | /usr/share/mysql/charsets/ |+--------------------------+----------------------------+8 rows in set (0.01 sec)mysql> show variables like '%colla%';+----------------------+-------------------+| Variable_name        | Value             |+----------------------+-------------------+| collation_connection | utf8_general_ci   || collation_database   | latin1_swedish_ci || collation_server     | latin1_swedish_ci |+----------------------+-------------------+3 rows in set (0.01 sec)

全局修改字符编码设置为UTF-8

默认情况下,MySQL的字符集是latin1,因此在存储中文的时候,会出现乱码的情况,所以我们需要把字符集统一改成UTF-8,用vi打开MySQL服务器的配置文件my.cnf

sudo vi /etc/mysql/my.cnf

在[client]标签下,增加客户端的字符编码

[client]default-character-set=utf8在[mysqld]标签下,增加服务器端的字符编码[mysqld]character-set-server=utf8collation-server=utf8_general_ci
  1 #  2 # The MySQL database server configuration file.  3 #  4 # You can copy this to one of:  5 # - "/etc/mysql/my.cnf" to set global options,  6 # - "~/.my.cnf" to set user-specific options.  7 #  8 # One can use all long options that the program supports.  9 # Run program with --help to get a list of available options and with 10 # --print-defaults to see which it would actually understand and use. 11 # 12 # For explanations see 13 # http://dev.mysql.com/doc/mysql/en/server-system-variables.html 14 15 # 16 # * IMPORTANT: Additional settings that can override those from this file! 17 #   The files must end with '.cnf', otherwise they'll be ignored. 18 # 19 20 !includedir /etc/mysql/conf.d/ 21 !includedir /etc/mysql/mysql.conf.d/ 22** 23 [client]**** 24 default-character-set = utf8**** 25**** 26 [mysqld]**** 27 character-set-server = utf8**** 28 collation-server = utf8_general_ci**

重启mysql,生效

使用 service 启动:sudo service mysql restartservice mysql start 启动service mysql stop 停止

创建数据库的时候直接指定默认字符

create database *** default character set utf8

远程链接mysql

检查3306端口

zyb@ubuntu:~ sudo netstat -apn|grep 3306tcp        0      0 0.0.0.0:3306            0.0.0.0:*               LISTEN      1852/mysqld

如果是绑定了本地回旋地址,需要改配置文件

zyb@ubuntu:~ sudo netstat -apn|grep 3306tcp        0      0 127.0.0.1:3306            0.0.0.0:*               LISTEN      1852/mysqld

修改mysql的配置文件文件

zyb@ubuntu:~ sudo vim /etc/mysql/mysql.conf.d/mysqld.cnf修改  bind-address = 127.0.0.1bind-address = 0.0.0.0

记得要重启mysql服务

sudo service mysql restart

创建用户

选中mysql数据库

use mysql;

查看现有用户

select user,host from user;

1、给现有用户添加远程访问权限

update user set host ='%' where user='root';  grant all on . to root@'%' identified by 'root';flush privileges;

2、创建可以远程访问的用户

CREATE USER '<username>'@'%' IDENTIFIED BY '<password>';GRANT ALL ON <dbname>.* TO '<username>'@'%';

3、创建只允许192.168.201.128访问的用户

CREATE USER 'user02'@'192.168.201.128' IDENTIFIED BY '<password>';GRANT ALL ON <dbname>.* TO '<username>'@'192.168.201.128'

查看用户权限与GRANT用法

[MySQL]查看用户权限与GRANT用法查看用户权限show grants for 你的用户比如:show grants for root@'localhost';

安装PyMySQL

pip install PyMySQL

安装sqlalchemy

pip install sqlalchemy

安装memcached

sudo apt-get install memcachedpip install python-memcached

12、安装redis,在Ubuntu中执行下面这句命令:

sudo apt-get install redis-server
启动服务端redis-server启动客户端redis-cli 
pip install redis

13、虚拟机与宿主机联网

宿主:Win7  虚拟机:Ubuntu(1)在虚拟机中以NAT的连接模式,共享宿主机的IP地址信息(2)在虚拟Linux系统中,ifconfig     eth0 获取虚拟主机的网卡分配的IP地址如:ip。(3)通过在宿主系统中的网址输入:ip,即可访问虚拟设备的服务。设置PyCharm工具的编码格式:File -> setting -> Editor -> File Encodings -> IDE Encoding  Project Encoding的值为:utf-8使用pycharm链接虚拟机------------------1、链接虚拟机-----------------------打开pycham,windows下连接服务器端Tools --> Deployment --> Configurasion 点击 +  name 随便写type SFTP配置连接服务器,name随便写,connection下,协议sftp,服务器主机IP  172.16.163.10,用户名,密码点击Test SFTP connection测试  成功显示ok-------------------2、windows下代码与服务器代码链接-----------------------------下面选择连接windows下的那部分代码和服务器上代码相连,Mappings,本地Local path,服务器path,apply,OK,表示已经把本地的代码和服务器代码连接上了。设置如何使得本地代码和服务器代码同步更新Tools --> Deployment -->  Options在upload changed files automatically to the default server 选项中选择On explicit save action(ctrl +s)表示在pycharm里修改代码后ctrl+s便可同步到服务器。never                   从未                 always                  总是on explicit save action 显式保存动作---------------------3.在pycharm里可以使用ssh------------------------------------------在pycharm里Tools->start ssh session可以使用ssh,如果ssh时候发现打开中文乱码,在settings里修改File --> Tools --> SSH Terminal --> Deployment server  rock1 --> Default encoding:  UTF-8--------------------4.Windows下的Pycharm远程连接虚拟机的Python环境---------------------Windows下的Pycharm远程连接虚拟机的Python环境打开Pycharm,File—>Settings—>Project—>Project Interpreter 选择Add Remote选择SSH Credentials,填写参数---------------------5运行virtualenv中的python------------------------- --------看python解释器位置which python(python2tornado) rock1@rock1:~/work/tornado_test/rock1/1lesson_helloworld$ which python/home/rock1/.virtualenvs/python2_tornado/bin/python---------------------------------------------------------------------------------使用xshell链接虚拟机使用Navicat链接虚拟机

14、安装curl

sudo apt install curl

15、清除浏览器缓存

Ctrl+Shift+Del 清除Google浏览器缓存的快捷键

Ctrl+Shift+R 重新加载当前网页而不使用缓存内容

使用locale命令查看系统当前编码

zyb@ubuntu:~$ localeLANG=zh_CN.UTF-8LANGUAGE=zh_CN:en_US:enLC_CTYPE="zh_CN.UTF-8"LC_NUMERIC=zh_CN.UTF-8LC_TIME=zh_CN.UTF-8LC_COLLATE="zh_CN.UTF-8"LC_MONETARY=zh_CN.UTF-8LC_MESSAGES="zh_CN.UTF-8"LC_PAPER=zh_CN.UTF-8LC_NAME=zh_CN.UTF-8LC_ADDRESS=zh_CN.UTF-8LC_TELEPHONE=zh_CN.UTF-8LC_MEASUREMENT=zh_CN.UTF-8LC_IDENTIFICATION=zh_CN.UTF-8LC_ALL=zyb@ubuntu:~$

VMWare 虚拟机备份

虚拟机->快照->拍摄快照     进行备份

豆瓣源安装

pip  install  -i  https://pypi.doubanio.com/simple/  --trusted-host pypi.doubanio.com  flask

很久没写东西了 最近有空就开始更新python 的tornado框架和django框架的项目开发过程。fighting!

原创粉丝点击