#!/usr/bin/python
# -*- coding:utf-8 -*-
# 注意:本实验用root用户。已经安装python3.6.5 用pycharm运行,首先把nginx安装包放在 /usr/local 下面;mysql安装包放在/root/soft/下面;php7.11安装包不用提前准备,网络下载就行
import subprocess
import sys
import os info = ''' #定义开头显示的提示选择信息
----- Select Install option -----
1.Install Nginx-1.12.2
2.Install mysql-5.7.22
3.Install PHP-7.1.1 5.Exit Program
---------------------------------
'''
nginx_service = '''
[Unit]
Description=nginx
After=network.target [Service]
Type=forking
ExecStart=/usr/local/nginx/sbin/nginx
ExecReload=/usr/local/nginx/sbin/nginx -s reload
ExecStop=/usr/local/nginx/sbin/nginx -s quit
PrivateTmp=true [Install]
WantedBy=multi-user.target
'''
my_cnf = '''
[mysqld]
basedir=/usr/local/mysql #介质目录
datadir=/usr/local/mysql/data #数据目录
port=3306 #端口
pid-file = /usr/local/mysql/data/mysqld.pid #进程id
user = mysql #启动用户
socket=/tmp/mysql.sock #sock文件地址
bind-address = 0.0.0.0 #绑定ip 这里表示绑定所有ip
server-id = 1 #用于复制环境钟标识实例,这个在复制环境里唯一
character-set-server = utf8 #服务端默认字符集,很重要,错误设置会出现乱码
max_connections = 1000 #允许客户端并发连接的最大数量
max_connect_errors = 6000 #如果客户端尝试连接的错误数量超过这个参数设置的值,则服务器不再接受新的客户端连接
open_files_limit = 65535 #操作系统允许MySQL服务打开的文件数量。
table_open_cache = 128 #所有线程能打开的表的数量
max_allowed_packet = 32M #网络传输时单个数据包的大小。
binlog_cache_size = 1M
max_heap_table_size = 1288M
tmp_table_size = 16M
read_buffer_size = 2M
read_rnd_buffer_size = 8M
sort_buffer_size = 16M
join_buffer_size = 16M
key_buffer_size = 4M
thread_cache_size = 8
query_cache_type = 1
query_cache_size = 4096M
query_cache_limit = 4M
ft_min_word_len = 4
log_bin = mysql-bin
binlog_format = mixed
expire_logs_days = 30
log_error = /usr/local/mysql/data/mysql-error.log #错误日志地址
slow_query_log = 1
long_query_time = 1
slow_query_log_file = /usr/local/mysql/data/mysql-slow.log #慢查询日志
performance_schema = 0
explicit_defaults_for_timestamp
lower_case_table_names = 1
skip-external-locking
default_storage_engine = InnoDB
#default-storage-engine = MyISAM
innodb_file_per_table = 1
innodb_open_files = 16350
innodb_buffer_pool_size = 10G
innodb_write_io_threads = 16
innodb_read_io_threads = 16
innodb_thread_concurrency = 32
innodb_purge_threads = 1
innodb_flush_log_at_trx_commit = 2
innodb_log_buffer_size = 128M
innodb_log_file_size = 1G
innodb_log_files_in_group = 3
innodb_max_dirty_pages_pct = 90
innodb_lock_wait_timeout = 120
bulk_insert_buffer_size = 8M
myisam_sort_buffer_size = 8M
myisam_max_sort_file_size = 10G
myisam_repair_threads = 1
interactive_timeout = 512
wait_timeout = 256
#lower_case_table_names = 1
skip-external-locking
default_storage_engine = InnoDB
#default-storage-engine = MyISAM
sql_mode='NO_AUTO_VALUE_ON_ZERO,STRICT_TRANS_TABLES,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION,PIPES_AS_CONCAT,ANSI_QUOTES' [client]
port=3306
socket=/tmp/mysql.sock
[mysql]
socket=/tmp/mysql.sock #开启快速度导出
[mysqldump]
quick
default-character-set = utf8mb4
max_allowed_packet = 256M [myisamchk] key_buffer_size = 20M
sort_buffer_size = 20M
read_buffer = 2M
write_buffer = 2M ''' while True:
print(info)
n = input('Input your select: ')
if n.isdigit(): # 判断是否是数字
n = int(n) # 如果是就转换成整型,raw_input接收类型默认是字符串型
if n <= 5 and n >= 1: # 数字必须在可选范围之内
if not os.path.isdir('/data'): # 判断是否存在/data目录
os.mkdir('/data') # 不存在就创建
else:
if n == 1: # 如果选的是1,运行shell命令安装nginx
print("创建nginx用户")
subprocess.call(["useradd nginx"], shell=True)
print("安装依赖环境")
subprocess.call([
"yum install gcc gcc-c++ zlib zlib-devel openssl openssl-devel pcre pcre-devel autoconf automake libtool make -y"],
shell=True)
print("编译安装")
subprocess.call([
"cd /usr/local && tar -xf nginx-1.12.2.tar.gz && cd nginx-1.12.2 && ./configure --prefix=/usr/local/nginx --conf-path=/etc/nginx/nginx.conf --with-http_stub_status_module --with-http_ssl_module --with-stream && make && make install"],
shell=True)
print("设置环境变量")
subprocess.call(["echo 'export PATH=$PATH:/usr/local/nginx/sbin' >> /etc/profile"], shell=True)
subprocess.call(["source /etc/profile"], shell=True)
print("设置配置文件")
subprocess.call(["/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf"], shell=True) print("创建开机自启文件")
with open("/lib/systemd/system/nginx.service", "a") as f:
f.write(my_cnf)
f.close()
print("设置开机启动")
subprocess.call(["systemctl enable nginx.service"], shell=True)
print("启动nginx服务")
subprocess.call(["systemctl start nginx.service"], shell=True)
print("重新加载nginx")
subprocess.call(["nginx -s reload"], shell=True) if n == 2: # 编译安装mysql,每个命令都在屏幕上显示;安装包提前放在/root/soft目录下
print("remove mariadb")
subprocess.call(["yum remove maria* -y"], shell=True)
print("清空my.cnf")
subprocess.call(["echo > /etc/my.cnf"], shell=True)
print("useradd mysql")
subprocess.call(["useradd mysql && groupadd mysql && useradd -r -g mysql mysql"], shell=True)
print("tar -zxvf mysql-5.7.22-linux-glibc2.12-x86_64.tar.gz")
subprocess.call(["cd /root/soft/ && tar -zxvf mysql-5.7.22-linux-glibc2.12-x86_64.tar.gz"],
shell=True)
print("mv /root/soft/mysql-5.7.22-linux-glibc2.12-x86_64 /usr/local/mysql")
subprocess.call(["cd /root/soft/ && mv mysql-5.7.22-linux-glibc2.12-x86_64 /usr/local/mysql"],
shell=True)
print("chown -R mysql:mysql /usr/local/mysql")
subprocess.call(["chown -R mysql:mysql /usr/local/mysql"], shell=True)
print("初始化mysql")
subprocess.call([
"cd /usr/local/mysql/ && bin/mysqld --initialize --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data"],
shell=True)
print("创建RSA private key")
subprocess.call(["cd /usr/local/mysql && bin/mysql_ssl_rsa_setup --datadir=/usr/local/mysql/data"],
shell=True)
subprocess.call(["chown -R mysql:mysql /usr/local/mysql/data"], shell=True) print("创建mysql配置文件")
with open("/etc/my.cnf", "a") as f:
f.write(my_cnf)
f.close()
print("添加开机启动")
subprocess.call(["cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld"], shell=True)
print("修改配置文件")
subprocess.call(["sed -i '2a basedir=/usr/local/mysql' /etc/init.d/mysqld "], shell=True)
subprocess.call(["sed -i '3a datadir=/usr/local/mysql/data' /etc/init.d/mysqld "], shell=True)
print("添加环境变量")
subprocess.call([
"sed -i '$a\PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin:/root/bin:/usr/local/mysql/bin' ~/.bash_profile && source ~/.bash_profile"],
shell=True)
print("启动mysq")
subprocess.call(["systemctl daemon-reload && systemctl start mysqld"], shell=True)
print("设置mysql的bin目录连接")
subprocess.call(["ln -s /usr/local/mysql/bin/mysql /usr/bin"], shell=True)
print("设置开机自启")
subprocess.call(["chmod +x /etc/init.d/mysqld && chkconfig --add mysqld"], shell=True) if n == 3:
print("安装依赖包")
subprocess.call(
[
"yum install openldap openldap-devel epel-release gcc gcc-c++ libxml2 libxml2-devel openssl openssl-devel bzip2 bzip2-devel libcurl libcurl-devel libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel gmp gmp-devel libmcrypt libmcrypt-devel readline readline-devel libxslt libxslt-devel -y"],
shell=True)
print("下载安装包、编译安装php")
subprocess.call(["cd /usr/local && wget -O php7.tar.gz http://cn2.php.net/get/php-7.1.1.tar.gz/from/this/mirror && tar -xvf php7.tar.gz && cd php-7.1.1/ && ./configure \
--prefix=/usr/local/php \
--with-config-file-path=/etc \
--enable-fpm \
--with-fpm-user=nginx \
--with-fpm-group=nginx \
--enable-inline-optimization \
--disable-debug \
--disable-rpath \
--enable-shared \
--enable-soap \
--with-libxml-dir \
--with-xmlrpc \
--with-openssl \
--with-mcrypt \
--with-mhash \
--with-pcre-regex \
--with-sqlite3 \
--with-zlib \
--enable-bcmath \
--with-iconv \
--with-bz2 \
--enable-calendar \
--with-curl \
--with-cdb \
--enable-dom \
--enable-exif \
--enable-fileinfo \
--enable-filter \
--with-pcre-dir \
--enable-ftp \
--with-gd \
--with-openssl-dir \
--with-jpeg-dir \
--with-png-dir \
--with-zlib-dir \
--with-freetype-dir \
--enable-gd-native-ttf \
--enable-gd-jis-conv \
--with-gettext \
--with-gmp \
--with-mhash \
--enable-json \
--enable-mbstring \
--enable-mbregex \
--enable-mbregex-backtrack \
--with-libmbfl \
--with-onig \
--enable-pdo \
--with-mysqli=mysqlnd \
--with-pdo-mysql=mysqlnd \
--with-zlib-dir \
--with-pdo-sqlite \
--with-readline \
--enable-session \
--enable-shmop \
--enable-simplexml \
--enable-sockets \
--enable-sysvmsg \
--enable-sysvsem \
--enable-sysvshm \
--enable-wddx \
--with-libxml-dir \
--with-xsl \
--enable-zip \
--with-ldap \
--enable-mysqlnd-compression-support \
--with-pear \
--enable-opcache && make && make install"], shell=True)
print("配置环境变量")
subprocess.call(["sed -i '$a\export PATH=$PATH:/usr/local/php/bin' /etc/profile && source /etc/profile"], shell=True)
print("配置php-fpm")
subprocess.call([
"cp /usr/local/php-7.1.1/php.ini-production /etc/php.ini && cp /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf"],
shell=True)
subprocess.call([
"cp /usr/local/php/etc/php-fpm.d/www.conf.default /usr/local/php/etc/php-fpm.d/www.conf"],
shell=True)
subprocess.call([
"cp /usr/local/php-7.1.1/sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm"],
shell=True)
print("给php启动脚本授权")
subprocess.call(["chmod +x /etc/init.d/php-fpm"], shell=True)
print("启动php")
subprocess.call(["/etc/init.d/php-fpm start"], shell=True)
print("设置开机自启")
subprocess.call(["chkconfig --add php-fpm"], shell=True) if n == 5: # 退出程序
print("Program will be quite!")
sys.exit()
else:
print('you select is not correct')
else:
print('you should input number')

