#!/bin/bash
#定义PATH变量
PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin
#声明PATH为环境变量
export PATH
# Check if user is root
#id -u 当前用户的uid,也可以使用反引号`id -u`,效果一样,0为root的用户id
if [ $(id -u) != "0" ]; then
echo "Error: You must be root to run this script, please use root to install lnmp"
exit 1
fi
#清屏操作
clear
#可以识别特殊字符
printf "=======================================================================\n"
printf "Install Apache for LNMP V1.0 , Written by Licess \n"
printf "=======================================================================\n"
printf "LNMP is a tool to auto-compile & install Nginx+MySQL+PHP on Linux \n"
printf "This script is a tool to install Apache for lnmp \n"
printf "\n"
printf "For more information please visit http://www.lnmp.org \n"
printf "=======================================================================\n"
#把当前路径给变量cur_dir
cur_dir=$(pwd)
#这个重点说一下,察看ip,
#通过1次grep,过滤掉不包含inet的行
#2次反向grep也就是取不包含的行,过滤掉包含127.0.0.1和inet6的行
#awk 打印第2列
#tr -d 去掉addr:,这样就只剩下ip
ipv4=`ifconfig -a|grep inet|grep -v 127.0.0.1|grep -v inet6|awk '{print $2}'|tr -d "addr:"`
#set Server Administrator Email Address
ServerAdmin=""
#读取用户键盘输入还可以使用-t 30 指定时间限制
read -p "Please input Administrator Email Address:" ServerAdmin
if [ "$ServerAdmin" == "" ]; then
echo "Administrator Email Address will set to webmaster@example.com!"
ServerAdmin="webmaster@example.com"
else
echo "==========================="
echo Server Administrator Email="$ServerAdmin"
echo "==========================="
fi
#定义函数
get_char()
{
#打印当前终端的设置赋予变量
SAVEDSTTY=`stty -g`
#echo input characters
stty -echo
stty cbreak
#把指定的输入文件拷贝到指定的输出文件中,并且在拷贝的过程中可以进行格式转换
#if =输入文件,bs = bytes 同时设置读/写缓冲区的字节数(等于设置obs和ibs),count = blocks 只拷贝输入的blocks块
dd if=/dev/tty bs=1 count=1 2> /dev/null
stty -raw
stty echo
stty $SAVEDSTTY
}
echo ""
echo "Press any key to start install Apache for LNMP or Press Ctrl+C to cancel..."
char=`get_char`
printf "===================== Check And Download Files =================\n"
#test测试 如果文件的长度不为零,则为真
if [ -s httpd-2.2.22.tar.gz ]; then
echo "httpd-2.2.22.tar.gz [found]"
else
echo "Error: httpd-2.2.22.tar.gz not found!!!download now......"
wget -c http://soft.vpser.net/web/apache/httpd-2.2.22.tar.gz
fi
#mod_rpaf是apache的一个模块,目的是为了获取访客的真实IP
if [ -s mod_rpaf-0.6.tar.gz ]; then
echo "mod_rpaf-0.6.tar.gz [found]"
else
echo "Error: mod_rpaf-0.6.tar.gz not found!!!download now......"
wget -c http://soft.vpser.net/web/apache/rpaf/mod_rpaf-0.6.tar.gz
fi
#php源码
if [ -s php-5.2.17.tar.gz ]; then
echo "php-5.2.17.tar.gz [found]"
else
echo "Error: php-5.2.17.tar.gz not found!!!download now......"
wget -c http://soft.vpser.net/web/php/php-5.2.17.tar.gz
fi
printf "=========================== install Apache ======================\n"
#停止当前的其他服务
echo "Stoping Nginx..."
/etc/init.d/nginx stop
echo "Stoping MySQL..."
/etc/init.d/mysql stop
echo "Stoping PHP-FPM..."
/etc/init.d/php-fpm stop
if [ -s /etc/init.d/memceached ]; then
echo "Stoping Memcached..."
/etc/init.d/memcacehd stop
fi
#备份
echo "Backup old php configure files....."
mkdir /root/lnmpbackup/
cp /root/lnmp /root/lnmpbackup/
cp /usr/local/php/etc/php.ini /root/lnmpbackup/
cp /usr/local/php/etc/php-fpm.conf /root/lnmpbackup/
#开始编译安装
cd $cur_dir
rm -rf httpd-2.2.22/
tar zxvf httpd-2.2.22.tar.gz
cd httpd-2.2.22/
./configure --prefix=/usr/local/apache --enable-headers --enable-mime-magic --enable-proxy --enable-so --enable-rewrite --enable-ssl --enable-deflate --enable-suexec --disable-userdir --with-included-apr --with-mpm=prefork --with-ssl=/usr --disable-userdir --disable-cgid --disable-cgi --with-expat=builtin
make && make install
cd ..
mv /usr/local/apache/conf/httpd.conf /usr/local/apache/conf/httpd.conf.bak
#\cp 不走alias的cp
\cp $cur_dir/conf/httpd.conf /usr/local/apache/conf/httpd.conf
\cp $cur_dir/conf/httpd-default.conf /usr/local/apache/conf/extra/httpd-default.conf
\cp $cur_dir/conf/httpd-vhosts.conf /usr/local/apache/conf/extra/httpd-vhosts.conf
\cp $cur_dir/conf/httpd-mpm.conf /usr/local/apache/conf/extra/httpd-mpm.conf
\cp $cur_dir/conf/rpaf.conf /usr/local/apache/conf/extra/rpaf.conf
#sed实现内容替换
sed -i 's/#ServerName www.example.com:80/ServerName www.lnmp.org:88/g' /usr/local/apache/conf/httpd.conf
sed -i 's/ServerAdmin you@example.com/ServerAdmin '$ServerAdmin'/g' /usr/local/apache/conf/httpd.conf
#sed -i 's/www.lnmp.org/'$domain'/g' /usr/local/apache/conf/extra/httpd-vhosts.conf
sed -i 's/webmaster@example.com/'$ServerAdmin'/g' /usr/local/apache/conf/extra/httpd-vhosts.conf
mkdir -p /usr/local/apache/conf/vhost
#向/usr/local/apache/conf/httpd.conf中末尾追加内容Include conf/vhost/*.conf
cat >>/usr/local/apache/conf/httpd.conf<<EOF
Include conf/vhost/*.conf
EOF
#安装rpaf
tar -zxvf mod_rpaf-0.6.tar.gz
cd mod_rpaf-0.6/
/usr/local/apache/bin/apxs -i -c -n mod_rpaf-2.0.so mod_rpaf-2.0.c
cd ..
#创建软链
ln -s /usr/local/lib/libltdl.so.3 /usr/lib/libltdl.so.3
#sed -i 's#your_ips#'$ipv4'#g' /usr/local/apache/conf/extra/rpaf.conf
echo "Stop php-fpm....."
rm -rf /usr/local/php/
cd $cur_dir
if [ -s php-5.2.17 ]; then
rm -rf php-5.2.17
fi
tar zxvf php-5.2.17.tar.gz
cd php-5.2.17/
wget -c http://soft.vpser.net/web/php/bug/php-5.2.17-max-input-vars.patch
#打一个补丁这里需要了解diff和patch
patch -p1 < php-5.2.17-max-input-vars.patch
./configure --prefix=/usr/local/php --with-config-file-path=/usr/local/php/etc --with-apxs2=/usr/local/apache/bin/apxs --with-mysql=/usr/local/mysql --with-mysqli=/usr/local/mysql/bin/mysql_config --with-iconv-dir --with-freetype-dir --with-jpeg-dir --with-png-dir --with-zlib --with-libxml-dir=/usr --enable-xml --disable-rpath --enable-discard-path --enable-magic-quotes --enable-safe-mode --enable-bcmath --enable-shmop --enable-sysvsem --enable-inline-optimization --with-curl --with-curlwrappers --enable-mbregex --enable-mbstring --with-mcrypt --enable-ftp --with-gd --enable-gd-native-ttf --with-openssl --with-mhash --enable-pcntl --enable-sockets --with-xmlrpc --enable-zip --enable-soap --without-pear --with-gettext --with-mime-magic
if cat /etc/issue | grep -Eqi '(Debian|Ubuntu)';then
cd ext/openssl/
wget -c http://soft.vpser.net/lnmp/ext/debian_patches_disable_SSLv2_for_openssl_1_0_0.patch
patch -p3 <debian_patches_disable_SSLv2_for_openssl_1_0_0.patch
cd ../../
fi
rm -rf libtool
cp /usr/local/apache/build/libtool .
make ZEND_EXTRA_LIBS='-liconv'
make install
mkdir -p /usr/local/php/etc
cp php.ini-dist /usr/local/php/etc/php.ini
cd ../
#安装PDO扩展
cd $cur_dir/php-5.2.17/ext/pdo_mysql/
/usr/local/php/bin/phpize
./configure --with-php-config=/usr/local/php/bin/php-config --with-pdo-mysql=/usr/local/mysql
make && make install
cd $cur_dir/
# 添加 php extensions
sed -i 's#extension_dir = "./"#extension_dir = "/usr/local/php/lib/php/extensions/no-debug-non-zts-20060613/"\nextension = "memcache.so"\nextension = "pdo_mysql.so"\n#' /usr/local/php/etc/php.ini
sed -i 's#output_buffering = Off#output_buffering = On#' /usr/local/php/etc/php.ini
sed -i 's/post_max_size = 8M/post_max_size = 50M/g' /usr/local/php/etc/php.ini
sed -i 's/upload_max_filesize = 2M/upload_max_filesize = 50M/g' /usr/local/php/etc/php.ini
sed -i 's/;date.timezone =/date.timezone = PRC/g' /usr/local/php/etc/php.ini
sed -i 's/short_open_tag = Off/short_open_tag = On/g' /usr/local/php/etc/php.ini
sed -i 's/; cgi.fix_pathinfo=1/cgi.fix_pathinfo=0/g' /usr/local/php/etc/php.ini
sed -i 's/max_execution_time = 30/max_execution_time = 300/g' /usr/local/php/etc/php.ini
sed -i 's/disable_functions =.*/disable_functions = passthru,exec,system,chroot,scandir,chgrp,chown,shell_exec,proc_open,proc_get_status,ini_alter,ini_alter,ini_restore,dl,pfsockopen,openlog,syslog,readlink,symlink,popepassthru,stream_socket_server,fsocket,fsockopen/g' /usr/local/php/etc/php.ini
#根据系统安装ZendOptimizer
if [ `getconf WORD_BIT` = '32' ] && [ `getconf LONG_BIT` = '64' ] ; then
wget -c http://soft.vpser.net/web/zend/ZendOptimizer-3.3.9-linux-glibc23-x86_64.tar.gz
tar zxvf ZendOptimizer-3.3.9-linux-glibc23-x86_64.tar.gz
mkdir -p /usr/local/zend/
cp ZendOptimizer-3.3.9-linux-glibc23-x86_64/data/5_2_x_comp/ZendOptimizer.so /usr/local/zend/
else
wget -c http://soft.vpser.net/web/zend/ZendOptimizer-3.3.9-linux-glibc23-i386.tar.gz
tar zxvf ZendOptimizer-3.3.9-linux-glibc23-i386.tar.gz
mkdir -p /usr/local/zend/
cp ZendOptimizer-3.3.9-linux-glibc23-i386/data/5_2_x_comp/ZendOptimizer.so /usr/local/zend/
fi
#给php.ini追加内容
cat >>/usr/local/php/etc/php.ini<<EOF
;eaccelerator
;ionCube
[Zend Optimizer]
zend_optimizer.optimization_level=1
zend_extension="/usr/local/zend/ZendOptimizer.so"
EOF
cd $cur_dir
cp conf/proxy.conf /usr/local/nginx/conf/proxy.conf
mv /usr/local/nginx/conf/nginx.conf /root/lnmpbackup/
cp conf/nginx_a.conf /usr/local/nginx/conf/nginx.conf
#添加apache自动启动脚本
echo "Download new Apache init.d file......"
wget -c http://soft.vpser.net/lnmp/ext/init.d.httpd
cp init.d.httpd /etc/init.d/httpd
chmod +x /etc/init.d/httpd
echo "Test Nginx configure files..."
/usr/local/nginx/bin/nginx -t
echo "ReStarting Nginx......"
/etc/init.d/nginx restart
echo "Starting Apache....."
/etc/init.d/httpd restart
#更新系统启动项
echo "Remove old startup files and Add new startup file....."
if cat /etc/issue | grep -Eqi '(Debian|Ubuntu)';then
update-rc.d -f httpd defaults
update-rc.d -f php-fpm remove
else
sed -i '/php-fpm/'d /etc/rc.local
chkconfig --level 345 php-fpm off
chkconfig --level 345 httpd on
fi
cd $cur_dir
rm -f /etc/init.d/php-fpm
mv /root/vhost.sh /root/lnmp.vhost.sh
cp vhost_lnmpa.sh /root/vhost.sh
chmod +x /root/vhost.sh
cp lnmpa /root/
chmod +x /root/lnmpa
printf "====================== Upgrade to LNMPA completed =====================\n"
printf "You have successfully upgrade from lnmp to lnmpa,enjoy it!\n"
printf "=======================================================================\n"
printf "LNMP is a tool to auto-compile & install Nginx+MySQL+PHP on Linux \n"
printf "This script is a tool to upgrade from lnmp to lnmpa \n"
printf "\n"
printf "For more information please visit http://www.lnmp.org \n"
printf "=======================================================================\n"总的来说,我对ruby还比较陌生,我正在为我正在创建的对象编写一些rspec测试用例。许多测试用例都非常基础,我只是想确保正确填充和返回值。我想知道是否有办法使用循环结构来执行此操作。不必为我要测试的每个方法都设置一个assertEquals。例如:describeitem,"TestingtheItem"doit"willhaveanullvaluetostart"doitem=Item.new#HereIcoulddotheitem.name.shouldbe_nil#thenIcoulddoitem.category.shouldbe_nilendend但我想要一些方法来使用
我试图在一个项目中使用rake,如果我把所有东西都放到Rakefile中,它会很大并且很难读取/找到东西,所以我试着将每个命名空间放在lib/rake中它自己的文件中,我添加了这个到我的rake文件的顶部:Dir['#{File.dirname(__FILE__)}/lib/rake/*.rake'].map{|f|requiref}它加载文件没问题,但没有任务。我现在只有一个.rake文件作为测试,名为“servers.rake”,它看起来像这样:namespace:serverdotask:testdoputs"test"endend所以当我运行rakeserver:testid时
作为我的Rails应用程序的一部分,我编写了一个小导入程序,它从我们的LDAP系统中吸取数据并将其塞入一个用户表中。不幸的是,与LDAP相关的代码在遍历我们的32K用户时泄漏了大量内存,我一直无法弄清楚如何解决这个问题。这个问题似乎在某种程度上与LDAP库有关,因为当我删除对LDAP内容的调用时,内存使用情况会很好地稳定下来。此外,不断增加的对象是Net::BER::BerIdentifiedString和Net::BER::BerIdentifiedArray,它们都是LDAP库的一部分。当我运行导入时,内存使用量最终达到超过1GB的峰值。如果问题存在,我需要找到一些方法来更正我的代
Rails2.3可以选择随时使用RouteSet#add_configuration_file添加更多路由。是否可以在Rails3项目中做同样的事情? 最佳答案 在config/application.rb中:config.paths.config.routes在Rails3.2(也可能是Rails3.1)中,使用:config.paths["config/routes"] 关于ruby-on-rails-Rails3中的多个路由文件,我们在StackOverflow上找到一个类似的问题
我想为Heroku构建一个Rails3应用程序。他们使用Postgres作为他们的数据库,所以我通过MacPorts安装了postgres9.0。现在我需要一个postgresgem并且共识是出于性能原因你想要pggem。但是我对我得到的错误感到非常困惑当我尝试在rvm下通过geminstall安装pg时。我已经非常明确地指定了所有postgres目录的位置可以找到但仍然无法完成安装:$envARCHFLAGS='-archx86_64'geminstallpg--\--with-pg-config=/opt/local/var/db/postgresql90/defaultdb/po
我正在寻找执行以下操作的正确语法(在Perl、Shell或Ruby中):#variabletoaccessthedatalinesappendedasafileEND_OF_SCRIPT_MARKERrawdatastartshereanditcontinues. 最佳答案 Perl用__DATA__做这个:#!/usr/bin/perlusestrict;usewarnings;while(){print;}__DATA__Texttoprintgoeshere 关于ruby-如何将脚
我需要从一个View访问多个模型。以前,我的links_controller仅用于提供以不同方式排序的链接资源。现在我想包括一个部分(我假设)显示按分数排序的顶级用户(@users=User.all.sort_by(&:score))我知道我可以将此代码插入每个链接操作并从View访问它,但这似乎不是“ruby方式”,我将需要在不久的将来访问更多模型。这可能会变得很脏,是否有针对这种情况的任何技术?注意事项:我认为我的应用程序正朝着单一格式和动态页面内容的方向发展,本质上是一个典型的网络应用程序。我知道before_filter但考虑到我希望应用程序进入的方向,这似乎很麻烦。最终从任何
我打算为ruby脚本创建一个安装程序,但我希望能够确保机器安装了RVM。有没有一种方法可以完全离线安装RVM并且不引人注目(通过不引人注目,就像创建一个可以做所有事情的脚本而不是要求用户向他们的bash_profile或bashrc添加一些东西)我不是要脚本本身,只是一个关于如何走这条路的快速指针(如果可能的话)。我们还研究了这个很有帮助的问题:RVM-isthereawayforsimpleofflineinstall?但有点误导,因为答案只向我们展示了如何离线在RVM中安装ruby。我们需要能够离线安装RVM本身,并查看脚本https://raw.github.com/wayn
我在我的项目中添加了一个系统来重置用户密码并通过电子邮件将密码发送给他,以防他忘记密码。昨天它运行良好(当我实现它时)。当我今天尝试启动服务器时,出现以下错误。=>BootingWEBrick=>Rails3.2.1applicationstartingindevelopmentonhttp://0.0.0.0:3000=>Callwith-dtodetach=>Ctrl-CtoshutdownserverExiting/Users/vinayshenoy/.rvm/gems/ruby-1.9.3-p0/gems/actionmailer-3.2.1/lib/action_mailer
我有一个奇怪的问题:我在rvm上安装了rubyonrails。一切正常,我可以创建项目。但是在我输入“railsnew”时重新启动后,我有“程序'rails'当前未安装。”。SystemUbuntu12.04ruby-v"1.9.3p194"gemlistactionmailer(3.2.5)actionpack(3.2.5)activemodel(3.2.5)activerecord(3.2.5)activeresource(3.2.5)activesupport(3.2.5)arel(3.0.2)builder(3.0.0)bundler(1.1.4)coffee-rails(