shell脚本:一键安装LAMP、LNMP脚本
脚本需要注意的地方:
1:脚本适用于centos系统6.5以上,干净系统;如安装过其他环境需要修改脚本内容;
2:脚本适用于:apache 2.4.x 版本;mysql5.5.x以上版本;php5.5.x以上版本;
3:mysql 、php、 apache、 nginx 安装包事先要下载到/usr/localc目录下,如名字不对需要更改脚本里的软件包名称;
脚本安装的版本为以下,如需其他名称,请自行修改软件安装包名称和对应的目录名即可;
httpd-2.4.7.tar.gz 、mysql-5.6.25.tar.gz 、nginx-1.6.2.tar.gz、 php-5.6.8.tar.gz
4:脚本没有增加判断,设定的环境为干净系统;
脚本内容如下:
#!/bin/bash
#written by mofansheng @2015-11-06
#one key install LAMP or LNMP scripts; apply to apache 2.4.x,mysql 5.6.x,nginx 1.6.x;
. /etc/init.d/functions
#check the results of the command execution
function check_ok(){
if [ $? -eq 0 ]
then
continue
else
echo "please check error"
exit
fi
}
function yum_update(){
#set yum repos
echo "===update yum repos,it will take serval mintinues==="
yum install wget -y
mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.bak
wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-6.repo &>/dev/null
wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-6.repo &>/dev/null
yum clean all &>/dev/null
yum makecache &>/dev/null
check_ok
action "yum repos update is ok" /bin/true
}
function yum_depend(){
#install dependencies packages
yum install wget gcc gcc-c++ make re2c curl curl-devel libxml2 libxml2-devel libjpeg libjpeg-devel libpng libpng-devel libmcrypt libmcrypt-devel zlib zlib-devel openssl openssl-devel freetype freetype-devel gd gd-devel perl perl-devel ncurses ncurses-devel bison bison-devel libtool gettext gettext-devel cmake bzip2 bzip2-devel pcre pcre-devel -y
}
function install_mysql(){
echo "mysql5.6.25 will be installed,please be patient"
cd /usr/localc
tar -zxf mysql-5.6.25.tar.gz
cd mysql-5.6.25
cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DMYSQL_DATADIR=/data/mysql -DMYSQL_UNIX_ADDR=/usr/local/mysql/mysql.sock -DSYSCONFDIR=/etc -DWITH_MYISAM_STORAGE_ENGINE=1 -DWITH_ARCHIVE_STORAGE_ENGINE=1 -DWITH_BLACKHOLE_STORAGE_ENGINE=1 -DWITH_INNOBASE_STORAGE_ENGINE=1 -DWITH_MEMORY_STORAGE_ENGINE=1 -DWITH_READLINE=1 -DMYSQL_TCP_PORT=3306 -DENABLED_LOCAL_INFILE=1 -DWITH_PARTITION_STORAGE_ENGINE=1 -DEXTRA_CHARSETS=all -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci
check_ok
make && make install
check_ok
useradd -M -s /sbinlogin mysql
mkdir -p /data/mysql
chown -R mysql:mysql /data/mysql/
chown -R mysql:mysql /usr/local/mysql/
check_ok
cd /usr/local/mysql/scripts/
./mysql_install_db --basedir=/usr/local/mysql/ --datadir=/data/mysql/ --user=mysql
check_ok
/bin /usr/local/mysql/my.cnf /etc/my.cnf
sed -i '/^[mysqld]$/auser = mysql datadir = /data/mysql default_storage_engine = InnoDB ' /etc/my.cnf
check_ok
cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld
sed -i 's#^datadir=#datadir=/data/mysql#' /etc/init.d/mysqld
sed -i 's#^basedir=#basedir=/usr/local/mysql#' /etc/init.d/mysqld
service mysqld start
chkconfig --add mysqld
chkconfig mysqld on
check_ok
iptables -A INPUT -m state --state NEW -m tcp -p tcp --dport 3306 -j ACCEPT
/etc/init.d/iptables save
check_ok
echo "export PATH=$PATH:/usr/local/mysql/bin" >>/etc/profile
source /etc/profile
check_ok
}
function install_apache(){
echo "apache2.4.7 will be installed,please be patient"
cd /usr/localc
wget http://mirrors.cnnic.cn/apache/apr/apr-1.5.2.tar.gz
wget http://mirrors.cnnic.cn/apache/apr/apr-util-1.5.4.tar.gz
check_ok
tar zxf apr-1.5.2.tar.gz
cd apr-1.5.2
./configure --prefix=/usr/local/apr
check_ok
make && make install
check_ok
cd /usr/localc
tar zxf apr-util-1.5.4.tar.gz
cd apr-util-1.5.4
./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr
check_ok
make && make install
check_ok
cd /usr/localc
tar zxf httpd-2.4.7.tar.gz
/bin -r apr-1.5.2 /usr/localctpd-2.4.7clib/apr
/bin -r apr-util-1.5.4 /usr/localctpd-2.4.7clib/apr-util
cd httpd-2.4.7
./configure --prefix=/usr/local/apache2 --with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util/ --with-pcre --enable-mods-shared=most --enable-so --with-included-apr
check_ok
make && make install
check_ok
echo "export PATH=$PATH:/usr/local/apache2/bin" >>/etc/profile
source /etc/profile
check_ok
iptables -A INPUT -m state --state NEW -m tcp -p tcp --dport 80 -j ACCEPT
/etc/init.d/iptables save
check_ok
/usr/local/apache2/bin/apachectl
check_ok
}
function install_php(){
echo "php5.6.8 will be installed,please be patient"
cd /usr/localc
tar zxf php-5.6.8.tar.gz
cd php-5.6.8
./configure --prefix=/usr/local/php --with-apxs2=/usr/local/apache2/bin/apxs --with-config-file-path=/usr/local/php/etc --with-mysql=/usr/local/mysql --with-libxml-dir --with-gd --with-jpeg-dir --with-png-dir --with-freetype-dir --with-iconv-dir --with-zlib-dir --with-bz2 --with-openssl --with-mcrypt --enable-soap --enable-gd-native-ttf --enable-mbstring --enable-sockets --enable-exif --disable-ipv6
check_ok
make && make install
check_ok
cp /usr/localc/php-5.6.8/php.ini-production /usr/local/php/etc/php.ini
sed -i 's#^;date.timezone =#date.timezone=Asia/Shanghai#' /usr/local/php/etc/php.ini
check_ok
}
function set_lamp(){
sed -i '/AddType application/x-gzip .gz .tgz/a AddType application/x-httpd-php .php ' /usr/local/apache2/conftpd.conf
sed -i 's#index.html#index.html index.php#' /usr/local/apache2/conftpd.conf
sed -i '/#ServerName www.example.com:80/aServerName localhost:80 ' /usr/local/apache2/conftpd.conf
check_ok
cat >>/usr/local/apache2docs/test.php<<EOF
<?php
echo "PHP is OK ";
?>
EOF
/usr/local/apache2/bin/apachectl graceful
check_ok
curl localhost/test.php
check_ok
action "LAMP is install success" /bin/true
}
function install_phpfpm(){
echo "php5.6.8 will be installed,please be patient"
useradd -s /sbinlogin php-fpm
cd /usr/localc
tar zxf php-5.6.8.tar.gz
cd php-5.6.8
./configure --prefix=/usr/local/php-fpm --with-config-file-path=/usr/local/php-fpm/etc --enable-fpm --with-fpm-user=php-fpm --with-fpm-group=php-fpm --with-mysql=mysqlnd --with-pdo-mysql=mysqlnd --with-mysqli=mysqlnd --with-libxml-dir --with-gd --with-jpeg-dir --with-png-dir --with-freetype-dir --with-iconv-dir --with-zlib-dir --with-mcrypt --enable-soap --enable-gd-native-ttf --enable-ftp --enable-exif --disable-ipv6 --with-pear --with-curl --enable-bcmath --enable-mbstring --enable-sockets --with-gettext
check_ok
make && make install
check_ok
cp /usr/localc/php-5.6.8/php.ini-production /usr/local/php-fpm/etc/php.ini
sed -i 's#^;date.timezone =#date.timezone=Asia/Shanghai#' /usr/local/php-fpm/etc/php.ini
cd /usr/local/php-fpm/etc/
mv php-fpm.conf.default php-fpm.conf
check_ok
cp /usr/localc/php-5.6.8pi/fpm/init.d.php-fpm /etc/init.d/php-fpm
chmod 755 /etc/init.d/php-fpm
chkconfig --add php-fpm
chkconfig php-fpm on
service php-fpm start
check_ok
}
function install_nginx(){
echo "nginx1.6.2 will be installed,please be patient"
cd /usr/localc
tar zxf nginx-1.6.2.tar.gz
cd nginx-1.6.2
./configure --prefix=/usr/localinx --with-pcre --with-http_stub_status_module --with-http_ssl_module --with-http_gzip_static_module
check_ok
make && make install
check_ok
/usr/localinx/sbininx
check_ok
}
function set_lnmp(){
sed -i '56alocation ~ .php$ { root html; fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME /usr/localinxml$fastcgi_script_name; include fastcgi_params; } ' /usr/localinx/confinx.conf
/usr/localinx/sbininx -s reload
check_ok
echo -e '<?php echo "nginx and PHP is OK"; ?> ' >/usr/localinxml/index.php
curl localhost/index.php
check_ok
action "LNMP is install success" /bin/true
}
function install_lamp(){
echo "apache 2.4.7 mysql 5.6.24 php5.6.8 will be installed"
echo "===update yum repos and install dependecies packages,it will take serval mintinues==="
yum_update
check_ok
yum_depend
check_ok
install_mysql
check_ok
install_apache
check_ok
install_php
check_ok
set_lamp
}
function install_lnmp(){
echo "nginx1.6.2 mysql 5.6.24 php5.6.8 will be installed"
echo "===update yum repos and install dependecies packages,it will take serval mintinues==="
yum_update
check_ok
yum_depend
check_ok
install_mysql
check_ok
install_phpfpm
check_ok
install_nginx
check_ok
set_lnmp
}
cat <<EOF
1:[install LAMP]
2:[install LNMP]
3:[exit]
EOF
read -t 10 -p "please input the num you want:" input
case ${input} in
1)
install_lamp
;;
2)
install_lnmp
;;
3)
exit
;;
*)
printf "You must input only in {1|2|3} "
esac
经验总结:
以上就是系统大全给大家介绍的如何使的方法都有一定的了解了吧,好了,如果大家还想了解更多的资讯,那就赶紧点击系统大全官网吧。
本文来自系统大全http://www.win7cn.com/如需转载请注明!推荐:win7纯净版
相关文章
- WorkBuddy 下载地址分享:腾讯版 “小龙虾”一键获取
- 阿里版 “OpenClaw 龙虾” 开启内测,无影 JVS 更名为 JVS Claw
- 腾讯版 “小龙虾” WorkBuddy 正式上线,兼容 OpenClaw 技能
- 微软 Win11 文件资源管理器将迎来更多圆角设计
- Win11 新增 “节能器” 菜单,支持一键切换深色 / 浅色模式
- 微软放缓新版 Outlook 企业强制迁移,延后至 2027 年 3 月
- Epic 喜加二!《大头菜小子抢银行》《遗忘国度之闲置冠军》免费领
- 英伟达发布 595.76 热修复驱动,解决显卡超频电压受限问题
- NVIDIA 发布 595.71 显卡驱动!附下载地址
- 微软扩大 Win11 彩色电池图标推送,电量状态一目了然
系统下载排行榜71011xp
番茄花园 Win7 64位 快速稳定版
2【纯净之家】Windows7 32位 全新纯净版
3【纯净之家】Win7 64位 Office2007 办公旗舰版
4【雨林木风】Windows7 64位 装机旗舰版
5JUJUMAO Win7 64位旗舰纯净版
6【电脑公司】Windows7 64位 免费旗舰版
7【纯净之家】Windows7 SP1 32位 全补丁旗舰版
8【深度技术】Windows7 64位 官方旗舰版
9【游戏专用】Windows7 64位 装机旗舰版
10【番茄花园】Windows7 64位 旗舰装机版
【纯净之家】Windows10 22H2 64位 企业版
2JUJUMAO Win10 X64 极速精简版
3【深度技术】 Win10 64位国庆特别版
4【雨林木风】Windows10 64位 专业精简版
5【深度技术】Windows10 64位 专业精简版
6【纯净之家】Windows10 32位 官方正式版
7【雨林木风】Windows10 64位稳定版系统
8【番茄花园】Windows10 64位 专业版镜像
9【技术员】Windows10 64位 系统纯净版
10【雨林木风】Windows10 64位 官方专业版
【纯净之家】Windows11 23H2 64位 游戏优化版
2【纯净之家】Windows11 23H2 64位 纯净专业版
3【纯净之家】Windows11 23H2 64位 企业版
4【纯净之家】Windows11 23H2 64位 中文家庭版
5风林火山Windows11下载中文版(24H2)
6【纯净之家】Windows11 23H2 64位专业精简版
7JUJUMAO Win11 24H2 64位 专业版镜像
8JUJUMAO Win11 24H2 64位 精简版镜像
9【纯净之家】Windows11 23H2 64位 纯净家庭版
10雨林木风 Win11 25H2 超级纯净版系统
深度技术 GHOST XP SP3 电脑专用版 V2017.03
2深度技术 GGHOST XP SP3 电脑专用版 V2017.02
3萝卜家园 GHOST XP SP3 万能装机版 V2017.03
4番茄花园 GHOST XP SP3 极速体验版 V2017.03
5Win7系统下载 PCOS技术Ghost WinXP SP3 2017 夏季装机版
6雨林木风 GHOST XP SP3 官方旗舰版 V2017.03
7萝卜家园 GHOST XP SP3 完美装机版 V2016.10
8电脑公司 GHOST XP SP3 经典旗舰版 V2017.03
9雨林木风GHOST XP SP3完美纯净版【V201710】已激活
10雨林木风 GHOST XP SP3 精英装机版 V2017.04
热门教程
装机必备 更多+
重装工具