python安装lnmp的更多相关文章

  1. yum安装lnmp

    python其他知识目录 1.安装LNMP之前要安装EPEL,以便安装源以外的软件,如Nginx,phpMyAdmin等. yum install epel-release 提示:EPEL,即Extr ...

  2. WordPress安装篇(4):YUM方式安装LNMP并部署WordPress

    YUM方式安装软件的优点就是简单.方便.快捷,本文介绍在Linux上如何使用YUM方式快速安装LNMP并部署WordPress.使用Linux CentOS 7.9 + Nginx 1.18 + My ...

  3. python安装、模块安装

    python安装 windows 下载安装包 https://www.python.org/downloads 改环境变量 [右键计算机]-->[属性]-->[高级系统设置]-->[ ...

  4. win7系统下python安装numpy,matplotlib,scipy和scikit-learn

    1.安装numpy,matplotlib,scipy和scikit-learn win7系统下直接采用pip或者下载源文件进行安装numpy,matplotlib,scipy时会遇到各种问题,这是因为 ...

  5. centos下编译安装lnmp

    centos下编译安装lnmp 本文以centos为背景在其中编译安装nginx搭建lnmp环境. 编译安装nginx时,需要事先安装 开发包组"Development Tools" ...

  6. python安装完毕后,提示找不到ssl模块的解决步骤

    转载自 醇酒醉影 python安装完毕后,提示找不到ssl模块: [root@localhost ~]# python2.7.5 Python 2.7.5 (default, Jun 3 2013, ...

  7. [python] 安装numpy+scipy+matlotlib+scikit-learn及问题解决

    这篇文章主要讲述Python如何安装Numpy.Scipy.Matlotlib.Scikit-learn等库的过程及遇到的问题解决方法.最近安装这个真是一把泪啊,各种不兼容问题和报错,希望文章对你有所 ...

  8. python安装numpy和pandas

    最近要对一系列数据做同比比较,需要用到numpy和pandas来计算,不过使用python安装numpy和pandas因为linux环境没有外网遇到了很多问题就记下来了.首要条件,python版本必须 ...

  9. CentOS安装LNMP环境的基础组件

    注:以下所有操作均在CentOS 6.5 x86_64位系统下完成. 在安装LNMP环境之前,请确保已经使用yum安装了以下各类基础组件(如果系统已自带,还可以考虑yum update下基础组件): ...

