草庐IT

LNMP一键自动安装脚本

1594cqb 2023-03-28 原文
 此脚本以在任何一台有网络的服务器上自动配置LNMP

使用方法:将inst_lnmp代码保存一个文件,例如inst_lnmp.sh 上传到服务器上执行。

此脚本在CentOS 6.0  X864环境下通过。

参考文章 http://os.51cto.com/art/201110/295713.htm

 

  1. #!/bin/bash  
  2. #set -x  
  3. #date: 2013-01-06  
  4. #Description: 一键安装LNMP环境  
  5. #Version: 0.1  
  6. #Author: Wolf  
  7. #定义命令搜索路径 
  8. PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin  
  9. export PATH  
  10.   
  11. src_dir=/usr/src  
  12. nginx_dir=/usr/local/nginx  
  13. mysql_dir=/usr/local/mysql  
  14. php_dir=/usr/local/php  
  15. libmcrypt_dir=/usr/local/libmcypt  
  16. #关闭SELiunx 
  17. echo "Disabled SELinux"  
  18. if [ -s /etc/selinux/config ]  
  19. then  
  20. sed -i 's/SELINUX=enforcing/SELINUX=disabled/g' /etc/selinux/config  
  21. fi  
  22. /usr/sbin/setenforce 0  
  23. Check if user is root  
  24. if [ "$UID" -ne 0 ]  
  25. then  
  26.     printf "Error: You must be root to run this script!\n"  
  27.     exit 1  
  28. fi  
  29.   
  30.     useradd -s /sbin/nologin mysql  
  31.   
  32. #检查需要的软件包是否存在,如果没有就下载。 
  33. download_src(){  
  34. cd $src_dir  
  35. if [ -s libiconv-1.13.1.tar.gz ] 
  36. then 
  37.     echo "libiconv-1.13.1.tar.gz found" 
  38. else 
  39.     echo "libiconv-1.13.1.tar.gz not found. download new...." 
  40.     wget http://mozbuildtools.googlecode.com/files/libiconv-1.13.1.tar.gz 
  41. fi 
  42. if [ -s mhash-0.9.9.9.tar.gz ] 
  43. then 
  44.     echo "mhash-0.9.9.9.tar.gz found" 
  45. else 
  46.     echo "mhash-0.9.9.9.tar.gz not found. download new....." 
  47.     wget http://acelnmp.googlecode.com/files/mhash-0.9.9.9.tar.gz 
  48. fi 
  49. if [ -s mysql-5.5.25a.tar.gz ]  
  50. then  
  51.     echo "mysql-5.5.25a.tar.gz found"  
  52. else  
  53.     echo "mysql-5.5.25a.tar.gz not found. download new....."      
  54.     wget http://mysql.ntu.edu.tw/Downloads/MySQL-5.5/mysql-5.5.25a.tar.gz   
  55. fi  
  56. if [ -s php-5.3.13.tar.gz ]  
  57. then  
  58.     echo "php-5.3.13.tar.gz found"  
  59. else  
  60.     echo "php-5.3.13.tar.gz not found. download new....."  
  61.     wget http://cn2.php.net/distributions/php-5.3.13.tar.gz   
  62. fi  
  63. if [ -s google-perftools-1.6.tar.gz ] 
  64. then 
  65.     echo "google-perftools-1.6.tar.gz found" 
  66. else 
  67.     echo "google-perftools-1.6.tar.gz not found. download new....." 
  68.     wget http://gperftools.googlecode.com/files/google-perftools-1.6.tar.gz 
  69. fi 
  70. if [ -s cmake-2.8.4.tar.gz ]  
  71. then  
  72.     echo "cmake-2.8.4.tar.gz found......"  
  73. else  
  74.     echo "cmake-2.8.4.tar.gz not found. download new....."  
  75.     wget http://www.cmake.org/files/v2.8/cmake-2.8.4.tar.gz  
  76. fi  
  77. if [ -s nginx-1.3.10.tar.gz ]  
  78. then  
  79.     echo "nginx-1.3.10.tar.gz found."  
  80. else  
  81.     echo "nginx-1.3.10.tar.gz not found. download new...."  
  82.     wget http://www.nginx.org/download/nginx-1.3.10.tar.gz  
  83. fi  
  84. if [ -s libmcrypt-2.5.7.tar.gz ]  
  85. then  
  86.     echo "libmcrypt-2.5.7.tar.gz found"  
  87. else  
  88.     echo "libmcrypt-2.5.7.tar.gz not found. download new..."  
  89.     wget http://nchc.dl.sourceforge.net/project/mcrypt/Libmcrypt/Production/libmcrypt-2.5.7.tar.gz  
  90. fi  
  91. if [ -s memcache-2.2.5.tgz ]  
  92. then  
  93.     echo "memcache-2.2.5.tgz found"  
  94. else  
  95.     echo "memcache-2.2.5.tgz not found. download new......"  
  96.     wget http://vps.googlecode.com/files/memcache-2.2.5.tgz  
  97. fi  
  98. if [ -s eaccelerator-0.9.5.3.tar.bz2 ]  
  99. then  
  100.     echo "eaccelerator-0.9.5.3.tar.bz2 found"  
  101. else  
  102.     echo "eaccelerator-0.9.5.3.tar.bz2 not found. download new.."  
  103.     wget http://autosetup1.googlecode.com/files/eaccelerator-0.9.5.3.tar.bz2  
  104. fi  
  105. if [ -s ImageMagick.tar.gz ]  
  106. then  
  107.     echo "ImageMagick.tar.gz found"  
  108. else  
  109.     echo "ImageMagick.tar.gz not found. download nrw."  
  110.     wget http://www.p_w_picpathmagick.org/download/ImageMagick.tar.gz  
  111. fi  
  112. if [ -s imagick-2.3.0.tgz ]  
  113. then  
  114.     echo "imagick-2.3.0.tgz found"  
  115. else  
  116.     echo  "imagick-2.3.0.tgz not found. download new"  
  117.     wget http://lnmpp.googlecode.com/files/imagick-2.3.0.tgz  
  118. fi  
  119. }  
  120. #初始化服务器 
  121. init_server(){  
  122. for src in dialog ntp vim-enhanced vixie-cron gcc gcc-c++ gcc-g77 flex bison autoconf automake glibc glibc-devel glib2 glib2-devel bzip2 bzip2-devel ncurses ncurses-devel libtool* zlib-devel libxml2-devel libjpeg-devel libpng-devel libtiff-devel fontconfig-devel freetype-devel libXpm-devel gettext-devel curl curl-devel pam-devel e2fsprogs-devel krb5-devel libidn libidn-devel openssl openssl-devel openldap openldap-devel net-snmp net-snmp-devel nss_ldap openldap-clients openldap-servers libtidy libtidy-devel wget libc-client libc-client-devel pcre pcre-devel  
  123. do  
  124.     yum -y install $src  
  125. done  
  126. ln -s /usr/lib64/libc-client.so* /usr/lib/  
  127. ln -s /usr/lib64/libldap* /usr/lib  
  128. }  
  129.  
  130.   
  131. #先检测mysql是否已经安装,如果已经安装了就不再安装,如果没安装就安装mysql 
  132. inst_mysql(){  
  133.    
  134.     tar zxvf cmake-2.8.4.tar.gz  
  135.     cd $src_dir/cmake-2.8.4  
  136.     ./configure && make && make install   
  137. if ( -d $mysql_dir )  
  138. then  
  139.     echo "MySQL is installed"  
  140. else  
  141.     echo "MySQL not install. install run..."  
  142.     cd $src_dir  
  143.     tar zxvf mysql-5.5.25a.tar.gz  
  144.     cd mysql-5.5.25a  
  145.     cmake . -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DMYSQL_DATADIR=/usr/local/mysql/data -DSYSCONFDIR=/etc -DWITH_INNOBASE_STORAGE_ENGINE=1 -DWITH_ARCHIVE_STORAGE_ENGINE=1 -DWITH_BLACKHOLE_STORAGE_ENGINE=1 -DWITH_FEDERATED_STORAGE_ENGINE=1 -DWITH_PARTITION_STORAGE_ENGINE=1 -DMYSQL_TCP_PORT=3306 -DENABLED_LOCAL_INFILE=1 -DWITH_SSL=yes  -DEXTRA_CHARSETS=all -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DWITH_READLINE=on  
  146.     gmake && make install  
  147. fi  
  148. if ( -f /ect/my.cnf )  
  149. then  
  150.     echo "MySQL config file my.cnf found. backup my.cnf to my.cnf.bak"  
  151.     mv /etc/my.cnf /etc/my.cnf.bak  
  152.     /bin/cp support-files/my-small.cnf /etc/my.cnf  
  153.     /bin/cp support-files/mysql.server /etc/rc.d/init.d/mysqld  
  154.     chmod 755 /etc/rc.d/init.d/mysqld  
  155. fi  
  156. /usr/local/mysql/scripts/mysql_install_db --basedir=/usr/local/mysql/ --datadir=/usr/local/mysql/data/ --user=root --defaults-file=/etc/my.cnf  
  157. }  
  158.   
  159. inst_libmcypt(){  
  160. if ( -d $libmcrypt_dir )  
  161. then  
  162.         echo "libmcrypt is installed."  
  163. else  
  164.         cd $src_dir  
  165.         tar zxvf libmcrypt-2.5.7.tar.gz  
  166.         cd libmcrypt-2.5.7  
  167.         ./configure --prefix=/usr/local/libmcypt && make && make install  
  168.     /sbin/ldconfig 
  169.     cd libltdl/ 
  170.     ./configure --enable-ltdl-install 
  171.     make 
  172.     make install 
  173. fi  
  174. cd $src_dir 
  175. tar zxf mhash-0.9.9.9.tar.gz 
  176. cd mhash-0.9.9.9/ 
  177. ./configure 
  178. make 
  179. make install 
  180. ln -s /usr/local/lib/libmhash.a /usr/lib/libmhash.a 
  181. ln -s /usr/local/lib/libmhash.la /usr/lib/libmhash.la 
  182. ln -s /usr/local/lib/libmhash.so /usr/lib/libmhash.so 
  183. ln -s /usr/local/lib/libmhash.so.2 /usr/lib/libmhash.so.2 
  184. ln -s /usr/local/lib/libmhash.so.2.0.1 /usr/lib/libmhash.so.2.0.1 
  185. }  
  186. #先检测PHP是否已经编译安装,如果安装了就不再进行安装,如果没安装就安装PHP 
  187. inst_php(){  
  188. cd $src_dir 
  189. tar zxf libiconv-1.13.1.tar.gz 
  190. cd libiconv-1.13.1/ 
  191. ./configure --prefix=/usr/local 
  192. make 
  193. make install 
  194. cd $src_dir  
  195. if ( -d $php_dir)  
  196. then  
  197.     echo "PHP is installed"  
  198. else  
  199.     echo "PHP not install. install run...."  
  200.     cd $src_dir  
  201.     tar zxvf php-5.3.13.tar.gz  
  202.     cd php-5.3.13  
  203.     ./configure --prefix=/usr/local/php --with-config-file-path=/usr/local/php/lib --with-mysql=/usr/local/mysql/bin/mysql_config --with-enable-sysvsem --enable-fpm --with-openssl --with-zlib --with-bz2 --with-curl --with-libxml-dir=/usr --with-gd --with-jpeg-dir --with-png-dir --with-zlib-dir --enable-gd-native-ttf --enable-gd-jis-conv --without-iconv --with-ldap --with-mcrypt=/usr/local/libmcypt --with-zlib-dir --with-snmp --enable-zip --with-curlwrappers --with-imap --with-kerberos --with-imap-ssl --with-freetype-dir --with-mysql=/usr/local/mysql  
  204.     make && make install  
  205.     cp php.ini-development /usr/local/php/lib/php.ini  
  206.     cp /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf  
  207. fi  
  208. }  
  209. #安装PHP扩展  
  210. inst_php_ex(){  
  211. cd $src_dir  
  212. tar zxf memcache-2.2.5.tgz  
  213. cd memcache-2.2.5/  
  214. ${php_dir}/bin/phpize  
  215. ./configure --with-php-config=${php_dir}/bin/php-config  
  216. make  
  217. make install  
  218. cd ../  
  219.   
  220. tar jxf eaccelerator-0.9.5.3.tar.bz2  
  221. cd eaccelerator-0.9.5.3  
  222. ${php_dir}/bin/phpize  
  223. ./configure --enable-eaccelerator=shared --with-eaccelerator-shared-memory --with-php-config=${php_dir}/bin/php-config  
  224. make  
  225. make install  
  226. cd $src_dir  
  227.   
  228. tar zxf ImageMagick.tar.gz  
  229. cd ImageMagick-6.8.1-9/  
  230. ./configure  
  231. make  
  232. make install  
  233. cd ../  
  234. tar zxf imagick-2.3.0.tgz  
  235. cd imagick-2.3.0/  
  236. ${php_dir}/bin/phpize  
  237. ./configure --with-php-config=${php_dir}/bin/php-config  
  238. make  
  239. make install  
  240. cd ..  
  241. echo "php extension installed successfully!"  
  242. }  
  243. #安装nginx  
  244. inst_nginx(){  
  245. cd $src_dir 
  246. tar zxf google-perftools-1.6.tar.gz 
  247. cd google-perftools* 
  248. ./configure 
  249. make 
  250. make install 
  251. cd $src_dir 
  252.  
  253. if ( -d $nginx_dir )  
  254. then  
  255.     echo "Nginx is installed"  
  256. else  
  257.     cd $src_dir  
  258.     tar zxvf nginx-1.3.10.tar.gz  
  259.     cd nginx-1.3.10  
  260.     ./configure --prefix=/usr/local/nginx --with-http_ssl_module --with-http_stub_status_module --with-http_gzip_static_module --with-http_stub_status_module  
  261.     make && make install      
  262. fi  
  263. }  
  264. #生成一个PHP启动脚本,可以用service phpd start | restart | stop | show 进行启动、重启、关闭、查看运行状态 
  265. phpd(){ 
  266. cat <<EOF >>phpd 
  267. #!/bin/bash   
  268. #Author: wolf 
  269. #Date: 2013-01-03 
  270. #   
  271. #chkconfig: - 85 15   
  272. #processname: php  
  273. php=/usr/local/php/sbin/php-fpm   
  274. conf=/usr/local/php/etc/php-fpm.conf   
  275. case $1 in   
  276.        start)   
  277.               echo -n "Starting php"   
  278.               $php   
  279.               echo " done"   
  280.        ;;   
  281.       stop)   
  282.               echo -n "Stopping php"   
  283.               killall -9 php-fpm   
  284.               echo " done"   
  285.        ;;   
  286.         restart)   
  287.                 $0 stop   
  288.                 $0 start   
  289.        ;;   
  290.        show)   
  291.               ps -aux|grep php   
  292.        ;;   
  293.        *)   
  294.               echo -n "Usage: $0 {start|restart|reload|stop|test|show}"   
  295.        ;;   
  296. esac 
  297. EOF 
  298. if [ -f phpd ] 
  299. then 
  300.     /bin/cp phpd /etc/rc.d/init.d/phpd 
  301.     chmod +x /etc/rc.d/init.d/phpd 
  302. fi 
  303. #生成nginx启动脚本,可以用service nginxd start | restart | stop | reload | test | show 进行重启、关闭、启动>、测试配置文件、查看状态和重新加载。 
  304. nginxd(){ 
  305. cat <<EOF >>nginxd 
  306. #!/bin/bash   
  307. #Author: wolf 
  308. #Date: 2013-01-03 
  309. #   
  310. #chkconfig: - 85 15   
  311. #description: Nginx is a World Wide Web server.   
  312. #processname: nginx   
  313. nginx=/usr/local/nginx/sbin/nginx   
  314. conf=/usr/local/nginx/conf/nginx.conf    
  315. case $1 in   
  316.        start)   
  317.               echo -n "Starting Nginx"   
  318.               $nginx -c $conf   
  319.               echo " done"   
  320.        ;;   
  321.       stop)   
  322.               echo -n "Stopping Nginx"   
  323.               killall -9 nginx   
  324.               echo " done"   
  325.        ;;   
  326.        test)   
  327.               $nginx -t -c $conf   
  328.        ;;   
  329.         reload)   
  330.               echo -n "Reloading Nginx"   
  331.               ps auxww | grep nginx | grep master | awk '{print $2}' | xargs kill -HUP   
  332.               echo " done"   
  333.        ;;   
  334.         restart)   
  335.                 $0 stop   
  336.                 $0 start   
  337.        ;;   
  338.        show)   
  339.               ps -aux|grep nginx   
  340.        ;;   
  341.        *)   
  342.               echo -n "Usage: $0 {start|restart|reload|stop|test|show}"   
  343.        ;;   
  344. esac 
  345. EOF 
  346. if [ -s nginxd ] 
  347. then 
  348.     /bin/cp nginxd /etc/rc.d/init.d/nginxd 
  349.     chmod +x /etc/rc.d/init.d/nginxd 
  350. fi 
  351. cat <<EOF 
  352. ############################################ 
  353.   1 install Nginx 
  354.   2 install PHP 
  355.   3 install MySQL 
  356.   4 install LNMP 
  357. ############################################ 
  358. ############################################ 
  359. 请选择你要安装的服务(1 | 2 | 3 | 4) 
  360. EOF 
  361.  
  362. echo "请输入一个数字: " 
  363. read num 
  364. case $num in   
  365.    1)  
  366.     echo "Nginx installing........... have a rest"  
  367.     init_server  
  368.     download_src  
  369.     inst_nginx  
  370.     ;;  
  371.    2)  
  372.     echo "PHP installing....... have a rest"  
  373.     download_src  
  374.     init_server  
  375.     inst_mysql  
  376.     inst_libmcypt  
  377.     inst_php  
  378.     inst_php_ex  
  379.     ;;  
  380.     3)  
  381.     echo "MySQL installing...... have a rest"  
  382.     init_server   
  383.     download_src  
  384.     inst_mysql  
  385.      ;;  
  386.     4)  
  387.     echo "LNMP installing......  have a rest"  
  388.     download_src  
  389.    init_server  
  390.    inst_mysql  
  391.    inst_libmcypt  
  392.    inst_php  
  393. inst_php_ex 
  394.    inst_nginx   
  395.     ;;  
  396. *) 
  397. echo "输入错误\n"         echo "选择你要安装的服务(1 | 2 | 3 | 4)"          
  398. ;; 
  399. esac 
  400.   
  401. #检查安装是否成功 
  402. case $num in  
  403.    4)  
  404.     if [ -s /usr/local/nginx ] && [ -s /usr/local/php ] && [ -s /usr/local/mysql ]  
  405.     then  
  406.           echo "LNMP is install  completed"  
  407.           echo "Nginx basedir: /usr/local/nginx"  
  408.           echo "PHP basedir: /usr/local/php"  
  409.           echo "MySQL basedir: /usr/local/mysql"  
  410.           echo "MySQL datadir: /usr/local/mysql/data"  
  411.     else  
  412.          echo "LNMP is install fail"  
  413.     fi  
  414.    ;;  
  415.    3)  
  416.     if [ -s /usr/local/mysql ]  
  417.     then  
  418.         echo "Nginx is install completed"  
  419.         echo "MySQL basedir: /usr/local/mysql"  
  420.         echo "MySQL datadir: /usr/local/mysql/data"  
  421.     phpd 
  422.     nginxd 
  423.     else  
  424.         echo "Nginx is install fail"  
  425.     fi  
  426.     ;;  
  427.    2)  
  428.     if  [ -s /usr/local/php ]  
  429.     then  
  430.         echo "PHP is install completed"  
  431.         echo "PHP basedir: /usr/local/php"  
  432.     phpd 
  433.     else  
  434.         echo "PHP is install fail"  
  435.     fi  
  436.     ;;  
  437.     1)  
  438.     if [ -s /usr/local/nginx ]  
  439.     then  
  440.         echo "Nginx is install completed"  
  441.         echo "Nginx basedir: /usr/local/nginx "  
  442.     nginxd 
  443.     else  
  444.         echo "Nginx is install fail"  
  445.     fi  
  446.     ;;  
  447. esac 

