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

[经验分享] LNMP+memcached 脚本

[复制链接]
YunVN网友  发表于 2018-12-25 11:35:14 |阅读模式
  在rh6.4 版本测试通过  在centos 只要更改库文件的链接位置就可以
  #!/bin/bash
  NGINXDIR=/usr/local/nginx   定义了安装nginx位置
  MYSQLDIR=/usr/local/mysql   定义了安装mysql位置
  PHPDIR=/usr/local/php        定义了安装php位置
  STARTDIR=/usr/local/bin/memcached  定义饿了安装memcached命令的位置
  NGINX=nginx-1.2.0  定义了nginx源码包的版本
  MYSQL=mysql-5.1.34   定义了mysql源码包的版本
  PHP=php-5.4.9       定义了php源码包的版本
  LIB=libmcrypt-2.5.8    提供加密功能的库文件
  MHASH=mhash-0.9.9.9    定义了哈希函数库的版本
  LIBICONV=libiconv-1.13   处理中文各种编码之间的转换
  STABLE=libevent-2.0.21-stable  事件库
  MEMCACHED=memcached-1.4.5  memcached 版本
  MEMCACHE=memcache-2.2.5
  TAR=.tar.gz
  NGINXMBER=81  nginx配置失败后返回的值
  MYSQLMBER=82   mysql配置失败后返回的值
  PHPBER=83     php配置失败后返回来的值
  NGINXNU=84    nginx启动失败后返回来的值
  MYSQLNU=85    mysql初始化失败后返回来的值
  NGINXPID=86     nginx语法错误返回来的值
  MEMCACHEMBER=87   memcached配置失败后返回来的值
  PHPUNMBER=88    留着备用
  

  for  PORT in {80,3306}  利用for循环检查 80端口是否被占用
  

  do
  port1=`lsof -i :$PORT | awk 'NR==2{print $1}'`
    netstat -nl  | grep  :$PORT &>/dev/null
      if [ $? -eq 0 ];then
  
  pkill -9 $port1
  
        else
  echo " $PORT port already by release"
      fi
  done
  

  for WRAP in {freetype,freetype-devel,gcc,gcc-c++,openssl,openssl-devel,pcre,pcre-devel,zlib-devel,zlib,libxml2,libxml2-devel,curl,curl-devel,libpng,libpng-devel,openldap-devel,ncurses,ncurses-devel,openldap,openldap-clients,openldap-servers,pam_ldap,openjpeg-libs,libjpeg-turbo,libjpeg-turbo-devel}
  do
    rpm -q $WRAP  &> /dev/null
      if [ $? != 0 ];then
          yum -y install $WRAP
       else
  echo "$WRAP already install "
       fi
   done
  sleep 3
  

  echo "--------------------------install nginx wrap--------------------------- "
  

  for USER in {nginx,mysql}
  do
  id $USER &>/dev/null
  

  if [ $? != 0 ];then
  
     useradd $USER
  else
   echo "user $USER already be"
  

  fi
  done
  

  cd /root
  
  tar -zxf /root/$NGINX$TAR
   cd /root/$NGINX
  

  ./configure  --prefix=$NGINXDIR  \
       --pid-path=$NGINXDIR/nginx.pid \
  --user=nginx   --group=nginx  \
       --with-http_ssl_module  \
       --with-http_flv_module  \
       --with-http_stub_status_module  \
  --with-http_gzip_static_module \
       --http-client-body-temp-path=$NGINXDIR/client \
       --http-proxy-temp-path=$NGINXDIR/proxy  \
       --http-fastcgi-temp-path=$NGINXDIR/fcgi \
  --http-scgi-temp-path=$NGINXDIR/scgi  \
       --http-uwsgi-temp-path=$NGINXDIR/uwsgi \
       --with-pcre
    if [ $? -eq 0 ];then
  make && make install
     else
  echo "nginx configure failed"
    exit $NGINXMBER
      fi
  ln -s $NGINXDIR/sbin/nginx /usr/sbin
  nginx -c  $NGINXDIR/conf/nginx.conf
  
  sleep 3
  echo "----------------------install libmcrypt wrap---------------------"
  cd /root
  tar -zxf /root/$LIB$TAR
  cd /root/$LIB
  ./configure  && make && make install
  cd libltdl
  ./configure  --with-gmetad --enable-gexec  --enable-ltdl-install && make && make install
  

  sleep 3
  echo "----------------------install mysql  wrap------------------------"
  

  cd /root
  tar -zxf /root/$MYSQL$TAR
  cd /root/$MYSQL
  ./configure  --prefix=$MYSQLDIR  --without-debug \
       --with-innodb --with-plugins=partition \
  --with-extra-charsets=all  --enable-assembler \
       --with-mysqld-ldflags=-all-static \
       --with-client-ldflags=-all-static \
       --with-unix-socket-path=/tmp/mysql.sock \
       --with-ssl
  if [ $? -eq 0 ];then
             make && make install
        else
             echo " mysql configure failed "
       exit $MYSQLMBER
  fi
  chown -R mysql.mysql $MYSQLDIR/*
  test -f /etc/my.cnf
  

    if [ $? != 0 ];then
        cp /root/$MYSQL/support-files/my-medium.cnf /etc/my.cnf
      else
        mv /etc/my.cnf  /etc/my.conf
  cp /root/$MYSQL/support-files/my-medium.cnf /etc/my.cnf
      fi
  cp /root/$MYSQL/support-files/mysql.server /etc/init.d/mysql
  
  ln -s $MYSQLDIR/bin/* /usr/bin
   ln -s $MYSQLDIR/lib/mysql/* /usr/lib64/
    ln -s $MYSQLDIR/include/mysql/* /usr/include/
     sed -i  's/^skip-federated$/# skip-federated/' /etc/my.cnf
  chmod +x /etc/init.d/mysql
  mysql_install_db --user=mysql
       if [ $? -eq 0 ];then
  service mysql restart
  chkconfig --add mysql
    chkconfig mysql on
  else
    echo "mysql initialize failed"
     exit $MYSQLNU
  fi
  sleep  3
  

  echo "----------------------install mhash -------------------------------"
  

  cd /root
  tar -zxf /root/$MHASH$TAR
  cd /root/$MHASH
  ./configure  && make && make install
  

  sleep 3
  

  echo "----------------------install libiconv---------------------------"
  cd /root
  tar -zxf /root/$LIBICONV$TAR
  cd /root/$LIBICONV
  ./configure  &&  make && make install
  

  sleep 3
  

  echo"-------------------install php wrap ---------------------------------"
  \cp -rfp /usr/lib64/libldap* /usr/lib/
  ln -s /usr/local/lib/libmcrypt* /usr/lib/
  ln -s /usr/local/lib/libmhash.* /usr/lib/
  ldconfig -v &> /dev/null
  cd /root
  tar -zxf $PHP$TAR
  cd $PHP
  ./configure  --prefix=$PHPDIR  --with-mysql=$MYSQLDIR \
       --with-zlib  --enable-xml --disable-rpath  \
       --enable-safe-mode   --enable-bcmath  \
       --enable-shmod  --enable-sysvsem  \
       --with-curl   --with-curlwrappers  \
       --enable-fpm   --enable-fastcgi   \
       --with-mcrypt   --with-gd  \
       --with-openssl  --with-mhash  \
       --with-mysqli=$MYSQLDIR/bin/mysql_config \
       --with-iconv-dir=/usr/lcoal   \
       --with-png-dir   --with-jpeg-dir  \
       --with-freetype-dir  --enable-gd-native-ttf  \
       --with-libxml-dir=/usr  \
       --enable-sockets  --with-ldap \
       --with-ldap-sasl --with-xmlrpc --enable-zip \
       --enable-soap
   if [ $? -eq 0 ];then
  make ZEND_EXTRA_LIBS='-liconv' && make install
  #     if [ $? != 0 ];then
  #echo "php make install failed"
  #  exit $PHPUNMBER
     else
  echo "php configure failed"
          exit $PHPMBER
     fi
  #              fi
  \cp /root/$PHP/php.ini-production $PHPDIR/php/php.ini
  \cp $PHPDIR/etc/php-fpm.conf.default $PHPDIR/etc/php-fpm.conf
  sed -i '/fpm.pid/s/;//' $PHPDIR/etc/php-fpm.conf
  sed -i '26a error_log = log/php-fpm.log' $PHPDIR/etc/php-fpm.conf
  sed -i '27a log_level = error' $PHPDIR/etc/php-fpm.conf
  sed -i '/daemonize/s/;// ' $PHPDIR/etc/php-fpm.conf
  sed -i '/user/s/nobody/nginx/' $PHPDIR/etc/php-fpm.conf
  sed -i '/group/s/nobody/nginx/' $PHPDIR/etc/php-fpm.conf
  #        for FAST-CGI in {pm.max_children,pm.start_servers,pm.min_spare_servers,pm.max_spare_servers}
  #          do
  #            for NUMBER in {32,15,5,32}
  #             do
  #               sed -i '/$FAST-CGI/s/[0-9]/$NUMBER/' $PHPDIR/etc/php-fpm.conf
  #          done
  #      done
  cp -rf /root/$PHP/sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
  chmod +x /etc/init.d/php-fpm
  chkconfig --add php-fpm
  service php-fpm restart
     chkconfig php-fpm on
    sed -i '/index.php/s/#//' $NGINXDIR/conf/nginx.conf
  sed -i '45c index index.php index.html index.html;' $NGINXDIR/conf/nginx.conf
  sed -i '/fastcgi_pass/s/#//' $NGINXDIR/conf/nginx.conf
  sed -i '/fastcgi_param/s/#//' $NGINXDIR/conf/nginx.conf
  sed -i '/include/s/#//g' $NGINXDIR/conf/nginx.conf
  sed -i '66a root  html;' $NGINXDIR/conf/nginx.conf
  sed -i '71a }'  $NGINXDIR/conf/nginx.conf
  sed -i '65a    location ~ \.php$ { ' $NGINXDIR/conf/nginx.conf
  
  sed -i '/nginx/s/$nginx_version//' $NGINXDIR/conf/fastcgi_params
  sed -i '4a fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;' $NGINXDIR/conf/fastcgi_params
  

  pkill -9 nginx
  nginx -t
  
  if [ $? -eq 0 ];then
  nginx
           else
             echo "configure file have  failed"
               exit $NGINXPID
            fi
  sleep  3
  

  echo "-------------------install libevent--------------------------"
  cd /root
  tar -zxf /root/$STABLE$TAR
  cd /root/$STABLE
  ./configure  && make && make install
  

  echo /usr/local/lib/  >> /etc/ld.so.conf.d/libevent.conf
  #     ldconfig $>/dev/null
  

  sleep 3
  

  echo "----------------------install memcached--------------------------"
  cd /root
  tar -zxf /root/$MEMCACHED$TAR
  cd /root/$MEMCACHED
  ./configure   && make  &&  make install
  $STARTDIR -u root -m 100 -c 200 -n 10 -f 2 -d
  

  sleep 3
  echo "----------------------install memcache----------------------------"
  cd /root
  tar -zxf /root/$MEMCACHE.tgz
  cd /root/$MEMCACHE
  $PHPDIR/bin/phpize
  ./configure   --with-php-config=$PHPDIR/bin/php-config  \
  --enable-memcache
  if [ $? -eq 0 ];then
  make && make install
  else
     echo "memcache install failed"
  exit  $MEMCACHEMBER
  fi
  sed -i '728a extension_dir=鈥?usr/local/php5nginx/lib/php/extensions/no-debug-non-zts-20100525/鈥?  $PHPDIR/php/php.ini
     sed -i '729a extension=memcache.so'
    service php-fpm reload
  echo "http {" >> $NGINXDIR/conf/nginx.conf
  echo "   upstream  web {" >> $NGINXDIR/conf/nginx.conf
  echo "      server 200.1.1.20:80;"  >> $NGINXDIR/conf/nginx.conf
  echo "      server 200.1.1.30:80;"  >> $NGINXDIR/conf/nginx.conf
  echo " }" >> $NGINXDIR/conf/nginx.conf
  echo "    server {"  >> $NGINXDIR/conf/nginx.conf
  echo "       listen 80;" >> $NGINXDIR/conf/nginx.conf
  echo "       server_name www.baidu.com;"  >> $NGINXDIR/conf/nginx.conf
  echo "     location / {" >> $NGINXDIR/conf/nginx.conf
  echo '       set $memcached_key $uri;' >> $NGINXDIR/conf/nginx.conf
  echo '       memcached_pass 127.0.0.1:11211;'  >> $NGINXDIR/conf/nginx.conf
  echo "       default_type text/html;" >> $NGINXDIR/conf/nginx.conf
  echo "       error_page 404 @fallback;"  >> $NGINXDIR/conf/nginx.conf
  echo "   }" >> $NGINXDIR/conf/nginx.conf
  echo "      location @fallback {"  >> $NGINXDIR/conf/nginx.conf
  echo "        proxy_pass http://web;"  >> $NGINXDIR/conf/nginx.conf
  echo "  }" >> $NGINXDIR/conf/nginx.conf
  echo " } "  >> $NGINXDIR/conf/nginx.conf
  echo " }"  >> $NGINXDIR/conf/nginx.conf
  pkill -9 nginx
  nginx -t
  if [ $? -eq 0 ];then
  nginx
  else
  echo "because of memcached configure file failed "
  fi
  
  





运维网声明 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-655654-1-1.html 上篇帖子: Memcached 客户端使用 下篇帖子: memcached一英文调用实例
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

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

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

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

扫描微信二维码查看详情

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


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


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


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



合作伙伴: 青云cloud

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