#!/bin/sh # Name: Atomic Archive configuration script # License: GPLv3 # Credits # Scott R. Shinn (atomicorp) # Andy Gredler (rackspace) if [ ! -f /etc/redhat-release ]; then echo "Error: /etc/redhat-release was not detected" exit 1 fi RELEASE=`cat /etc/redhat-release | awk -F\( ‘{print $1}‘` ATOMIC_VER="2.0.14" VERSION="1.0-19" SERVER=updates.atomicorp.com ARCH=`uname -i` REDHAT=0 # Input validation function # check_input <msg> <valid responses regex> <default> # if <default> is passed on as null, then there is no default # Example: check_input "Some question (yes/no) " "yes|no" "yes" function check_input { message=$1 validate=$2 default=$3 while [ $? -ne 1 ]; do echo -n "$message " read INPUTTEXT < /dev/tty if [ "$INPUTTEXT" == "" -a "$default" != "" ]; then INPUTTEXT=$default return 1 fi echo $INPUTTEXT | egrep -q "$validate" && return 1 echo "Invalid input" done } if [ "$query" == "no" ]; then echo "Exiting" echo exit 1 fi if rpm -q atomic-release > /dev/null ; then if [ ! -f /etc/yum.repos.d/atomic.repo ]; then rpm -e atomic-release # else # echo # echo "atomic-release is already installed." # echo "Exiting...." # echo # exit 0 fi fi echo echo "Configuring the [atomic] yum archive for this system " echo if grep -q "Red Hat Linux release 9 " /etc/redhat-release ; then DIST="rh9" DIR=redhat/9 echo echo "$RELEASE is no longer supported." echo exit 1 elif grep -q "Fedora Core release 2 " /etc/redhat-release ; then DIST="fc2" DIR=fedora/2 echo echo "$RELEASE is no longer supported." echo exit 1 elif grep -q "Fedora Core release 3 " /etc/redhat-release ; then DIST="fc3" DIR=fedora/3 echo echo "$RELEASE is no longer supported." echo exit 1 #YUMDEPS="fedora-release python-elementtree python-sqlite python-urlgrabber yum" elif grep -q "Fedora Core release 4 " /etc/redhat-release ; then DIST="fc4" DIR=fedora/4 YUMDEPS="fedora-release python-elementtree python-sqlite python-urlgrabber yum" PLESKREPO="plesk-fedora" elif grep -q "Fedora Core release 5 " /etc/redhat-release ; then DIST="fc5" DIR=fedora/5 YUMDEPS="fedora-release python-elementtree python-sqlite python-urlgrabber yum" PLESKREPO="plesk-fedora" elif grep -q "Fedora Core release 6 " /etc/redhat-release ; then DIST="fc6" DIR=fedora/6 YUMDEPS="fedora-release python-elementtree python-sqlite python-urlgrabber yum rpm-python" PLESKREPO="plesk-fedora" elif grep -q "Fedora release 7 " /etc/redhat-release ; then DIST="fc7" DIR=fedora/7 YUMDEPS="fedora-release python-elementtree python-sqlite python-urlgrabber yumrpm-python" PLESKREPO="plesk-fedora" elif grep -q "Fedora release 8 " /etc/redhat-release ; then DIST="fc8" DIR=fedora/8 YUMDEPS="fedora-release python-elementtree python-sqlite python-urlgrabber yumrpm-python" PLESKREPO="plesk-fedora" elif grep -q "Fedora release 9 " /etc/redhat-release ; then DIST="fc9" DIR=fedora/9 YUMDEPS="fedora-release python-elementtree python-sqlite python-urlgrabber yumrpm-python" PLESKREPO="plesk-fedora" DISABLE_PLESK=yes elif grep -q "Fedora release 10 " /etc/redhat-release ; then DIST="fc10" DIR=fedora/10 YUMDEPS="fedora-release python-elementtree python-sqlite python-urlgrabber yumrpm-python" PLESKREPO="plesk-fedora" DISABLE_PLESK=yes elif grep -q "Fedora release 11 " /etc/redhat-release ; then DIST="fc11" DIR=fedora/11 YUMDEPS="fedora-release python-elementtree python-sqlite python-urlgrabber yumrpm-python" PLESKREPO="plesk-fedora" DISABLE_PLESK=yes elif grep -q "Fedora release 12 " /etc/redhat-release ; then DIST="fc12" DIR=fedora/12 YUMDEPS="fedora-release python-elementtree python-sqlite python-urlgrabber yumrpm-python" PLESKREPO="plesk-fedora" DISABLE_PLESK=yes elif grep -q "Fedora release 13 " /etc/redhat-release ; then DIST="fc13" DIR=fedora/13 G YUMDEPS="fedora-release python-elementtree python-sqlite python-urlgrabber yumrpm-python" PLESKREPO="plesk-fedora" DISABLE_PLESK=yes elif grep -q "Fedora release 14 " /etc/redhat-release ; then DIST="fc14" DIR=fedora/14 YUMDEPS="fedora-release python-elementtree python-sqlite python-urlgrabber yumrpm-python" PLESKREPO="plesk-fedora" DISABLE_PLESK=yes elif grep -q "Fedora release 15 " /etc/redhat-release ; then DIST="fc15" DIR=fedora/15 YUMDEPS="fedora-release python-elementtree python-sqlite python-urlgrabber yumrpm-python" PLESKREPO="plesk-fedora" DISABLE_PLESK=yes elif grep -q "Fedora release 16 " /etc/redhat-release ; then DIST="fc16" DIR=fedora/16 YUMDEPS="fedora-release python-elementtree python-sqlite python-urlgrabber yumrpm-python" PLESKREPO="plesk-fedora" DISABLE_PLESK=yes elif grep -q "Fedora release 17 " /etc/redhat-release ; then DIST="fc17" DIR=fedora/17 YUMDEPS="fedora-release python-elementtree python-sqlite python-urlgrabber yumrpm-python" elif grep -q "Fedora release 18 " /etc/redhat-release ; then DIST="fc18" DIR=fedora/18 elif grep -q "Fedora release 19 " /etc/redhat-release ; then DIST="fc19" DIR=fedora/19 elif grep -q "Fedora release 20 " /etc/redhat-release ; then DIST="fc20" DIR=fedora/20 elif grep -q "Fedora release 21 " /etc/redhat-release ; then DIST="fc21" DIR=fedora/21 elif grep -q "Fedora release 22 " /etc/redhat-release ; then DIST="fc22" DIR=fedora/22 elif grep -q "Fedora release 23 " /etc/redhat-release ; then DIST="fc23" DIR=fedora/23 elif egrep -q "Red Hat Enterprise Linux (A|E)S release 3 " /etc/redhat-release ; then DIST="el3" DIR=redhat/3 echo echo "$RELEASE is not supported at this time, you will need to configure yum manually:" echo "see http://$SERVER/channels for instructions" echo exit 1 elif grep -q "CentOS release 3" /etc/redhat-release ; then DIST="el3" DIR=centos/3 echo echo "$RELEASE is not supported at this time, you will need to configure yum manually:" echo "see http://$SERVER/channels for instructions" echo exit 1 elif egrep -q "Red Hat Enterprise Linux (A|E|W)S release 4" /etc/redhat-release ; then REDHAT=1 DIST="el4" DIR=redhat/4 YUMDEPS="python-elementtree python-sqlite python-urlgrabber yum sqlite" PLESKREPO="plesk-redhat" elif egrep -q "Red Hat Enterprise Linux.*release 5" /etc/redhat-release ; then REDHAT=1 DIST="el5" DIR=redhat/5 YUMDEPS="rpm-python python-elementtree python-sqlite python-urlgrabber yum sqlite" PLESKREPO="plesk-redhat" elif egrep -q "Red Hat Enterprise Linux.*release 6" /etc/redhat-release ; then REDHAT=1 DIST="el6" DIR=redhat/6 YUMDEPS="rpm-python python-elementtree python-sqlite python-urlgrabber yum sqlite" PLESKREPO="plesk-redhat" elif egrep -q "Red Hat Enterprise Linux.*release 7" /etc/redhat-release ; then REDHAT=1 DIST="el7" DIR=redhat/7 YUMDEPS="rpm-python python-elementtree python-sqlite python-urlgrabber yum sqlite" PLESKREPO="plesk-redhat" elif grep -q "CentOS release 3" /etc/redhat-release ; then DIST="el3" DIR=centos/3 YUMDEPS="centos-release python-elementtree python-sqlite python-urlgrabber yum sqlite" PLESKREPO="plesk-centos" elif grep -q "CentOS release 4" /etc/redhat-release ; then DIST="el4" DIR=centos/4 YUMDEPS="centos-release python-elementtree python-sqlite python-urlgrabber yum sqlite" PLESKREPO="plesk-centos" elif egrep -q "(release 5|release 2011)" /etc/redhat-release ; then DIST="el5" DIR=centos/5 YUMDEPS="rpm-python centos-release python-elementtree python-sqlite python-urlgrabber yum sqlite m2crypto" PLESKREPO="plesk-centos" # Fc6 uses "release 6" so we need the whole thing here elif egrep -q "(release 6|release 2012)" /etc/redhat-release ; then DIST="el6" DIR=centos/6 YUMDEPS="rpm-python centos-release python-elementtree python-sqlite python-urlgrabber yum sqlite m2crypto" PLESKREPO="plesk-centos" elif egrep -q "(release 7|release 2014)" /etc/redhat-release ; then DIST="el7" DIR=centos/7 YUMDEPS="rpm-python centos-release python-elementtree python-sqlite python-urlgrabber yum sqlite m2crypto" PLESKREPO="plesk-centos" else echo "Error: Unable to determine distribution type. Please send the contents of /etc/redhat-release to support@atomicrocketturtle.com" exit 1 fi ATOMIC=atomic-release-$VERSION.$DIST.art.noarch.rpm # for up2date SOURCES="yum atomic http://www.atomicorp.com/channels/atomic/$DIR/$ARCH" # Yum install function function installyum { opts=$1 if [ ! -d atomic/yumdeps ]; then mkdir -p atomic/yumdeps/ fi cd atomic/yumdeps if [ -f $DIST-$ARCH-yumdeps.tar.gz ]; then rm -f $DIST-$ARCH-yumdeps.tar.gz fi #echo "wget -q http://$SERVER/installers/yum/$DIST-$ARCH-yumdeps.tar.gz" wget -q http://$SERVER/installers/yum/$DIST-$ARCH-yumdeps.tar.gz || exit 1 tar zxf $DIST-$ARCH-yumdeps.tar.gz for i in $YUMDEPS; do rpm --quiet --queryformat=%{NAME} -q $i || INSTALLDEPS="$i*rpm $INSTALLDEPS" done #echo "DEBUG $INSTALLDEPS" rpm -Uvh $opts $INSTALLDEPS } echo -n "Installing the Atomic GPG keys: " if [ ! -f RPM-GPG-KEY.art.txt ]; then wget -q https://www.atomicorp.com/RPM-GPG-KEY.art.txt 1>/dev/null 2>&1 fi rpm -import RPM-GPG-KEY.art.txt >/dev/null 2>&1 if [ ! -f RPM-GPG-KEY.atomicorp.txt ]; then wget -q https://www.atomicorp.com/RPM-GPG-KEY.atomicorp.txt 1>/dev/null 2>&1 fi rpm -import RPM-GPG-KEY.atomicorp.txt >/dev/null 2>&1 echo "OK" echo if [ ! -f /usr/bin/yum ]; then echo "Yum was not detected. Attempting to resolve.. " echo # If were on RHEL4, ask if they want to convert to centos, or use up2date if [ "$REDHAT" == "1" ]; then echo echo "Redhat Enterprise Linux Detected.." echo " If you do not have a valid RHEL subscription, this utility can be used" echo " to convert this system to centos. If you do have a valid subscription" echo " just hit enter, or n to continue. The installer will add the [atomic]" echo " channel to up2date, and *attempt* to install yum." echo #echo -n "Convert this system to CentOS? (y/n) [Default: no]: " #read useyum < /dev/tty useyum=$INPUTTEXT if [ "$useyum" == "y" ]; then echo "Installing yum from CentOS" YUMDEPS="centos-release $YUMDEPS" PLESKREPO="plesk-centos" installyum else echo "Attempting to configure [atomic] for up2date" if egrep -q "^yum atomic" /etc/sysconfig/rhn/sources ; then echo "atomic channel detected" else echo $SOURCES >> /etc/sysconfig/rhn/sources fi echo "Attempting to set up yum for RHEL" echo -n " Installing RPM GPG key: " wget -q http://www.atomicorp.com/installers/yum/RPM-GPG-KEY-c4 1>/dev/null 2>&1 rpm -import RPM-GPG-KEY-c4 >/dev/null 2>&1 echo "OK" installyum "--nodeps" YUM=1 fi else # for everyone else installyum YUM=1 fi else YUM=1 fi if [ "$YUM" == "1" ]; then ATOMICRELEASE=0 echo -n "Downloading $ATOMIC: " wget -q http://$SERVER/channels/atomic/$DIR/$ARCH/RPMS/$ATOMIC >/dev/null 2>&1 || exit $? if [ $? -ne 0 ]; then echo "Error: File $ATOMIC not found." echo exit fi if [ -f $ATOMIC ]; then rpm -Uvh $ATOMIC || exit 1 rm -f $ATOMIC else echo "ERROR: $ATOMIC was not downloaded." exit 1 fi echo "OK" fi if [ ! -f /etc/yum.repos.d/atomic.repo ]; then echo "Error: /etc/yum.repos.d/atomic.repo was not detected." exit 1 fi if [ -f /etc/yum.repos.d/plesk.repo ]; then rm -f /etc/yum.repos.d/plesk.repo fi fi
#------------------CentOS lnmp环境-------------# #! /bin/bash #执行之前需要把上面的nginx文件放入同等目录下 echo "一:配置iptables Please Wait" #1、配置防火墙,开启80端口、3306端口 iptables -I INPUT -m state --state NEW -m tcp -p tcp --dport 80 -j ACCEPT iptables -I INPUT -m state --state NEW -m tcp -p tcp --dport 3306 -j ACCEPT service iptables save service iptables restart echo "二:关闭selinux" #2、关闭SELINUX \cp -rp /etc/selinux/config /etc/selinux/config.bak sed -i ‘7s/enforcing/disabled/‘ /etc/selinux/config #3、配置CentOS 6.2 第三方yum源(CentOS默认的标准源里没有nginx软件包) #yum install wget -y #echo "正在开始下载第三方nginx库文件 Please Wait" #sleep 2 #wget http://www.atomicorp.com/installers/atomic #sh ./atomic sh ./nginx yum check-update #执行更新一下yum仓库 echo "三:安装Nginx服务" #4.安装nginx yum install nginx -y service nginx restart chkconfig nginx on #设置为开机启动 /etc/init.d/nginx restart rm -rf /usr/share/nginx/html/* #删除nginx默认目录下html所有的文件 echo "四:安装Mysql服务" #5.安装mysql yum install mysql mysql-server -y #将mysql加入开机启动 chkconfig mysqld on #开启mysql服务 /etc/init.d/mysqld start #为Mysql设置登录密码 mysqladmin -uroot password "P@ssw0rd" #拷贝配置文件(强制覆盖/etc/my.cnf文件) \cp -rfp /usr/share/mysql/my-medium.cnf /etc/my.cnf #重启数据库 /etc/init.d/mysqld restart echo "五:安装PHP" #安装PHP (此处PHP的插件比较多) yum install php php-mysql php-gd libjpeg* php-imap php-ldap php-odbc php-pear php-xml php-xmlrpc php-mbstring php-mcrypt php-bcmath php-mhash libmcrypt libmcrypt-devel php-fpm -y #重启MySql /etc/init.d/mysqld restart #重启nginx /etc/init.d/nginx restart #启动php-fpm /etc/rc.d/init.d/php-fpm start #设置开机启动 chkconfig php-fpm on echo "六:配置nginx支持php" #备份原有配置文件 \cp /etc/nginx/nginx.conf /etc/nginx/nginx.confbak \cp /etc/nginx/conf.d/default.conf /etc/nginx/conf.d/default.confbak #添加默认文档 sed -i ‘14s/index index.html index.htm;/index index.php index.html index.htm;/‘ /etc/nginx/conf.d/default.conf #首先删除最后一行的数据 我们把需要的附加进去 sed -i ‘$d‘ /etc/nginx/conf.d/default.conf sed -i ‘$d‘ /etc/nginx/conf.d/default.conf sed -i ‘$d‘ /etc/nginx/conf.d/default.conf echo -e "location ~ \.php$ {\nroot /usr/share/nginx/html/;\nfastcgi_pass 127.0.0.1:9000;\nfastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;\ninclude fastcgi_params;\n}\n} " >> /etc/nginx/conf.d/default.conf sed -i ‘57s/fastcgi_param SCRIPT_FILENAME ;/fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;/‘ /etc/nginx/conf.d/default.conf #重启服务 /etc/init.d/nginx restart echo "七:配置PHP" #修改php.ini的配置 在946行下面添加时间 \cp /etc/php.ini /etc/php.inibak sed -i ‘946a date.timezone = PRC‘ /etc/php.ini sed -i ‘314s/^/;&/‘ /etc/php.ini sed -i ‘314a disable_functions = passthru,exec,system,chroot,scandir,chgrp,chown,shell_exec,proc_open,proc_get_status,ini_alter,ini_alter,ini_restore,dl,openlog,syslog,readlink,symlink,popepassthru,stream_socket_server,escapeshellcmd,dll,popen,disk_free_space,checkdnsrr,checkdnsrr,getservbyname,getservbyport,disk_total_space,posix_ctermid,posix_get_last_error,posix_getcwd, posix_getegid,posix_geteuid,posix_getgid, posix_getgrgid,posix_getgrnam,posix_getgroups,posix_getlogin,posix_getpgid,posix_getpgrp,posix_getpid, posix_getppid,posix_getpwnam,posix_getpwuid, posix_getrlimit, posix_getsid,posix_getuid,posix_isatty, posix_kill,posix_mkfifo,posix_setegid,posix_seteuid,posix_setgid, posix_setpgid,posix_setsid,posix_setuid,posix_strerror,posix_times,posix_ttyname,posix_uname‘ /etc/php.ini echo "配置php-fpm" #备份原有配置文件 \cp /etc/php-fpm.d/www.conf /etc/php-fpm.d/www.confbak #将fpm配置文件里面的39和41换成nginx用户和组 sed -i ‘39s/user = apache/user = nginx/ ‘ /etc/php-fpm.d/www.conf sed -i ‘41s/group = apache/group = nginx/‘ /etc/php-fpm.d/www.conf #重启MySql /etc/init.d/mysqld restart #重启nginx /etc/init.d/nginx restart #重启php-fpm /etc/rc.d/init.d/php-fpm restart echo "开始测试" #添加测试页 测试php版本 echo -e "<?php\nphpinfo();\n?> " > /usr/share/nginx/html/phpinfo.php #设置目录所有者 chown nginx.nginx /usr/share/nginx/html/ -R #设置目录权限 chmod 755 /usr/share/nginx/html/ -R echo "-----------------------------------------------" echo "LNMP安装成功" echo "Mysql 密码为P@ssw0rd" echo "nginx默认站点目录是:/usr/share/nginx/html/" echo "MySQL数据库目录是:/var/lib/mysql" echo "-----------------------------------------------"
原文:http://www.cnblogs.com/yangxiaofei/p/5015693.html