#!/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. 12 复习 - webpack基本配置1

    1.npm包管理工具 npm init -y 如果创建的项目的根目录名称是中文或者包含中文,不能使用-y npm init 回车时要求你输入包的名称,自己手写项目名称,例test 2.新建src,di ...

  2. HTML5 服务器发送事件(Server-Sent Events)

    沈阳SEO:HTML5 服务器发送事件(server-sent event)允许网页获得来自服务器的更新. Server-Sent 事件 - 单向消息传递 Server-Sent 事件指的是网页自动获 ...

  3. 在mysql中用int类型存储IP

    SELECT INET_ATON( '127.0.0.1' ); SELECT INET_NTOA();

  4. Jedis常用方法API

    一.键操作 二.字符串操作 三.整数和浮点数操作 四.列表(List)操作 五.集合(Set)操作 六.哈希(Hash)操作 七.有序集合(Zsort)操作 八.排序操作

  5. MongoDB 3.2变动一览

    3.2测试版本总算release了!E叔带大家来一览MongoDB 3.2版本的真容. (PS:内容比较多,在此仅针对个人认为比较重要的进行讲解,markdown写的,貌似WP的markdown插件有 ...

  6. 前端利用webuploader实现超大文件分片上传、断点续传

    本人在2010年时使用swfupload为核心进行文件的批量上传的解决方案.见文章:WEB版一次选择多个文件进行批量上传(swfupload)的解决方案. 本人在2013年时使用plupload为核心 ...

  7. 【HTTP】图解HTTPS

    我们都知道HTTPS能够加密信息,以免敏感信息被第三方获取.所以很多银行网站或电子邮箱等等安全级别较高的服务都会采用HTTPS协议. HTTPS简介 HTTPS其实是有两部分组成:HTTP + SSL ...

  8. pyzabbix

    pyzabbix

  9. 18.4.09 模拟考 zhx P75

    题目链接 https://files.cnblogs.com/files/lovewhy/P75.pdf P75 竞赛时间: ????年??月??日??:??-??:?? 注意事项(请务必仔细阅读) ...

  10. python中如何给散点图上面的特定点做标记

    今天想在散点图的某些特定的点外面画圆圈标记,从下面的文章找到一些灵感,只要在原来的散点图上面给指点添加相应的标志,设置其透明度就可以实现该想法. 顺便复习下散点图的用法. 大家平时为了直观地显示数据的 ...