Transfer from https://www.jianshu.com/p/7fcaa16b5e40
——————————————————————————————————————————————————
Cloud server purchase
https://ecs-buy.aliyun.com/#/prepay
Ali cloud ECS services. Simple project minimum configuration on the line.
My personal server 1 nuclear 1G1MB bandwidth of
this configuration is probably the concept of what ?? For example
I installed java + apache tomcat, run jenkins form of war package. In the installation jenkins when the plug completely card dead. the reason is the lack of server memory. 1G memory enough to make jenkins run up ....
But the installation of mysql + nginx + uwsgi run django project without any problems. Fast.
After I deployed a simple test it.
Python library Requests
under native mac systems, scripting circulation requesting the remote server django project interfaces
circulation 100,000 times
the average response rate of 55ms
uwsgi thread a total of 7, 100,000 to finish the requesting server memory there are about 200MB.
All of the following examples are the root user command
Server Port Configuration
After a successful purchase ECS server instance, you can view your public ip address, connect to the server it is to use the ip address to connect later.
Public ip.png
Configuration Examples security group in the Server Manager console to open the port.
Port .png
ssh 22-port
http 80
occasionally test uses port 8000
mysql database 3306 Port
tomcat (if helpful to) 8080 port.
确保服务器状态处于"运行中"
接下来ssh 连接服务器, 开始敲击各种命令来配置python环境.
mac系统ssh连接远程ubuntu系统.
在够买服务器时应该填写过root用户密码, 这个密码一定包保存好.
ssh0.png
mac系统打开终端,
输入 ssh [email protected]
输入密码回车
举个栗子
ssh [email protected]
your password
连接成功显示上图.
root表示服务器用户名, 如果创建了新的用户需要用新用户登录, 就将root更换为新的用户名.输入新用户的密码.
连接成功
显示欢迎使用阿里巴巴弹性云计算服务
列举一些常用的终端命令(linux, ubuntu)
命令 | 功能 |
---|---|
ls | 显示当前目录下的内容 |
ls -a | 同时显示隐藏内容 |
cd | 跳转目录 |
cd .. | 跳转至上一级目录 |
mv | 剪切 |
cp | 复制 |
mkdir | 创建路径 |
vim | vim编辑器 |
rm -r | 删除目录 |
apt-get install | 安装软件 |
free | 查看内存情况 |
netstat -lntp | 查看端口号情况 |
top | 查看cpu |
ps -df | 查看进程情况 |
df | 查看磁盘使用情况 |
安装各种软件
先apt-get update
apt-get update
mysql
apt-get install mysql-server
apt-get install mysql-client
apt-get install libmysqlclient-dev
mysql 5.7的坑!!!
1.user表没有password 字段 改为authentication_string
1.开放mysql外网访问
sudo vim /etc/mysql/mysql.conf.d/mysqld.cnf 找到 bind-address=127.0.0.1
修改为
bind-address=0.0.0.0
编辑完成输入
:wq! 强制修改.
最后的效果:
bind-address.png
重启mysql
sudo /etc/init.d/mysql restart
2.授权用户进行远程连接.
进入mysql命令执行状态
输入mysql -u root -p
表示root 用户登录mysql
授权用户进行远程链接.grant all privileges on *.* to root@"%" identified by "password" with grant option;
flush privileges;
mysql.png
从mysql命令输入状态退出
quit命令. over
nginx
安装nginxsudo apt-get install nginx
修改nginx用户. 默认是www-data用户, 此用户权限极低.
理论上应该新建操作系统用户来运行web程序, 我这里就简单点(反正没重要数据, 挂了就挂了吧.)统统都是用root用户来运行.
vim /etc/nginx/nginx.conf
修改第一行改为root, 保存并重启nginx
nginxconf.png
sudo /etc/init.d/nginx start
sudo /etc/init.d/nginx restart
安装python
sudo apt-get install python3.5
sudo apt-get install python3.5-dev
sudo apt-get install build-essential
sudo apt-get install libssl-dev
sudo apt-get install libevent-dev
sudo apt-get install libjpeg-dev
sudo apt-get install libxml2-dev
sudo apt-get install libxslt-dev
sudo apt-get install python-pip
sudo pip install virtualenv
sudo pip install
sudo apt-get install python-pip
sudo pip install virtualenv
sudo pip install virtualenvwrapper
为virtualenvwrapper 写入环境变量
cd ~
ls -a
vim .bashrc
在文件末尾添加环境变量.
export WORKON_HOME=$HOME/.virtualenvs
export PROJECT_HOME=$HOME/workspace
source /usr/local/bin/virtualenvwrapper.sh
之前的文章中有介绍如何使用pip 与 virtualenv,以及virtualenvwrapper.
使用virtualenvwrapper 创建新的python环境.
创建的新的python 环境目录为
~/.virtualenvs/{your environment}
安装git
sudo apt-get install git
为git 配置用户名邮箱.
git config --global user.name "youname"
git config --global user.email "[email protected]"
为git 添加 ssh 私钥. (公钥在你的git服务器上, 私钥用来验证用户身份)
mac系统下文件上传和下载命令
# 下载文件到桌面(从远程服务器下载文件到本机,此处以google dns ip地址举例)
scp [email protected]:/root/filename.txt /User/username/Desktop
# 下载文件夹到桌面
scp -r [email protected]:/root/filedir /User/username/Desktop
# cd 到待上传文件目录下,上传文件
scp -r filename.py [email protected]:/root/filedir
# 进入root用户根目录
cd ~
# 查看.ssh目录
cd .ssh
# 需要将你的git私钥上传到.ssh目录
scp -r id_rsa [email protected]:/root/.ssh
此时远程服务器有权限拉取托管在git上的 程序.
安装uwsgi
uwsgi使用来运行django服务区项目的 web应用服务器.
apt-get install uwsgi
apt-get install uwsgi-plugin-python
sudo apt-get install uwsgi-plugins-all
作者:行如风
链接:https://www.jianshu.com/p/7fcaa16b5e40
来源:简书
著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。