随记-项目部署相关

python web 基础环境脚本

阿里云Ubuntu

环境: Ubuntu 16.04 + python3

1.sh

#!/bin/bash

# 更新安装源
sudo apt-get update

# 安装pip3
sudo apt-get -y install python3-pip

# 解决python版本共存问题,设置默认为python3
sudo update-alternatives --install /usr/bin/python python /usr/local/lib/python2.7 100
sudo update-alternatives --install /usr/bin/python python /usr/local/lib/python3.5 200

# 安装虚拟环境
pip3 install virtualenv
pip3 install virtualenvwrapper

# 配制虚拟环境
echo "
export WORKON_HOME=$HOME/.virtualenvs
export PROJECT_HOME=$HOME/workspace 
VIRTUALENVWRAPPER_PYTHON=/usr/bin/python3
source /usr/local/bin/virtualenvwrapper.sh
" >> ~/.bashrc
 

如果将其它命令也放入1.sh 会使虚拟环境的配制不生效,所以拆分成多个shell 脚本, 并且为了将web 应用所需要的模块安装到虚拟环境中, 也需要将

2.sh


# 安装msyql
sudo apt-get -y install mysql-server
sudo apt-get -y install libmysqlclient-dev

# 安装redis
sudo apt-get -y install redis-server
 
# 安装git
sudo apt-get -y install git
 
# 安装前置依赖,
sudo apt-get -y build-dep python-mysqldb

# 安装模块
pip3 install alembic==0.9.9
pip3 install asn1crypto==0.24.0
pip3 install attrs==18.1.0
pip3 install Automat==0.6.0
pip3 install backcall==0.1.0
pip3 install backports.shutil-get-terminal-size==1.0.0
pip3 install beautifulsoup4==4.6.0
pip3 install blinker==1.4
pip3 install bs4==0.0.1
pip3 install certifi==2018.4.16
pip3 install cffi==1.11.5
pip3 install chardet==3.0.4
pip3 install checkbox-support==0.38.0
pip3 install click==6.7
pip3 install colorama==0.3.9
pip3 install constantly==15.1.0
pip3 install cryptography==2.2.2
pip3 install cssselect==1.0.3
pip3 install decorator==4.3.0
pip3 install defer==1.0.4
pip3 install dominate==2.3.1
pip3 install enum34==1.1.6
pip3 install feedparser==5.2.1
pip3 install Flask==0.10.1
pip3 install Flask-Bootstrap==3.3.7.1
pip3 install Flask-Login==0.4.1
pip3 install Flask-Mail==0.9.1
pip3 install Flask-Migrate==2.1.1
pip3 install Flask-MySQLdb==0.2.0
pip3 install Flask-Redis==0.3.0
pip3 install Flask-Script==2.0.6
pip3 install Flask-Session==0.3.1
pip3 install Flask-SQLAlchemy==2.3.2
pip3 install Flask-Testing==0.7.1
pip3 install Flask-WTF==0.14.2
pip3 install gevent==1.3.3
pip3 install greenlet==0.4.13
pip3 install guacamole==0.9.2
pip3 install gunicorn==19.8.1
pip3 install html5lib==1.0.1
pip3 install httplib2==0.11.3
pip3 install hyperlink==18.0.0
pip3 install idna==2.6
pip3 install incremental==17.5.0
pip3 install ipaddress==1.0.22
pip3 install ipython==6.4.0
pip3 install ipython-genutils==0.2.0
pip3 install itsdangerous==0.24
pip3 install jedi==0.12.0
pip3 install Jinja2==2.10
#               pip install # jtypes.jpype==0.6.2b5
pip3 install louis==1.3
pip3 install lxml==4.2.1
pip3 install Mako==1.0.7
pip3 install MarkupSafe==1.0
pip3 install MyApplication==0.1.0
pip3 install mysqlclient==1.3.12
pip3 install oauthlib==2.1.0
pip3 install padme==1.1.1
pip3 install parsel==1.4.0
pip3 install parso==0.2.1
pip3 install pathlib2==2.3.2
pip3 install pbr==4.0.4
pip3 install pexpect==4.6.0
pip3 install pickleshare==0.7.4
pip3 install Pillow==5.1.0
pip3 install plainbox==0.38.0
pip3 install prompt-toolkit==1.0.15
pip3 install psutil==5.4.6
pip3 install ptyprocess==0.5.2
pip3 install pyasn1==0.4.3
pip3 install pyasn1-modules==0.2.1
pip3 install pycparser==2.18
#               pip install # pycurl==7.43.0.2
pip3 install PyDispatcher==2.0.5
pip3 install pygame==1.9.3
pip3 install Pygments==2.2.0
pip3 install PyJWT==1.6.4
pip3 install PyMySQL==0.8.1
pip3 install pyOpenSSL==18.0.0
pip3 install pyparsing==2.2.0
pip3 install python-dateutil==2.7.2
pip3 install python-debian==0.1.32
pip3 install python-editor==1.0.3
pip3 install python-systemd==0.0.9
pip3 install pyxdg==0.26
pip3 install qiniu==7.2.0
pip3 install queuelib==1.5.0
pip3 install redis==2.10.6
pip3 install redis-py-cluster==1.3.4
pip3 install reportlab==3.4.0
pip3 install requests==2.18.4
pip3 install requests-unixsocket==0.1.5
pip3 install scandir==1.7
pip3 install service-identity==17.0.0
pip3 install simplegeneric==0.8.1
pip3 install six==1.11.0
pip3 install SQLAlchemy==1.2.8
#               pip install # ssh-import-id==5.6
pip3 install stevedore==1.28.0
pip3 install traitlets==4.3.2
pip3 install urllib3==1.22
pip3 install virtualenv==16.0.0
pip3 install virtualenv-clone==0.3.0
pip3 install virtualenvwrapper==4.8.2
pip3 install visitor==0.1.3
pip3 install w3lib==1.19.0
pip3 install wcwidth==0.1.7
pip3 install webencodings==0.5.1
pip3 install WebOb==1.8.2
pip3 install Werkzeug==0.14.1
pip3 install WTForms==2.1
pip3 install XlsxWriter==1.0.5
pip3 install xmltodict==0.11.0
pip3 install zope.interface==4.5.0 
# 安装 gunicorn
pip3 install gunicorn

