ubuntu 基于windows

windows10下的ubuntu子系统

wsl windows server linux

ubuntu在微软商店可下载,安装好之后配置一个用户名和密码,默认的root用户时没有密码的。需要使用root用户 使用passwd root来就行修改

使用xshell来连接本机ubuntu

ubuntu端进行配置:

cd /etc/ssh #切换到ssh配置文件的位置
sudo cp sshd_config sshd_config.bak   #先把原来的备份

sudo vim sshd_config		#编辑配置文件
在文件中做更改
Port 3652  #修改端口,原来的22端口已经存在
ListenAddress 0.0.0.0  #打开本地监听
#StrictModes yes  #注释掉
PasswordAuthentication yes  #修改登陆的方式,允许密码登陆

重启ssh
sudo service ssh restart

重新生成host key
sudp dpkg-reconfigure openssh-server

由于是wsl的ubuntu,使用ifconfig查找lo的ip值,就是127.0.0.1
使用xshell连接,127.0.0.1即可
在windows关机后重启开启ubuntu只会启动一个用户的bash,没有其他的服务启动,要想使用xshell连接,可以修改 .bashrc 文件 ,把 service ssh start 加进去,切换root用户的同时就启动了ssh,关掉windows的shell,就可以用xshell连接了

修改默认源

cd /etc/apt/
cp sources.list ./sources.list.bak
vim sources.list

deb http://mirrors.aliyun.com/ubuntu/ trusty main restricted universe multiverse  
deb http://mirrors.aliyun.com/ubuntu/ trusty-security main restricted universe multiverse  
deb http://mirrors.aliyun.com/ubuntu/ trusty-updates main restricted universe multiverse  
deb http://mirrors.aliyun.com/ubuntu/ trusty-proposed main restricted universe multiverse  
deb http://mirrors.aliyun.com/ubuntu/ trusty-backports main restricted universe multiverse  
deb-src http://mirrors.aliyun.com/ubuntu/ trusty main restricted universe multiverse  
deb-src http://mirrors.aliyun.com/ubuntu/ trusty-security main restricted universe multiverse  
deb-src http://mirrors.aliyun.com/ubuntu/ trusty-updates main restricted universe multiverse  
deb-src http://mirrors.aliyun.com/ubuntu/ trusty-proposed main restricted universe multiverse  
deb-src http://mirrors.aliyun.com/ubuntu/ trusty-backports main restricted universe multiverse


更新源
sudo apt-get update
更新软件
sudo apt-get upgrade

文件系统挂载点

ubuntu系统在windows的%localappdata%PackagesCanonicalGroupLimited.UbuntuonWindows_79rhkp1fndgscLocalState ootfs 文件夹下
windows系统在wsl中的路径都是挂载在/mnt下面

装py3

apt install python3

装pip3

apt-get install python3-pip
安装的时候报错 [ImportError: cannot import name 'sysconfig']
解决:https://blog.csdn.net/weixin_41282397/article/details/85068590
安装过程很耗时的

开启xshell之后,每执行一条命令,都会在在windows的任务管理器中开启一个bash sudo这样的进程,关掉xsehll,进程就都掉

ubuntu子系统在任务管理器中的进程为 init

虚拟环境的建立

1 安装包
sudo apt install python-virtualenv
sudo easy_install virtualenvwrapper
virtualenvwrapper依赖于 python virtualenv,安装的顺序不能颠倒
或者使用pip进行安装,两种方式都是一样的
sudo pip install virtualenv
sudo pip install virtualenvwrapper

安装完成之后可能没有mkvirtualenv命令,一般是脚本文件没有加入系统路径

# 找到virtualenvwrapper的脚本文件
whereis virtualenvwrapper
# 执行脚本文件激活virtualenvwrapper
source virtualenvwrapper.sh
# 可以正常使用命令了

或者将sourc加到用户的环境配置文件中
sudo vi ~/.bashrc
source xxx/virtualenvwrapper.sh的绝对路径
更新文件
source ~/.bashrc

创建虚拟环境
mkvirtualenv 环境名称 -p 指定python版本

进入环境 
workon

退出环境
deactivate

然后就可以在虚拟环境中安装需要的包了

文件传输

由于ubuntu作为windows的一个子系统,所以ip是同一个,所以就不在用pycharm的文件同步功能了,直接在ubuntu中访问 /mnt下的各盘,找到工作目录就可以执行操作了

mysql 数据库

apt-get install mysql-server
启动
service mysql start
默认没密码就能登录,上去更改密码
select mysql;
update user set authentication_string=password('123456') where user='root';

redis

安装Redis服务器端
sudo apt-get install redis-server

启动
service redis-server start

zabbix

wget https://repo.zabbix.com/zabbix/4.0/ubuntu/pool/main/z/zabbix-release/zabbix-release_4.0-2+bionic_all.deb
dpkg -i zabbix-release_4.0-2+bionic_all.deb
apt update
apt install zabbix-server-mysql
 apt install zabbix-frontend-php
 zcat /usr/share/doc/create.sql.gz |mysql -mzabbix -pzabbix


安装完成之后再刚进入zabbix界面的时候出现时区错误问题,需要修改两个文件,再重启zabbix 跟 apache2

vim /etc/php/7.2/apache2/php.ini

vim /etc/apache2/conf-available/zabbix.conf

原文地址:https://www.cnblogs.com/cizao/p/11482022.html