apt install sudo
adduser xiaogeldx
visudo
vi /etc/sudoers
xiaogeldx ALL=(ALL:ALL) ALL
su user #user 是想要切换到的用户名
sudo apt-get install openssh-client #用于远程登录
sudo apt-get install openssh-server #提供远程登陆
sudo /etc/init.d/ssh start #开启远程登陆
ps -e | grep ssh
# 如果成功,会出现如下结果
vim /etc/ssh/sshd_config
# PermitRootLogin prohibit-password # 默认打开 禁止root用户使用密码登陆,需要将其注释
RSAAuthentication yes #启用 RSA 认证
PubkeyAuthentication yes #启用公钥私钥配对认证方式
PermitRootLogin yes #允许root用户使用ssh登录
sudo apt-get install net-tools
sudo apt-get install libxss1 libappindicator1 libindicator7
wget https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb
sudo apt-get install -f
sudo dpkg -i google-chrome*.deb
Errors were encountered while processing:
google-chrome-stable
就安装 google-chrome-stable,sudo apt-get install google-chrome-stable
,如果出现 E: Unmet dependencies. Try 'apt --fix-broken install' with no packages (or specify a solution).
(缺少依赖关系) 就运行 sudo apt --fix-broken install
sudo apt install vim
sudo vim Pycharm.desktop
[Desktop Entry]
Type=Application
Name=Pycharm
GenericName=Pycharm3
Comment=Pycharm3:The Python IDE
Exec="/home/xiaoge/下载/pycharm-professional-2019.1.1/pycharm-2019.1.1/bin/pycharm.sh" %f
Icon=/home/xiaoge/下载/pycharm-professional-2019.1.1/pycharm-2019.1.1/bin/pycharm.png
Terminal=pycharm
Categories=Pycharm;
mkdir ~/.pip
vim ~/.pip/pip.conf
,填入下面代码:[global]
index-url = http://mirrors.aliyun.com/pypi/simple/
[install]
trusted-host=mirrors.aliyun.com
[list]
format=columns
什么是虚拟环境:
通过工具将系统上的Python解释器复制了一份最简版本
虚拟环境的重要性:
- 不会污染系统环境
- 不同的项目环境的隔离
#安装virtualenv这个包
sudo apt-get install virtualenv
#安装 virtualenwrapper 这个包
sudo apt-get install virtualenvwrapper
#运行下virtualenvwrapper.sh
source /usr/share/virtualenvwrapper/virtualenvwrapper.sh
#这里运行成功不会提示
#创建虚拟环境
mkvirtualenv -p /usr/bin/pythonx.x「项目名字」
#mkvirtualenv -p /usr/bin/python3.7 spider
#进入虚拟环境
workon [项目名字]
pip freeze > requirements.txt
生成扩展库信息列表sudo apt-get install build-essential checkinstall
sudo apt-get install libreadline-gplv2-dev libncursesw5-dev libssl-dev libsqlite3-dev tk-dev libgdbm-dev libc6-dev libbz2-dev
下载Python 3.7.3:
sudo mkdir -p /etc/python3.7
cd /etc/python3.7
sudo wget https://www.python.org/ftp/python/3.7.3/Python-3.7.3.tgz
解压下载的软件包:
sudo tar xzf Python-3.7.3.tgz
编译Python源:
cd Python-3.7.3
sudo ./configure --enable-optimizations --prefix=/etc/python3.7
sudo make altinstall
建立python3.7的软链
sudo ln -s /etc/python3.7/bin/python3.7 /usr/bin/python3.7
sudo ln -s /etc/python3.7/bin/pip3.7 /usr/bin/pip3.7
将/etc/python3.7/bin加入PATH
vim ~/.bash_profile
# .bash_profile
# Get the aliases and functions
if [ -f ~/.bashrc ]; then
. ~/.bashrc
fi
# User specific environment and startup programs
PATH=$PATH:$HOME/bin:/etc/python3.7/bin
export PATH
使生效
source ~/.bash_profile
如果报错-ModuleNotFoundError: No module named ‘_ctypes’
sudo apt-get install --reinstall zlibc zlib1g zlib1g-dev
sudo apt-get install libffi-dev libssl-dev libreadline-dev -y
cd /usr/bin
sudo rm -rf python
sudo ln -s /usr/bin/python3.7 /usr/bin/python
No apport report written because MaxReports is reached already Errors were encountered while processing:
cd /var/lib/dpkg
sudo mv info/ info-bak
sudo mkdir info
sudo apt-get update
sudo apt-get install -f
#就解决了问题,然后恢复info-bak
sudo mv info/* info-bak/
sudo rm -rf info
sudo mv info-bak/ info
sudo apt-get update
sudo apt-get dist-upgrade
#有选1234就选1,有default或者y,n的选默认
需要安装pythonX.Y-devXY,即你的Python版本
安装uWSGI:(首先要创建虚拟环境,在虚拟环境下进行)
pip install uwsgi
基本无问题,进行下一步:
基础测试:创建一个名为test.py的文件,代码如下:
def application(env, start_response):
start_response('200 OK', [('Content-Type','text/html')])
return [b"Hello World"]
uwsgi --http :8000 --wsgi-file test.py
uwsgi --http :8000 --module 项目名.wsgi
sudo pkill -f uwsgi -9
vim /etc/uwsgi/sites/web_prv.ini
[uwsgi]
chdir = /home/web_prv
module = web_prv.wsgi:application
wsgi-file = /home/web_prv/web_prv/wsgi.py
home = /home/env
master = true
processes = 1
thunder-lock =true
enable-threads =true
socket = web_prv.sock
chmod-socket = 666
vacuum = true
daemonize = /home/web_prv/logs/web_prv.log
http : 协议类型和端口号
processes : 开启的进程数量
workers : 开启的进程数量,等同于processes(官网的说法是spawn the specified number ofworkers / processes)
chdir : 指定运行目录(chdir to specified directory before apps loading)
wsgi-file : 载入wsgi-file(load .wsgi file)
stats : 在指定的地址上,开启状态服务(enable the stats server on the specified address)
threads : 运行线程。由于GIL的存在,我觉得这个真心没啥用。(run each worker in prethreaded mode with the specified number of threads)
master : 允许主进程存在(enable master process)
daemonize : 使进程在后台运行,并将日志打到指定的日志文件或者udp服务器(daemonize uWSGI)。实际上最常用的,还是把运行记录输出到一个本地文件上。(肯定要启用,要不刷屏!!)
pidfile : 指定pid文件的位置,记录主进程的pid号。 (生成pid文件,以便stop uwsgi)
vacuum : 当服务器退出的时候自动清理环境,删除unix socket文件和pid文件(try to remove all of the generated file/sockets)
sudo apt-get install nginx
sudo service nginx start/stop/restart
vim /etc/nginx/sites-available/web_prv.conf
# the upstream component nginx needs to connect to
upstream web_prv {
server unix:///home/web_prv/web_prv.sock; 和uwsgi的配置socket = web_prv.sock对应
}
# configuration of the server
server {
# the port your site will be served on
listen 80;
# the domain name it will serve for
server_name xxx;
server_name xxxx; #确保django的settings.py文件中的ALLOWED_HOSTS有这些域名或者ip
charset utf-8;
access_log /home/web_prv/logs/access.log; #django项目根目录下创建logs文件夹,logs下创建access.log和error.log
error_log /home/web_prv/logs/error.log;
# max upload size
client_max_body_size 75M;
location /static {
alias /home/web_prv/static;# your Django project's static files - amend as required
}
location /media {
alias /home/web_prv/media;
}
# Finally, send all non-media requests to the Django server.
location / {
uwsgi_pass web_prv;
include /etc/nginx/uwsgi_params;# the uwsgi_params file you installed
}
}
sudo ln -s /etc/nginx/sites-available/web_prv.conf /etc/nginx/sites-enabled/
sudo service nginx configtest
sudo nginx -t
查看service nginx restart
uwsgi /etc/uwsgi/sites/web_prv.ini -d /home/web_prv/web_prv.log
如果这时候你的网站已经可以正常浏览使用了,别忘记再在项目中的settings.py中关闭你的Debug:settings.py
DEBUG = False
/etc/nginx/sites-available/default default是个链接,所以如果想要自己创建个配置文件(我建的web_prv),就链接一下,链接方法:
ln -s /etc/nginx/sites-available/web_prv /etc/nginx/sites-enabled/
检查你的nginx错误日志(/var/log/nginx/error.log)。如果你看到类似的东西:
connect() to unix:///path/to/your/mysite/mysite.sock failed (13: Permission
denied)
那么可能你需要管理套接字上的权限,以便允许nginx使用它。
尝试:
uwsgi --socket mysite.sock --wsgi-file test.py --chmod-socket=666 # (very permissive)
运行项目uwsgi /etc/uwsgi/sites/web_prv.ini -d /home/web_prv/logs/web_prv.log
settings.py一些注意点
sys.path.insert(0, BASE_DIR)
sys.path.insert(1, os.path.join(BASE_DIR, 'apps'))
DEBUG = False
ALLOWED_HOSTS = [
'xxx',
'xxxx'
]
STATIC_URL = '/static/'
STATIC_ROOT = os.path.join(BASE_DIR, 'static/')
MEDIA_URL = '/media/'
MEDIA_ROOT = os.path.join(BASE_DIR,'media')
uwsgi /etc/uwsgi/sites/web_prv.ini -d /home/web_prv/logs/web_prv.log
,或者运行后发现配置错了导致部署失败,更改好配置后也要删除该文件,在运行 uwsgi./start_navicat
[Desktop Entry]
Encoding=UTF-8
Name=Navicat
Comment=The Smarter Way to manage dadabase
Exec=/bin/sh "/home/xiaoge/下载/navicat121_premium_cs_x64/start_navicat" #改为自己的路径
Icon=/home/xiaoge/下载/navicat121_premium_cs_x64/navicat.png #改为自己的路径
Categories=Application;Database;MySQL;navicat
Version=1.0
Type=Application
#禁止匿名访问
anonymous_enable=NO
#接受本地用户
local_enable=YES
#可以上传
write_enable=YES
#启用在chroot_list_file的用户只能访问根目录
chroot_list_enable=YES
chroot_list_file=/etc/vsftpd.chroot_list
echo "xiaoge" >> /etc/vsftpd.chroot_list
ftp> quote pasv
227 Entering Passive Mode (192,168,0,112,164,248).
ftp> passive
Passive mode on.
Linux安装
apt-get install libcurl4-gnutls-dev libexpat1-dev gettext libz-dev libssl-dev
apt-get install git
git --version #查看版本
配置用户
git config --global user.name 用户名
git config --global user.email 邮箱
查看配置信息
git config --list
git连接github,本地git仓库和github仓库之间的传输是通过SSH加密的
使用以下命令生成SSH Key:
ssh-keygen -t rsa -C "邮箱" #注意有引号#邮箱是github注册的邮箱
一直回车就行,成功的话会在~/下生成.ssh文件夹,进去,打开 id_rsa.pub,复制里面的 key
cd ~
cd .ssh
cat id_rsa.pub #复制key
为了验证是否成功用如下代码
ssh -T [email protected] #成功会显示github名
创建一个和github的项目名相同的git本地仓库的文件夹,然后进入文件夹
#下面这些代码是复制图中的第二种方法的代码
echo "# hahaah" >> README.md
git init
git add README.md
git commit -m "first commit"
git remote add origin [email protected]:xiaogeldx/hahaah.git
git push -u origin master
sudo apt-get update
sudo apt-get install redis-server
redis-server
redis-cli
redis 127.0.0.1:6379> ping
PONG
以上说明我们已经成功安装了redis
sudo add-apt-repository ppa:nilarimogard/webupd8
sudo apt update
sudo apt install woeusb
sudo apt-get remove docker docker-engine docker.io containerd runc
sudo apt-get update
sudo apt-get install \
apt-transport-https \
ca-certificates \
curl \
gnupg-agent \
software-properties-common
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
sudo add-apt-repository \
"deb [arch=amd64] https://download.docker.com/linux/ubuntu \
$(lsb_release -cs) \
stable"
sudo apt-get install docker-ce docker-ce-cli containerd.io
sudo docker run hello-world
sudo usermod -aG docker xiaoge
#xiaoge 为当前用户名{
"registry-mirrors": [
"https://dockerhub.azk8s.cn",
"https://reg-mirror.qiniu.com"
]
}
sudo apt-get install ipython3
pip install ipython
sudo vim /etc/apt/sources.list
sudo vim /etc/default/locale
#以下内容
LANG="en_US.UTF-8"
LANGUAGE="en_US:en"
#以上内容
source /etc/default/locale