# 安装Nginx
sudo apt-get -y install nginx

# 停止Nginx 服务
/etc/init.d/nginx stop



使用说明

将.sh 文件放到服务器,
执行以下命令

# 修改sh 文件权限
chmod 764 pre_test.sh
chmod 764 test.sh

# 替换文件中的\r
sed -i 's/\r$//' 1.sh 
sed -i 's/\r$//' 2.sh

# 执行1.sh
./1.sh

# 使配置文件生效
source ~/.bashrc   
mkvirtualenv -p python3 虚拟环境名字
./2.sh
 
# 修改Nginx ,然后启动


# 配置Nginx 示例 文件 /etc/nginx/sites-available/default

"
upstream flask {
        server 127.0.0.1:5000;
        server 127.0.0.1:5001;
}
server {
        # 监听80端口
        listen 80 default_server;
        listen [::]:80 default_server;

        root /var/www/html;

        index index.html index.htm index.nginx-debian.html;

        server_name _;

        location / {
                # 请求转发到gunicorn服务器
                proxy_pass http://127.0.0.1:5000;
                # 请求转发到多个gunicorn服务器
                # proxy_pass http://flask;
                # 设置请求头,并将头信息传递给服务器端 
                proxy_set_header Host $host;
                # 设置请求头,传递原始请求ip给 gunicorn 服务器
                proxy_set_header X-Real-IP $remote_addr;
        }
}

" 

阿里云Centos

CentOS 7.2 + Python3

1.sh

#!/bin/bash
# 安装python3
sudo yum -y install zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel gcc make
mv /usr/bin/python /usr/bin/python.bak
wget https://www.python.org/ftp/python/3.6.2/Python-3.6.2.tar.xz
tar -xvJf  Python-3.6.2.tar.xz
cd Python-3.6.2
./configure prefix=/usr/local/python3
make && make install

2.sh

#!/bin/bash
# 还原系统默认设置,保证系统正常运行
sudo sed -i "s/python/python2/" /usr/bin/yum 
sudo sed -i "s/python/python2/" /usr/libexec/urlgrabber-ext-down
 
# mysql
yum install mysql -y
wget http://dev.mysql.com/get/mysql-community-release-el7-5.noarch.rpm
rpm -ivh mysql-community-release-el7-5.noarch.rpm
yum install mysql-community-server -y
yum install mysql-devel -y
service mysqld restart

echo "
[mysql]
default-character-set=utf8
" >> /etc/my.cnf

service mysqld restart