有关LNMP一键自动安装脚本的更多相关文章

  1. ruby-on-rails - 使用 Ruby on Rails 进行自动化测试 - 最佳实践 - 2

    很好奇,就使用ruby​​onrails自动化单元测试而言,你们正在做什么?您是否创建了一个脚本来在cron中运行rake作业并将结果邮寄给您?git中的预提交Hook?只是手动调用?我完全理解测试,但想知道在错误发生之前捕获错误的最佳实践是什么。让我们理所当然地认为测试本身是完美无缺的,并且可以正常工作。下一步是什么以确保他们在正确的时间将可能有害的结果传达给您? 最佳答案 不确定您到底想听什么,但是有几个级别的自动代码库控制:在处理某项功能时,您可以使用类似autotest的内容获得关于哪些有效,哪些无效的即时反馈。要确保您的提

  2. ruby - 在 64 位 Snow Leopard 上使用 rvm、postgres 9.0、ruby 1.9.2-p136 安装 pg gem 时出现问题 - 2

    我想为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

  3. ruby - 如何将脚本文件的末尾读取为数据文件(Perl 或任何其他语言) - 2

    我正在寻找执行以下操作的正确语法(在Perl、Shell或Ruby中):#variabletoaccessthedatalinesappendedasafileEND_OF_SCRIPT_MARKERrawdatastartshereanditcontinues. 最佳答案 Perl用__DATA__做这个:#!/usr/bin/perlusestrict;usewarnings;while(){print;}__DATA__Texttoprintgoeshere 关于ruby-如何将脚

  4. ruby - 完全离线安装RVM - 2

    我打算为ruby​​脚本创建一个安装程序,但我希望能够确保机器安装了RVM。有没有一种方法可以完全离线安装RVM并且不引人注目(通过不引人注目,就像创建一个可以做所有事情的脚本而不是要求用户向他们的bash_profile或bashrc添加一些东西)我不是要脚本本身,只是一个关于如何走这条路的快速指针(如果可能的话)。我们还研究了这个很有帮助的问题:RVM-isthereawayforsimpleofflineinstall?但有点误导,因为答案只向我们展示了如何离线在RVM中安装ruby。我们需要能够离线安装RVM本身,并查看脚本https://raw.github.com/wayn

  5. ruby-on-rails - rails 目前在重启后没有安装 - 2

    我有一个奇怪的问题:我在rvm上安装了ruby​​onrails。一切正常,我可以创建项目。但是在我输入“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(

  6. ruby - 如何为 emacs 安装 ruby​​-mode - 2

    我刚刚为fedora安装了emacs。我想用emacs编写ruby。为ruby​​提供代码提示、代码完成类型功能所需的工具、扩展是什么? 最佳答案 ruby-mode已经包含在Emacs23之后的版本中。不过,它也可以通过ELPA获得。您可能感兴趣的其他一些事情是集成RVM、feature-mode(Cucumber)、rspec-mode、ruby-electric、inf-ruby、rinari(用于Rails)等。这是我当前用于Ruby开发的Emacs配置:https://github.com/citizen428/emacs

  7. ruby-on-rails - 无法在centos上安装therubyracer(V8和GCC出错) - 2

    我正在尝试在我的centos服务器上安装therubyracer,但遇到了麻烦。$geminstalltherubyracerBuildingnativeextensions.Thiscouldtakeawhile...ERROR:Errorinstallingtherubyracer:ERROR:Failedtobuildgemnativeextension./usr/local/rvm/rubies/ruby-1.9.3-p125/bin/rubyextconf.rbcheckingformain()in-lpthread...yescheckingforv8.h...no***e

  8. ruby-on-rails - 独立 ruby​​ 脚本的配置文件 - 2

    我有一个在Linux服务器上运行的ruby​​脚本。它不使用rails或任何东西。它基本上是一个命令行ruby​​脚本,可以像这样传递参数:./ruby_script.rbarg1arg2如何将参数抽象到配置文件(例如yaml文件或其他文件)中?您能否举例说明如何做到这一点?提前谢谢你。 最佳答案 首先,您可以运行一个写入YAML配置文件的独立脚本:require"yaml"File.write("path_to_yaml_file",[arg1,arg2].to_yaml)然后,在您的应用中阅读它:require"yaml"arg

  9. ruby - 通过 RVM (OSX Mountain Lion) 安装 Ruby 2.0.0-p247 时遇到问题 - 2

    我的最终目标是安装当前版本的RubyonRails。我在OSXMountainLion上运行。到目前为止,这是我的过程:已安装的RVM$\curl-Lhttps://get.rvm.io|bash-sstable检查已知(我假设已批准)安装$rvmlistknown我看到当前的稳定版本可用[ruby-]2.0.0[-p247]输入命令安装$rvminstall2.0.0-p247注意:我也试过这些安装命令$rvminstallruby-2.0.0-p247$rvminstallruby=2.0.0-p247我很快就无处可去了。结果:$rvminstall2.0.0-p247Search

  10. ruby - 如何在 Lion 上安装 Xcode 4.6,需要用 RVM 升级 ruby - 2

    我实际上是在尝试使用RVM在我的OSX10.7.5上更新ruby,并在输入以下命令后:rvminstallruby我得到了以下回复:Searchingforbinaryrubies,thismighttakesometime.Checkingrequirementsforosx.Installingrequirementsforosx.Updatingsystem.......Errorrunning'requirements_osx_brew_update_systemruby-2.0.0-p247',pleaseread/Users/username/.rvm/log/138121

随机推荐