python安装lnmp
#!/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的更多相关文章
- yum安装lnmp
python其他知识目录 1.安装LNMP之前要安装EPEL,以便安装源以外的软件,如Nginx,phpMyAdmin等. yum install epel-release 提示:EPEL,即Extr ...
- WordPress安装篇(4):YUM方式安装LNMP并部署WordPress
YUM方式安装软件的优点就是简单.方便.快捷,本文介绍在Linux上如何使用YUM方式快速安装LNMP并部署WordPress.使用Linux CentOS 7.9 + Nginx 1.18 + My ...
- python安装、模块安装
python安装 windows 下载安装包 https://www.python.org/downloads 改环境变量 [右键计算机]-->[属性]-->[高级系统设置]-->[ ...
- win7系统下python安装numpy,matplotlib,scipy和scikit-learn
1.安装numpy,matplotlib,scipy和scikit-learn win7系统下直接采用pip或者下载源文件进行安装numpy,matplotlib,scipy时会遇到各种问题,这是因为 ...
- centos下编译安装lnmp
centos下编译安装lnmp 本文以centos为背景在其中编译安装nginx搭建lnmp环境. 编译安装nginx时,需要事先安装 开发包组"Development Tools" ...
- python安装完毕后,提示找不到ssl模块的解决步骤
转载自 醇酒醉影 python安装完毕后,提示找不到ssl模块: [root@localhost ~]# python2.7.5 Python 2.7.5 (default, Jun 3 2013, ...
- [python] 安装numpy+scipy+matlotlib+scikit-learn及问题解决
这篇文章主要讲述Python如何安装Numpy.Scipy.Matlotlib.Scikit-learn等库的过程及遇到的问题解决方法.最近安装这个真是一把泪啊,各种不兼容问题和报错,希望文章对你有所 ...
- python安装numpy和pandas
最近要对一系列数据做同比比较,需要用到numpy和pandas来计算,不过使用python安装numpy和pandas因为linux环境没有外网遇到了很多问题就记下来了.首要条件,python版本必须 ...
- CentOS安装LNMP环境的基础组件
注:以下所有操作均在CentOS 6.5 x86_64位系统下完成. 在安装LNMP环境之前,请确保已经使用yum安装了以下各类基础组件(如果系统已自带,还可以考虑yum update下基础组件): ...
随机推荐
- 改变某个对象的CSS样式时,不要使用JS直接添加样式,
重绘: 使用js改变网页的背景颜色 浏览器会把整个网页的颜色重新在画一遍,导致性能降低 回流: 只要改变某个DOM对象的宽或者高,浏览器就会重新再计算网页结构,重新生成一次,导致性能严重降低. CSS ...
- PHP 创建 MySQL 表
CREATE TABLE 语句用于创建 MySQL 表. 创建表前,我们需要使用 use myDB 来选择要操作的数据库: use myDB; 我们将创建一个名为 "MyGuests&quo ...
- MySQL-时间日期类型
一.MySQL中 日期和时间类型 表示时间值的日期和时间类型为 DATETIME.DATE.TIMESTAMP.TIME和YEAR. 每个时间类型有一个有效值范围和一个"零"值,当 ...
- 学到了林海峰,武沛齐讲的Day16完
函数嵌套 foo()()() ==== foo()>>>gxr gxr()>>>wsb wsb()>>执行wsb函数 lambda 一行 ...
- Mysql开启慢查询命令
; 查询: SHOW VARIABLES LIKE '%slow_query_log%'; 结果:
- Linux ntp 时间同步服务配置
一.基础环境 1.操作系统:CentOS 7.3 2.ntp:4.2.6 3.机器,服务端(192.168.1.210)客户端(192.168.1.211) 二.安装ntp yum -y instal ...
- Greenplum 监控segment是否正常
在greenplum运行过程中,Segement很有可能因为压力大出现不可用的情况, 主备Segement发现了切换,或是主备Segement网络断开,数据不同步了.在 默认情况下,如果GreenPl ...
- php利用webuploader实现超大文件分片上传、断点续传
PHP用超级全局变量数组$_FILES来记录文件上传相关信息的. 1.file_uploads=on/off 是否允许通过http方式上传文件 2.max_execution_time=30 允许脚本 ...
- angular2事件触发
输入框输入过程触发Select()方法. <input type="text" name="code" [(ngModel)]="code&qu ...
- SpatialHadoop的编译与运行
本文通过MetaWeblog自动发布,原文及更新链接:https://extendswind.top/posts/technical/spatialhadoop_compile_and_run Spa ...