# Redis
yum install gcc -y
wget http://download.redis.io/releases/redis-4.0.6.tar.gz

tar -zxvf redis-4.0.6.tar.gz
cd /root/Python-3.6.2/redis-4.0.6
make MALLOC=libc 
cd /root/Python-3.6.2/redis-4.0.6/src && make install
 
cd /root/Python-3.6.2/redis-4.0.6
sudo sed -i "s/daemonize no/daemonize yes/" redis.conf
cd /root/Python-3.6.2/redis-4.0.6/src 
# ./redis-server /root/Python-3.6.2/redis-4.0.6/redis.conf
 
#killall -9 redis-server
cd /etc
mkdir redis
\cp -f /root/Python-3.6.2/redis-4.0.6/redis.conf /etc/redis/6379.conf
\cp -f /root/Python-3.6.2/redis-4.0.6/utils/redis_init_script /etc/init.d/redisd  
chmod 775 /etc/init.d/redisd

sed -i  "2a # chkconfig:   2345 90 10" /etc/init.d/redisd 
sed -i  "3a # description:  Redis is a persistent key-value database" /etc/init.d/redisd 

chkconfig redisd on

# git
sudo yum -y install git

# 虚拟环境
cd /opt
# 创建虚拟环境
python -m venv py3_flask

3.sh

#!/bin/bash
# mysql-python
sudo yum install python-devel -y
sudo yum install libevent-devel -y
sudo pip install mysql-python

pip install alembic==0.9.9
pip install asn1crypto==0.24.0
pip install attrs==18.1.0
pip install Automat==0.6.0
pip install backcall==0.1.0
pip install backports.shutil-get-terminal-size==1.0.0
pip install beautifulsoup4==4.6.0
pip install blinker==1.4
pip install bs4==0.0.1
pip install certifi==2018.4.16
pip install cffi==1.11.5
pip install chardet==3.0.4
pip install checkbox-support==0.38.0
pip install click==6.7
pip install colorama==0.3.9
pip install constantly==15.1.0
pip install cryptography==2.2.2
pip install cssselect==1.0.3
pip install decorator==4.3.0
pip install defer==1.0.4
pip install dominate==2.3.1
pip install enum34==1.1.6
pip install feedparser==5.2.1
pip install Flask==0.10.1
pip install Flask-Bootstrap==3.3.7.1
pip install Flask-Login==0.4.1
pip install Flask-Mail==0.9.1
pip install Flask-Migrate==2.1.1
pip install Flask-MySQLdb==0.2.0
pip install Flask-Redis==0.3.0
pip install Flask-Script==2.0.6
pip install Flask-Session==0.3.1
pip install Flask-SQLAlchemy==2.3.2
pip install Flask-Testing==0.7.1
pip install Flask-WTF==0.14.2
pip install gevent==1.3.3
pip install greenlet==0.4.13
pip install guacamole==0.9.2
pip install gunicorn==19.8.1
pip install html5lib==1.0.1
pip install httplib2==0.11.3
pip install hyperlink==18.0.0
pip install idna==2.6
pip install incremental==17.5.0
pip install ipaddress==1.0.22
pip install ipython==6.4.0
pip install ipython-genutils==0.2.0
pip install itsdangerous==0.24
pip install jedi==0.12.0
pip install Jinja2==2.10
#               pip install # jtypes.jpype==0.6.2b5
pip install louis==1.3
pip install lxml==4.2.1
pip install Mako==1.0.7
pip install MarkupSafe==1.0
pip install MyApplication==0.1.0
pip install mysqlclient==1.3.12
pip install oauthlib==2.1.0
pip install padme==1.1.1
pip install parsel==1.4.0
pip install parso==0.2.1
pip install pathlib2==2.3.2
pip install pbr==4.0.4
pip install pexpect==4.6.0
pip install pickleshare==0.7.4
pip install Pillow==5.1.0
pip install plainbox==0.38.0
pip install prompt-toolkit==1.0.15
pip install psutil==5.4.6
pip install ptyprocess==0.5.2
pip install pyasn1==0.4.3
pip install pyasn1-modules==0.2.1
pip install pycparser==2.18
#               pip install # pycurl==7.43.0.2
pip install PyDispatcher==2.0.5
pip install pygame==1.9.3
pip install Pygments==2.2.0
pip install PyJWT==1.6.4
pip install PyMySQL==0.8.1
pip install pyOpenSSL==18.0.0
pip install pyparsing==2.2.0
pip install python-dateutil==2.7.2
pip install python-debian==0.1.32
pip install python-editor==1.0.3
pip install python-systemd==0.0.9
pip install pyxdg==0.26
pip install qiniu==7.2.0
pip install queuelib==1.5.0
pip install redis==2.10.6
pip install redis-py-cluster==1.3.4
pip install reportlab==3.4.0
pip install requests==2.18.4
pip install requests-unixsocket==0.1.5
pip install scandir==1.7
pip install service-identity==17.0.0
pip install simplegeneric==0.8.1
pip install six==1.11.0
pip install SQLAlchemy==1.2.8
#               pip install # ssh-import-id==5.6
pip install stevedore==1.28.0
pip install traitlets==4.3.2
pip install urllib3==1.22
pip install virtualenv==16.0.0
pip install virtualenv-clone==0.3.0
pip install virtualenvwrapper==4.8.2
pip install visitor==0.1.3
pip install w3lib==1.19.0
pip install wcwidth==0.1.7
pip install webencodings==0.5.1
pip install WebOb==1.8.2
pip install Werkzeug==0.14.1
pip install WTForms==2.1
pip install XlsxWriter==1.0.5
pip install xmltodict==0.11.0
pip install zope.interface==4.5.0