随机推荐

  1. Prometheus+Grafana监控

    什么是Prometheus? Prometheus是由SoundCloud开发的开源监控报警系统和时序列数据库(TSDB).Prometheus使用Go语言开发,是Google BorgMon监控系统 ...

  2. socket、端口、进程的关系

    本文属网络编程部分.socket的引入是为了解决不同计算机间进程间通信的问题. 端口是TCP/IP协议中的概念,描述的是TCP协议上的对应的应用,可以理解为基于TCP的系统服务,或者说系统进程!如下图 ...

  3. Redis的下载、安装及启动

    一.下载Redis 1. redis 的下载路径 https://pan.baidu.com/s/1tdMzOlcTlFC7Z3a3I_59hQ 提取码:5tgy 二.安装Redis cd到当前解压目 ...

  4. 修改DEDE文章标题长度,解决DEDE文章标题显示不全

    在用dede调用列表标题出来的时候,会发现标题文字字数显示不完全,那是因为dede默认标题出来长度是30个字符,为了让标题显示完整,要做以下修改! 进入后台–系统–系统设置–系统基本参数–其他选项–文 ...

  5. MongoDB 分片键分类与数据分发

    In sharded clusters, if you do not use the _id field as the shard key, then your application must en ...

  6. 二十.Nginx反向代理、Nginx的TCP/UDP调度器、Nginx常见问题处理

    proxy client web1 web2 1.nginx反向代理   使用Nginx实现Web反向代理功能,实现如下功能:   后端Web服务器两台(web1 192.168.2.100 web2 ...

  7. linux系列(五):rm命令

    rm是一个危险的命令,使用的时候要特别当心,尤其对于新手,否则整个系统就会毁在这个命令(比如在/(根目录)下执行rm * -rf).所以,我们在执行rm之前最好先确认一下在哪个目录,到底要删除什么东西 ...

  8. wepy项目的学习

    使用Promise 开发实时编译 wepy build --watch 安装依赖 cd myproject npm install 安装(更新) wepy 命令行工具. npm install wep ...

  9. P1069 细胞分裂——数学题,质因数分解

    P1069 细胞分裂 我们求的就是(x^k)|(m1^m2) k的最小值: 先给m1分解质因数,再给每个细胞分解: 如果m1有的质因数,细胞没有就跳过: 否则就记录答案: 注意整数除法下取整的原则: ...

  10. python pillow 绘制图片

    demo1 #coding=utf- from PIL import Image img = Image.,))###创建一个5*5的图片 pixTuple = (,,,)###三个参数依次为R,G, ...