欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  科技

【Ubuntu16.04】虚拟机环境搭建

程序员文章站 2022-09-11 13:29:36
一、允许远程连接 sudo apt-get install ssh #安装远程ssh服务 service ssh start #启动远程ssh连接服务 二、更换更新源 1)备份原文件 sudo cp /etc/apt/sources.list /etc/apt/sources.list.bak 2) ......

一、允许远程连接

  sudo apt-get install ssh  #安装远程ssh服务

  service ssh start     #启动远程ssh连接服务      

二、更换更新源

  1)备份原文件
    sudo cp /etc/apt/sources.list /etc/apt/sources.list.bak

  2)编辑更新源,替换成国内的地址
    sudo gedit /etc/apt/sources.list

  阿里云源

  # deb cdrom:[Ubuntu 16.04 LTS _Xenial Xerus_ - Release amd64 (20160420.1)]/ xenial main restricted
  deb-src http://archive.ubuntu.com/ubuntu xenial main restricted #Added by software-properties
  deb http://mirrors.aliyun.com/ubuntu/ xenial main restricted
  deb-src http://mirrors.aliyun.com/ubuntu/ xenial main restricted multiverse universe #Added by software-properties
  deb http://mirrors.aliyun.com/ubuntu/ xenial-updates main restricted
  deb-src http://mirrors.aliyun.com/ubuntu/ xenial-updates main restricted multiverse universe #Added by software-properties
  deb http://mirrors.aliyun.com/ubuntu/ xenial universe
  deb http://mirrors.aliyun.com/ubuntu/ xenial-updates universe
  deb http://mirrors.aliyun.com/ubuntu/ xenial multiverse
  deb http://mirrors.aliyun.com/ubuntu/ xenial-updates multiverse
  deb http://mirrors.aliyun.com/ubuntu/ xenial-backports main restricted universe multiverse
  deb-src http://mirrors.aliyun.com/ubuntu/ xenial-backports main restricted universe multiverse #Added by software-properties
  deb http://archive.canonical.com/ubuntu xenial partner
  deb-src http://archive.canonical.com/ubuntu xenial partner
  deb http://mirrors.aliyun.com/ubuntu/ xenial-security main restricted
  deb-src http://mirrors.aliyun.com/ubuntu/ xenial-security main restricted multiverse universe #Added by software-properties
  deb http://mirrors.aliyun.com/ubuntu/ xenial-security universe
  deb http://mirrors.aliyun.com/ubuntu/ xenial-security multiverse

  3)让更新源生效

    sudo apt-get update

三、安装mysql并允许远程连接

  1、安装上服务
    sudo apt-get install mysql-server
    sudo apt-get install mysql-client
    sudo apt-get install libmysqlclient-dev
  2、修改mysql配置文件,将bind-address=127.0.0.1注释掉
    sudo /etc/mysql/mysql.conf.d/mysqld.cnf
   a、进入mysql
     mysql -u root -p
   b、修改权限
     grant all privileges on *.* to 'root'@'%' identified by 'root' with grant option;
   c、刷新访问权限
     flush privileges;
   d、重启mysql服务
     sudo /etc/init.d/mysql restart

四、安装vim编辑器

  sudo apt-get install vim

五、安装java环境

  sudo add-apt-repository ppa:webupd8team/java
  sudo apt-get update
  sudo apt-get install oracle-java8-installer
  java -version
  sudo apt-get install oracle-java8-set-default
  sudo echo JAVA_HOME="/usr/lib/jvm/java-8-oracle"
  source /etc/environment

六、安装虚拟环境下的各种插件

  1、安装虚拟环境

    安装pip和pip3:  sudo apt-get install python-pip       sudo apt-get install python3-pip

    1) sudo pip install virtualenv
    2) sudo pip install virtualenvwrapper
    3) mkdir ~/.virtualenvs
    4) sudo vim ~/.bashrc
      末尾增加以下两行
      export WORKON_HOME=$HOME/.virtualenvs # 所有虚拟环境存储的目录
      source /usr/local/bin/virtualenvwrapper.sh
    5) source ~/.bashrc
    6) sudo chmod 777 /home/yufeng/.virtualenvs
    7) 创建py2或py3的虚拟环境
      mkvirtualenv -p /usr/bin/python3 env_name
      mkvirtualenv -p /usr/bin/python2 env_name
    8) 运行虚拟环境
      workon env_name
      workon + 两次tab键可以显示所有的虚拟环境
    9) 退出虚拟环境
      deactivate
    10) 删除虚拟环境
      rmvirtualenv env_name

  2、安装paramiko  [ssh的方式管理远程服务器]

    sudo pip3 install pycrypto
    sudo pip install paramiko

  3、安装django1.8.2

    sudo pip3 install django==1.8.2

  4、安装分布式爬虫

    sudo pip install scrapy

  5、科学计算和数学工作基础包

    sudo pip3 install numpy

  6、封装了微信API的python扩展库

    sudo pip3 install itchat

  7、关系型数据库  sqlAlchemy

    sudo pip3 install SQLAlchemy

  8、网络模块方面(协程、多进程)

    sudo pip3 install Greenlet

    sudo pip3 install Gevent

  9、RabbitMQ队列(消息分发、过滤发送等)

    sudo pip3 install pika

  10、异步框架jinja2

    sudo pip3 install aiohttp

    sudo pip3 install aiomysql

    sudo pip3 install jinja2

  11、安装非关系型数据库redis

    特征:内存级读写,宕机可能丢失数据,运用于主从   和  订阅

    1)redis官网下载redis-3.2.5.tar.gz

    2)解压到指定目录下

      tar zxvf redis-3.2.5.tar.gz

      sudo mv -r redis-3.2.5/* /usr/local/redis/

    3)生成

      cd /usr/local/redis/

      sudo make

    4)测试

      sudo make test

    5)将redis的命令安装到/usr/bin/目录

      sudo make install

    6)配置redis配置文件

      sudo vim /usr/local/redis/redis.conf

      "daemonize yes  #以守护进程运行"

      "dbfilename dump.rdb"

      "dir /var/lib/redis"

      "bind 127.0.0.1"  #注释掉此行,以便其他服务器连接

      "bind 192.168.0.131"  #绑定本地机器的实际IP地址

    7)复制配置文件到/etc/redis/下

      sudo cp /usr/local/redis/redis.conf /etc/redis/

    8)配置文件方式启动

      sudo redis-server /etc/redis/redis.conf

    9)启动客户端

      redis-cli -h 192.168.0.131

    10)停止redis服务

      ps ajx|grep redis

      sudo kill -9 redis的进程id

 

  12、安装celery异步发送请求

    sudo pip3 install celery==3.1.25

    sudo pip3 install celery-with-redis==3.0

    sudo pip3 install django-celery==3.1.7