sudo yum -y install nginx

sed -i  "47a# 请求转发到gunicorn服务器                                    " /etc/nginx/nginx.conf 
sed -i  "48aproxy_pass http\:\/\/127.0.0.1:5000;                          " /etc/nginx/nginx.conf 
sed -i  "49a# 请求转发到多个gunicorn服务器                                " /etc/nginx/nginx.conf 
sed -i  "50a# proxy_pass http\:\/\/flask;                                 " /etc/nginx/nginx.conf 
sed -i  "51aproxy_set_header Host \$host;                                 " /etc/nginx/nginx.conf 
sed -i  "52aproxy_set_header X-Real-IP \$remote_addr;                     " /etc/nginx/nginx.conf 
sed -i  "53aproxy_set_header X-Forwarded-For \$proxy_add_x_forwarded_for; " /etc/nginx/nginx.conf 
sed -i  "54aproxy_set_header Cookie \$http_cookie;                        " /etc/nginx/nginx.conf 

pip install gunicorn

# shutdown -r now
service redisd start
service nginx start

使用说明


# 修改权限
chmod 764 1.sh
sed -i 's/\r$//' 1.sh
chmod 764 2.sh
sed -i 's/\r$//' 2.sh
chmod 764 3.sh
sed -i 's/\r$//' 3.sh

# 执行1.sh
.1.sh

# 执行完成, 执行一下3条命令
\rm -f /usr/bin/python
ln -s /usr/local/python3/bin/python3 /usr/bin/python
.2.sh

# 执行完成, 执行一下2条命令
source /opt/py3_flask/bin/activate
.3.sh




# redis 服务 启动/停止命令 
service redisd start
service redisd stop

# nginx 服务
service nginx restart
service nginx start
service nginx stop

# 注意点

在win下编辑的时候,换行结尾是\n\r , 而在linux下 是\n,所以才会有 多出来的\r

sed -i 's/\r$//' 文件名(假设是 build.sh)

会把 build.sh 中的\r 替换成空白!
再次编译!成功!!


centos mysql 安装完成无密码

第一步:用帐号登录mysql
[root@CentOs5 ~]# mysql -uroot
第二步:改变用户数据库
mysql> use mysql
第三步:修改密码,记得密码要用password()函数进行加密,一定不要忘记!!!
mysql> update user set password=password("mysql") where User="root";
第四步:刷新权限表
mysql> flush privileges;
第五步:退出mysql,对mysql进行重启
[root@CentOs5 ~]# service mysqld restart;


----
到此结  DragonFangQy 2018.7.4
©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 216,001评论 6 498
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 92,210评论 3 392
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 161,874评论 0 351
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 58,001评论 1 291
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 67,022评论 6 388
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 51,005评论 1 295
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 39,929评论 3 416
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 38,742评论 0 271
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 45,193评论 1 309
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 37,427评论 2 331
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 39,583评论 1 346
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 35,305评论 5 342
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 40,911评论 3 325
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 31,564评论 0 21
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 32,731评论 1 268
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 47,581评论 2 368
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 44,478评论 2 352

推荐阅读更多精彩内容