设为首页 收藏本站
查看: 594|回复: 0

[经验分享] LNMP(nginx+mysql+php)环境/架构 一键安装脚本

[复制链接]

尚未签到

发表于 2018-12-16 13:20:18 | 显示全部楼层 |阅读模式
  该脚本已经在centos 7.1 上测试通过,用时27分,硬件环境(1G,1U)。该脚本有安装PHP加速器xcache:
  

  
  #!/bin/bash
  

  #该脚本的作用 :在线一键部署LNMP
  #Write      :King
  #Date       :2015-03-19
  

  #mysql      数据存放目录为/data/mysql
  #php        主配置文件在 /usr/local/php/etc
  #nginx      web 程序目录/usr/local/nginx/html/index,主配置目录 /usr/local/nignx/conf/nginx.conf
  

  #源码下载目录
  SoftDir='/usr/local/src'
  

  #定义安装日志路径
  LOG_INS='/var/log/install.log'
  

  #定义Mysql 源码目录:
  MysqlS='/usr/local/mysql'
  

  #define make
  function MAKE(){
  if [ `echo $?` -eq 0 ];then
  make >> $LOG_INS 2>&1
  else
  exit
  fi
  }
  

  #define make install
  function MAKE_INS(){
  if [ `echo $?` -eq 0 ];then
  make install >> $LOG_INS 2>&1
  else
  exit
  fi
  }
  

  #安装系统扩展源:http://dl.fedoraproject.org/pub/epel
  if [ `awk '{print $3}' /etc/redhat-release |awk -F '.' '{print $1}'` -eq 6 ];then
  rpm -ivh http://dl.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm >> $LOG_INS 2>&1
  elif [ `awk '{print $4}' /etc/redhat-release |awk -F '.' '{print $1}'` -eq 7 ];then
  rpm -ivh http://dl.fedoraproject.org/pub/epel/7/x86_64/e/epel-release-7-5.noarch.rpm >> $LOG_INS 2>&1
  fi
  

  #安装系统运维包:
  yum install -y lrzsz gcc gcc-c++  bzip2 bzip2-devel make man vim tree unzip wget lua-devel lua-static patch libxml2-devel libxslt libxslt-devel gd gd-devel ntp ntpdate screen sysstat tree rsync lsof autoconf gettext  gettext-devel automake libtool git >> $LOG_INS 2>&1
  

  #升级系统:
  yum update -y >> $LOG_INS 2>&1
  

  #替换selinux 配置:
  sed -i 's/SELINUX=enforcing/SELINUX=disabled/' /etc/selinux/config
  

  #下载安装Mysql:  http://cdn.mysql.com/Downloads
  cd $SoftDir && wget -q http://www.linuser.com/share/soft/mysql-5.6.26-linux-glibc2.5-x86_64.tar.gz
  

  #解压:
  tar zxf mysql-5.6.26-linux-glibc2.5-x86_64.tar.gz
  

  #移动解压目录病重命名Mysql:
  mv mysql-5.6.26-linux-glibc2.5-x86_64 /usr/local/mysql
  

  #添加mysql 系统用户:
  if [ -z `grep mysql /etc/passwd` ] ;then
  useradd -s /sbin/nologin mysql
  fi
  

  #创建mysql 初始化数据目录:
  if [ ! -d "/data/mysql" ] ;then
  mkdir -p /data/mysql
  fi
  

  #将mysql 初始化目录所属主和组修改为mysql:
  chown -R mysql.mysql /data/mysql/
  

  #初始化
  cd $MysqlS && ./scripts/mysql_install_db --datadir=/data/mysql --user=mysql  >> $LOG_INS 2>&1
  

  #备份系统默认的my.cnf 文件:
  mv /etc/my.cnf{,.bak}
  

  #复制mysql 的 主配置文件到etc 目录下病重命名为my.cnf
  \cp support-files/my-default.cnf /etc/my.cnf
  

  #复制mysql 的启动脚本到/etc/init.d 目录下:
  \cp support-files/mysql.server /etc/init.d/mysqld
  

  #赋予启动755 权限:
  chmod 755 /etc/init.d/mysqld
  

  #修改my.cnf 文件配置如下:
  cat  /etc/my.cnf
  [mysqld]
  pid-file=/data/mysql/mysql.pid
  log-error=/var/log/mysql.log
  datadir = /data/mysql
  basedir = /usr/local/mysql
  character-set-server=utf8
  port = 3306
  socket = /tmp/mysql.sock
  key_buffer_size = 256M
  max_allowed_packet = 1M
  table_open_cache = 256
  sort_buffer_size = 1M
  read_buffer_size = 1M
  read_rnd_buffer_size = 4M
  myisam_sort_buffer_size = 64M
  thread_cache_size = 8
  query_cache_size = 16M
  thread_concurrency = 8
  binlog_format=mixed
  server-id = 1
  slow-query-log = 1
  slow-query-log-file = /data/mysql/mysql-slow.log
  log-bin = mysql-bin
  log-bin-index = mysql-bin.index
  symbolic-links = 0
  skip-name-resolve
  

  [client]
  port = 3306
  socket = /tmp/mysql.sock
  default-character-set=utf8
  

  [mysqldump]
  quick
  max_allowed_packet = 16M
  

  #[mysqld_safe]
  

  [mysql]
  no-auto-rehash
  

  [myisamchk]
  key_buffer_size = 128M
  sort_buffer_size = 128M
  read_buffer = 2M
  write_buffer = 2M
  

  [mysqlhotcopy]
  interactive-timeout
  EOF
  

  #启动mysql:
  service mysqld start
  

  if [ `echo $?` -eq 0 ] ;then
  echo "Mysql started"
  else
  exit
  fi
  

  #将Mysqld 设置为随机启动:
  chkconfig --add mysqld && chkconfig mysqld on
  

  #=====================================                 安装LTP          =======================================
  #下载LTP:
  cd $SoftDir &&  wget -q http://www.linuser.com/share/soft/ltp-full-20150420.tar.bz2
  

  #解压
  tar jxf ltp-full-20150420.tar.bz2
  

  #配置编译参数:
  cd ./ltp-full-20150420 && ./configure >> $LOG_INS 2>&1
  

  #编译及安装
  MAKE && MAKE_INS
  

  #=====================================                 安装openssl1.0.2           =======================================
  #下载openssl:
  cd $SoftDir &&  wget -q http://www.linuser.com/share/soft/openssl-1.0.2.tar.gz
  

  #解压:
  tar zxf openssl-1.0.2.tar.gz
  

  #进入解压目录,配置编译参数:
  cd ./openssl-1.0.2 && ./config >> $LOG_INS 2>&1
  

  #编译及安装
  MAKE && MAKE_INS
  

  #=====================================                 安装curl-7.45.0           =======================================
  #下载:
  cd $SoftDir &&  wget -q http://www.linuser.com/share/soft/curl-7.45.0.tar.gz
  

  #解压:
  tar zxf curl-7.45.0.tar.gz
  

  #进入解压目录,配置编译参数:
  cd ./curl-7.45.0 && ./configure >> $LOG_INS 2>&1
  

  #编译及安装
  MAKE && MAKE_INS
  

  #=====================================                 安装libmcrypt-2.5.8                  ==================================
  #下载:
  cd $SoftDir &&  wget -q http://www.linuser.com/share/soft/libmcrypt-2.5.8.tar.gz
  

  #解压:
  tar zxf libmcrypt-2.5.8.tar.gz
  

  #进入解压目录,配置编译参数:
  cd ./libmcrypt-2.5.8 && ./configure >> $LOG_INS 2>&1
  

  #编译及安装
  MAKE && MAKE_INS
  

  #=======================================        安装PHP 5.5.22          ====================================
  #下载PHP 5.5.22
  cd $SoftDir &&  wget -q http://www.linuser.com/share/soft/php-5.5.30.tar.gz
  

  #解压PHP:
  tar zxf php-5.5.30.tar.gz
  

  #添加php-fpm 用户,不允许登陆系统
  useradd -s /sbin/nologin php-fpm
  

  #进入PHP解压目录,配置编译参数:
  cd ./php-5.5.30 && ./configure --prefix=/usr/local/php   --with-config-file-path=/usr/local/php/etc  --enable-fpm   --with-fpm-user=php-fpm  --with-fpm-group=php-fpm   --with-mysql=/usr/local/mysql  --with-mysql-sock=/tmp/mysql.sock  --with-libxml-dir  --with-gd   --with-jpeg-dir   --with-png-dir   --with-freetype-dir  --with-iconv-dir   --with-zlib-dir   --with-mcrypt   --enable-soap   --enable-gd-native-ttf   --enable-ftp  --enable-mbstring  --enable-exif  --enable-zend-multibyte   --disable-ipv6   --with-pear   --with-curl --with-openssl --with-mysqli --enable-mysqlnd --with-gettext >> $LOG_INS 2>&1
  

  #编译及安装
  MAKE && MAKE_INS
  

  #复制Php 主配置:
  \cp php.ini-production /usr/local/php/etc/php.ini
  

  #创建php-fpm 主配置文件:
  cat > $LOG_INS 2>&1
  

  #编译及安装
  MAKE && MAKE_INS
  

  #=======================================        添加libmaxminddb        ====================================
  #下载:
  cd $SoftDir && wget -q http://www.linuser.com/share/soft/libmaxminddb-1.1.1.tar.gz
  

  #解压:
  tar zxf libmaxminddb-1.1.1.tar.gz
  

  cd ./libmaxminddb-1.1.1 && ./configure >> $LOG_INS 2>&1
  

  #编译及安装
  MAKE && MAKE_INS
  

  

  #=======================================        添加geoip2模块                ====================================
  #下载
  cd $SoftDir && wget -q  http://www.linuser.com/share/soft/ngx_http_geoip2_module-master.zip
  

  #解压:
  unzip ngx_http_geoip2_module-master.zip >> $LOG_INS 2>&1
  

  #=======================================        添加libuwind               ====================================
  #下载:
  cd $SoftDir && wget -q http://www.linuser.com/share/soft/libunwind-1.1.tar.gz
  

  #解压:
  tar zxf libunwind-1.1.tar.gz
  

  #进入解压目录,配置编译参数::
  cd ./libunwind-1.1 && ./configure >> $LOG_INS 2>&1
  

  #编译及安装
  MAKE && MAKE_INS
  

  #=======================================        添加gperftools                ====================================
  #下载:
  cd $SoftDir && wget -q http://www.linuser.com/share/soft/gperftools-master.zip
  

  #解压:
  unzip gperftools-master.zip
  

  #进入解压目录,执行autogen.sh 生产配置文件:
  cd ./gperftools-master && ./autogen.sh  >> $LOG_INS 2>&1
  

  #配置编译参数:
  if [ `echo $?` -eq 0 ];then
  ./configure >> $LOG_INS 2>&1
  else
  exit
  fi
  

  #编译及安装
  MAKE && MAKE_INS
  

  #=======================================        安装Tengine 2.1.0          ====================================
  #下载
  cd $SoftDir && wget -q http://www.linuser.com/share/soft/nginx-1.8.0.tar.gz
  #解压:
  tar zxf nginx-1.8.0.tar.gz
  

  #进入解压目录,配置编译参数:
  cd ./nginx-1.8.0 && ./configure --prefix=/usr/local/nginx --with-http_realip_module  --with-http_sub_module --with-http_dav_module --with-http_gzip_static_module --with-http_stub_status_module  --with-http_flv_module --with-http_mp4_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_auth_request_module --with-http_secure_link_module --with-http_stub_status_module --with-http_ssl_module --http-log-path=/var/log/nginx_access.log --with-google_perftools_module --with-pcre=/usr/local/src/pcre-8.37 --with-openssl=/usr/local/src/openssl-1.0.2 --add-module=/usr/local/src/ngx_http_geoip2_module-master >> $LOG_INS 2>&1
  

  #编译及安装
  MAKE && MAKE_INS
  

  #设置软链接
  ln -s /usr/local/lib/libmaxminddb.so.0 /usr/lib64
  ln -s /usr/local/lib/libprofiler.so.0 /usr/lib64
  ln -s /usr/local/lib/libunwind.so.8 /usr/lib64
  

  #检测初始化完成的nginx 配置是否有问题
  /usr/local/nginx/sbin/nginx  -t
  if [ `echo $?` -eq 0 ];then
  echo "Nginx installed successfully!"
  else
  exit
  fi
  

  #创建nginx 启动脚本
  cat

运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-652026-1-1.html 上篇帖子: 源码编译php 下篇帖子: CentOS 7系统之 lamp (php
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表