仓酷云

 找回密码
 立即注册
搜索
热搜: 活动 交友 discuz
查看: 608|回复: 7
打印 上一主题 下一主题

[其他Linux] 来一发LAMP&LNMP主动化安装剧本代码

[复制链接]
若相依 该用户已被删除
跳转到指定楼层
楼主
发表于 2015-1-16 13:06:48 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有帐号?立即注册

x
虽然Linux桌面应用发展很快,但是命令在Linux中依然有很强的生命力。Linux是一个命令行组成的操作系统,精髓在命令行。
1、剧本的情况先容
2、剧本的先容
3、剧本的功效先容

1、剧本的情况先容
此剧本运转在RHEL6.4版本上
运转此剧本需注重:
1)、主机必要可以上彀,由于博主是搭建的搜狐的外网yum源,此yum源由两部分构成,一个是光盘内里的一切软件包,一个是epel源。
2)、需懂得软件之间的互相依附性。

2、剧本的先容
剧本是由函数构成,每个函数完成一个功效
.代码以下:

functioncreate_yum#此函数是搭建sohu的yum堆栈
functiondownload#此函数是下载全体所需的软件包
functioninstall_apache#此函数是安装apache软件包
functionconfig_apache#此函数是修正apache的服务剧本和开启
apache服务
functioninstall_nginx#此函数是安装nginx软件包
functioninstall_mysql#此函数是安装mysql软件包
functionconfig_mysql#此函数是初始化mysql和开启mysql的服务
functioninstall_php#此函数是安装php软件包
functionconfig_php#此函数供应php的设置文件
functioninstall_php_fpm#此函数是安装php-fpm软件包供应fastcgi服务
functionconfig_php_fpm#此函数是修正php-fpm的设置文件盒开启
php-fpm的服务
functioninstall_xcache#此函数是安装为php代码减速的软件包
functioninstall_memcache#此函数是安装毗连memcached的软件包
functioninstall_memcached#此函数是安装memcached软件包
functioninstall_lamp#此函数内里只包括了apache,mysql,php的函数
functionconfig_lamp
functioninstall_lammp#此函数内里只包括了apache,mysql,
memcached,php的函数
functionconfig_lammp
functioninstall_lnmp#此函数内里只包括了nginx,mysql,php的函数
functionconfig_lnmp
functioninstall_lnmmp#此函数内里只包括了nginx,mysql,
memcached,php的函数
functionconfig_lnmmp


假如列位博友以为设置文件的路径寄存数据的路径与列位博友所请求的了局纷歧样,那请列位博友只需小小的自行修正一下
3、剧本的功效先容
1)、撑持某台呆板独自安装某一个软件,如apache、nginx、mysql、php-fpm,memcached
2)、撑持某台呆板间接安装lamp、lnmp、lammp、lnmmp架构
3)、假如想一个一个的安装lamp(lnmp)架构,请注重安装按次:apache(nginx)-->
mysql-->php
4)、php与php-fpm实在都是安装php源码软件包,可是供应的功效纷歧样
假如你的apache与php安装在分歧的呆板上,那末php的那台主机安装的是
php-fpm;
假如你的php与mysql安装在分歧的呆板上,那末php的那台主机也是安装
php-fpm;
php-fpm与memcached安装在分歧的呆板上,那末php-fpm的那台主机必需安装memcache,用于毗连memcached。
5)、安装完每一个剧本后,会把源码包天生的文件与体系能辨认的头文件、库文件、二进制中
6)、会为服务供应systemV剧本文件
7)、会自行的把服务开启,并到场到开机主动启动的服务列表中

全部剧本
.代码以下:

#!/bin/bash
#discripte:frist,youlinuxservermustbesurfInternetbecauseweusehttp://mirrors.sohu.com/yumsourceandepelsource
functioncreate_yum{
dir=/etc/yum.repos.d/
mv$dir/*.repo/tmp
cat>>$dir/sohu.repo<<EOF
[centos]
name=sohu-centos
baseurl=http://mirrors.sohu.com/centos/$releasever/os/$basearch
gpgcheck=1
enable=0
gpgkey=http://mirrors.sohu.com/centos/RPM-GPG-KEY-CentOS-6
[epel]
name=sohu-epel
baseurl=http://mirrors.sohu.com/fedora-epel/$releasever/$basearch/
enable=1
gpgcheck=0
EOF
yumcleanall&>/dev/null
}
functiondownload{
yum-yinstallwget
cd/root
echo-e"33[32m=========downloadaboutwebserversourcepackage==========33[0m"
wgethttp://mirror.esocc.com/apache/apr/apr-1.4.6.tar.bz2
wgethttp://mirror.esocc.com/apache/apr/apr-util-1.5.2.tar.bz2
wgethttp://mirror.esocc.com/apache/httpd/httpd-2.4.6.tar.bz2
wgethttp://nginx.org/download/nginx-1.4.2.tar.gz
echo-e"33[32m=========downloadaboutphporphp-fpmsourepackage========33[0m"
wgethttp://xcache.lighttpd.net/pub/Releases/3.0.3/xcache-3.0.3.tar.bz2
wgethttp://pecl.php.net/get/memcache-2.2.7.tgz
wgethttp://downloads.php.net/stas/php-5.4.19.tar.bz2
echo-e"33[32m======downloadaboutmemcachedsourcepackage========33[0m"
wgethttp://nchc.dl.sourceforge.net/project/levent/libevent/libevent-2.0/libevent-2.0.21-stable.tar.gz
wgethttp://memcached.googlecode.com/files/memcached-1.4.15.tar.gz
echo-e"33[32m======downloadaboutmysqlsourcepackage=========33[0m"
wgethttp://mysql.llarian.net/Downloads/MySQL-5.5/mysql-5.5.33.tar.gz
}
functioninstall_apache{
cd/root
yum-yinstallpcre-devel
tarxfapr-1.4.6.tar.bz2
tarxfapr-util-1.5.2.tar.bz2
tarxfhttpd-2.4.6.tar.bz2
cd/root/apr-1.4.6
./configure--prefix=/usr/local/apr&&make&&makeinstall
echo-e"33[32m=========aprisok========33[0m"
cd/root/apr-util-1.5.2
./configure--prefix=/usr/local/apr-util--with-apr=/usr/local/apr&&make&&makeinstall
echo-e"33[32m=========apr-utilisok========33[0m"
cd/root/httpd-2.4.6
./configure--prefix=/usr/local/apache--enable-so--enable-ssl--enable-cgi--enable-rewrite--with-zlib
--with-pcre--with-apr=/usr/local/apr--with-apr-util=/usr/local/apr-util--enable-modules=most
--enable-mpms-shared=all--with-mpm=event&&make&&makeinstall
echo-e"33[32m=========httpdisok========33[0m"
}
functionconfig_apache{
echo-e"33[32mfrist,Associatedsystempath33[0m"
echo"PATH=/usr/local/apache/bin/:$PATH">/etc/profile.d/httpd.sh
source/etc/profile.d/httpd.sh
ln-sv/usr/local/apache/include//usr/include/httpd
echo-e"33[32msecond,ModifyconfigurationfilesandprovidedsystemVscripts33[0m"
IP=`ifconfig|grep"inetaddr"|grep-v"127.0.0.1"|awk-F:{print$2}|cut-d-f1`
cp/root/httpd-2.4.6/build/rpm/httpd.init/etc/rc.d/init.d/httpd
sed-i/httpd/s/usr/sbin/httpd/usr/local/apache/bin/httpd/g/etc/rc.d/init.d/httpd
sed-i/^httpd/aprog=httpd/etc/rc.d/init.d/httpd
sed-i/^pidfile/s/var/run/usr/local/apache/logs/g/etc/rc.d/init.d/httpd
sed-is/etc/httpd/conf/httpd.conf/usr/local/apache/conf/httpd.conf/g/etc/rc.d/init.d/httpd
sed-i$aServerName$IP:80/usr/local/apache/conf/httpd.conf
chkconfig--addhttpd
chkconfig--level35httpdon
servicehttpdstart
}
functioninstall_nginx{
cd/root
yum-yinstallpcre-devel
tarxfnginx-1.4.2.tar.gz
groupaddnginx
useradd-r-gnginxnginx
cd/root/nginx-1.4.2
./configure
--prefix=/usr
--sbin-path=/usr/sbin/nginx
--conf-path=/etc/nginx/nginx.conf
--error-log-path=/var/log/nginx/error.log
--http-log-path=/var/log/nginx/access.log
--pid-path=/var/run/nginx/nginx.pid
--lock-path=/var/lock/nginx.lock
--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=/var/tmp/nginx/client/
--http-proxy-temp-path=/var/tmp/nginx/proxy/
--http-fastcgi-temp-path=/var/tmp/nginx/fcgi/
--http-uwsgi-temp-path=/var/tmp/nginx/uwsgi
--http-scgi-temp-path=/var/tmp/nginx/scgi
--with-pcre&&make&&makeinstall
echo-e"33[32m=========nginxisok========33[0m"
}
functioninstall_mysql{
cd/root
yum-yinstallcmakebison
useradd-rmysql
tarxfmysql-5.5.33.tar.gz
cd/root/mysql-5.5.33
cmake.-DCMAKE_INSTALL_PREFIX=/usr/local/mysql-DMYSQL_DATADIR=/mydata/data-DSYSCONFDIR=/etc
-DWITH_INNOBASE_STORAGE_ENGINE=1-DWITH_ARCHIVE_STORAGE_ENGINE=1-DWITH_BLACKHOLE_STORAGE_ENGINE=1
-DWITH_READLINE=1-DWITH_SSL=system-DWITH_ZLIB=system-DWITH_LIBWRAP=0-DMYSQL_UNIX_ADDR=/tmp/mysql.sock
-DDEFAULT_CHARSET=utf8-DDEFAULT_COLLATION=utf8_general_ci
make&&makeinstall
echo-e"33[32m=========mysqldisok========33[0m"
}
functionconfig_mysql{
echo-e"33[32mfrist,Associatedsystempath,andInitializationdatabase33[0m"
cp/usr/local/mysql/support-files/my-large.cnf/etc/my.cnf
cp/usr/local/mysql/support-files/mysql.server/etc/rc.d/init.d/mysqld
chown-Rroot.mysql/usr/local/mysql/
mkdir-pv/mydata/data
chown-Rmysql:mysql/mydata/data/
sed-i/thread_concurrency/adatadir=/mydata/data/etc/my.cnf
sed-i/datadir/ainnodb_file_per_table=1/etc/my.cnf
/usr/local/mysql/scripts/mysql_install_db--user=mysql--datadir=/mydata/data/--basedir=/usr/local/mysql
servicemysqldstart
echo"PATH=/usr/local/mysql/bin:$PATH">/etc/profile.d/mysqld.sh
source/etc/profile.d/mysqld.sh
echo"/usr/local/mysql/lib">/etc/ld.so.conf.d/mysqld.conf
ldconfig-v|grepmysql
ln-sv/usr/local/mysql/include//usr/include/mysqld
chkconfig--addmysqld
chkconfig--level35mysqldon
}
functioninstall_php{
yum-yinstalllibxml2-develbzip2-develcurl-devellibmcrypt-develmhash-devel
tarxfphp-5.4.19.tar.bz2
cd/root/php-5.4.19
./configure--prefix=/usr/local/php--with-mysql=/usr/local/mysql--with-openssl--with-mysqli=/usr/local/mysql/bin/mysql_config
--enable-mbstring--with-freetype-dir--with-jpeg-dir--with-png-dir--with-zlib--with-libxml-dir=/usr
--enable-xml--enable-sockets--with-apxs2=/usr/local/apache/bin/apxs--with-mcrypt--with-curl
--with-config-file-path=/etc--with-config-file-scan-dir=/etc/php.d--with-bz2--enable-maintainer-zts
make&&makeinstall
echo-e"33[32m=========phpisok========33[0m"
}
functionconfig_php{
cp/root/php-5.4.19/php.ini-production/etc/php.ini
}
functioninstall_php_fpm{
yum-yinstalllibxml2-develbzip2-develcurl-devellibmcrypt-develmhash-devel
tarxfphp-5.4.19.tar.bz2
cd/root/php-5.4.19
./configure--prefix=/usr/local/php--with-mysql=mysqlnd--with-pdo-mysql=mysqlnd--with-mysqli=mysqlnd
--with-openssl--enable-sockets--enable-sysvshm--enable-mbstring--with-freetype-dir--with-jpeg-dir--with-png-dir
--with-zlib-dir--with-libxml-dir=/usr--enable-xml--with-mhash--with-mcrypt--with-config-file-path=/etc
--with-config-file-scan-dir=/etc/php.d--with-bz2--with-curl--enable-maintainer-zts--enable-fpm&&make&&makeinstall
echo-e"33[32m=========php-fpmisok========33[0m"
}
functionconfig_php_fpm{
echo-e"33[32mfrist,Associatedsystempath33[0m"
IP2=`ifconfig|grep"inetaddr"|grep-v"127.0.0.1"|awk-F:{print$2}|cut-d-f1`
cp/root/php-5.4.19/php.ini-production/etc/php.ini
echo"PATH=/usr/local/php/bin:/usr/local/php/sbin:$PATH">/etc/profile.d/php-fpm.sh
source/etc/profile.d/php-fpm.sh
echo-e"33[32msecond,ModifyconfigurationfilesandprovidedsystemVscripts33[0m"
mv/usr/local/php/etc/php-fpm.conf.default/usr/local/php/etc/php-fpm.conf
sed-is/127.0.0.1/$IP2/g/usr/local/php/etc/php-fpm.conf
cp/root/php-5.4.19/sapi/fpm/init.d.php-fpm/etc/rc.d/init.d/php-fpm
chmod+x/etc/rc.d/init.d/php-fpm
servicephp-fpmstart
chkconfig--addphp-fpm
chkconfig--level35php-fpmon
}
functioninstall_xcache{
cd/root
tarxfxcache-3.0.3.tar.bz2
if[-d/usr/local/php];then
cd/root/xcache-3.0.3
/usr/local/php/bin/phpize
./configure--enable-xcache--with-php-config=/usr/local/php/bin/php-config
make&&makeinstall
else
install_php_fpm
cd/root/xcache-3.0.3
/usr/local/php/bin/phpize
./configure--enable-xcache--with-php-config=/usr/local/php/bin/php-config
make&&makeinstall
echo-e"33[32m=========xcacheisok========33[0m"
fi
}
functioninstall_memcache{
cd/root
tarxfmemcache-2.2.7.tgz
if[-d/usr/local/php];then
cd/root/memcache-2.2.7
/usr/local/php/bin/phpize
./configure--with-php-config=/usr/local/php/bin/php-config--enable-memcache&&make&&makeinstall
else
install_php_fpm
cd/root/memcache-2.2.7
/usr/local/php/bin/phpize
./configure--with-php-config=/usr/local/php/bin/php-config--enable-memcache&&make&&makeinstall
echo-e"33[32m=========memcacheisok========33[0m"
fi
}
functioninstall_memcached{
cd/root
tarxflibevent-2.0.21-stable.tar.gz
tarxfmemcached-1.4.15.tar.gz
cd/root/libevent-2.0.21-stable
./configure--prefix=/usr/local/libevent&&make&&makeinstall
echo-e"33[32m=========libeventisok========33[0m"
cd/usr/local/libevent/
echo"/usr/local/libevent/lib">/etc/ld.so.conf.d/libevent.conf
ldconfig-v|greplibevent
ln-sv/usr/local/libevent//usr/include/libevent
cd/root/memcached-1.4.15
./configure--prefix=/usr/local/memcached--with-libevent=/usr/local/libevent/
make&&makeinstall
echo-e"33[32m=========memcachedisok========33[0m"
}
functioninstall_lamp{
install_apache
install_mysql
install_php
install_xcache
}
functionconfig_lamp{
config_apache
config_mysql
config_php
}
functioninstall_lnmp{
install_nginx
install_mysql
install_php
install_xcache
}
functionconfig_lnmp{
config_mysql
config_php
}
functioninstall_lammp{
install_apache
install_mysql
install_php
install_xcache
install_memcache
install_memcached
}
functionconfig_lammp{
config_apache
config_mysql
config_php
config_php_fpm
}
functioninstall_lnmmp{
install_nginx
install_mysql
install_php
install_xcache
install_memcache
install_memcached
}
functionconfig_lnmmp{
config_mysql
config_php
config_php_fpm
}
echo-e"33[32m====makesureyumisok=========33[0m"
#create_yum
echo-e"33[32m====now,downloadallpackage====33[0m"
#download
echo-e"33[32m====installdevelopmentpackages====33[0m"
#yum-ygroupinstall"Developmenttools""ServerPlatformDevelopment"
echo-e"33[32m=========youcanchoiceyouneedinstallpackage==========33[0m"
cat<<EOF
apache|A)installapachesourcepackage.
nginx|N)installnginxsourcepackage.
mysql|M)installmysqlsourcepackage.
php|P)installphpsourcepackage.
php-fpm|PF)installphp-fpmsourcepackage.
xcache|X)installxcahesourcepackage.
memcache|ME)installmemcachesourcepackage.
memcached|MD)installmemcachedsourcepackage.
lamp)installlampsourcepackage.
lammp)installlammpsourcepackage.
lnmp)installlnmpsourcepackage.
lnmmp)installlnmmpsourcepackage.
q|Q)quit
EOF
read-p"Pleasechoosetoinstall:"Choice
echo-e"33[32m=====startinstall$Choice====33[0m"
until[$Choice==q-o$Choice==Q];do
case$Choicein
apache|A)
install_apache
config_apache;;
nginx|N)
install_nginx;;
mysql|M)
install_mysql
config_mysql;;
php|P)
install_php
config_php;;
php-fpm|PF)
install_php_fpm
config_php_fpm;;
xcache|X)
install_xcache;;
memcache|ME)
install_memcache;;
memcached|MD)
install_memcached;;
lamp)
install_lamp
config_lamp;;
lammp)
install_lammp
config_lammp;;
lnmp)
install_lnmp
config_lnmp;;
lnmmp)
install_lnmmp
config_lnmmp;;
q|Q)
break
esac
read-p"Haveanychoiceagin,ifyouno,q|Qisquit:"Choice
done


这个剧本和nginxsystemV,memcachedsystemV的剧本以附件的情势上传了,点此下载
缺点:
1)、没能为nginx供应主动化systemV剧本,可是nginx的systemV剧本我会以附件的体例上传,列位博友必要vim/etc/rc.d/init.d/nginx然后copy我供应的systemV剧本然后增加权限,就能够servicenginxstart了
2)、也没能为memcached供应主动化systemV剧本,可是memcached的systemV剧本会以附件体例上传,列位博友必要vim/etc/rc.d/init.d/memcached然后copy我供应的systemV剧本然后增加权限,就能够servicememcachedstart了

本文出自“手艺之路---桀”博客

为什么我使用一个命令的时候,系统告诉我找不到该目录,我要如何限制使用者的权限等问题,这些问题其实都不是很难的。
金色的骷髅 该用户已被删除
沙发
发表于 2015-1-18 10:11:00 来自手机 | 只看该作者
通过自学老师给的资料和向同学请教,掌握了一些基本的操作,比如挂载优盘,编译程序,在Linux环境下运行,转换目录等等。学了这些基础才能进行下面的模拟OS程序。?
透明 该用户已被删除
板凳
发表于 2015-1-24 14:50:33 | 只看该作者
就这样,我们一边上OS理论课,一边上这个实验,这样挺互补的,老师讲课,一步一步地布置任务
冷月葬花魂 该用户已被删除
地板
发表于 2015-2-1 17:19:42 来自手机 | 只看该作者
老实说,第一个程序是在C中编译好的,调试好了才在Linux下运行,感觉用vi比较麻烦,因为有错了不能调试,只是提示错误。
乐观 该用户已被删除
5#
发表于 2015-2-7 13:33:18 | 只看该作者
虽然大家都比较喜欢漂亮的mm,但是在学 linux 的过程中,还是要多和“男人”接触一下:P 遇到问题的时候,出来看说和上网查之外,就是要多用 linux 下的 man 命令找找帮助。
第二个灵魂 该用户已被删除
6#
发表于 2015-2-22 09:21:55 | 只看该作者
一定要学好命令,shell是命令语言,命令解释程序及程序设计语言的统称,shell也负责用户和操作系统之间的沟通。
再现理想 该用户已被删除
7#
发表于 2015-3-7 00:29:00 | 只看该作者
下面笔者在论坛看到的一个好问题: “安装红旗4.0后,系统紫光输入法自带的双拼方案和我的习惯不一样,如何自定义双拼方案解决?谢谢?”这个问题很简练。
分手快乐 该用户已被删除
8#
发表于 2015-3-14 00:34:03 | 只看该作者
和私有操作系统不同,各个Linux的发行版本的技术支持时间都较短,这对于Linux初学者是往往不够的。
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|Archiver|手机版|仓酷云 鄂ICP备14007578号-2

GMT+8, 2024-12-22 23:15

Powered by Discuz! X3.2

© 2001-2013 Comsenz Inc.

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