设为首页 收藏本站
查看: 1520|回复: 0

lamp脚本一键搭建

[复制链接]
累计签到:1 天
连续签到:1 天
发表于 2017-3-20 10:56:51 | 显示全部楼层 |阅读模式
lamp的工作流程:
1. 用户发送http请求到达httpd服务器

2. httpd解析url获取需要的资源的路径,通过内核空间读取硬盘资源,如是静态资源,则构建响应报文,发回给用户

3. 如果是动态资源,将资源地址发给php解析器,解析php程序文件,解析完毕将内容发回给httpd,httpd构建响应报文,发回给用户

4. 如果涉及到数据库操作,则利用php-mysql驱动,获取数据库数据,返回给PHP解析器。
lamp的工作方式
1:将php编译成模块,使用内存共享的方式去解析PHP页面。
2:CGI,通用网关接口,apache基于CGI跟PHP通信,通过CGI调用PHP解释器。
3:fastcgi、是一种协议,CGI的升级版。
PHP作为一种模块或者PHP解释器运行,不是监听在某个套接字上接受别人请求的,在php5.3.3版本后直接编译成php-fpm模块,通过这个模块可以使PHP和WEB的通信基于某个套接字去调用PHP解释器或者别的动态脚本解释器,采用分层机制的方式将PHP和HTTP服务器进行分离。
使用脚本安装LAMP环境:(1)安装apache的httpd:脚本内容:
[iyunv@www bin]# cat apache_install.sh
#!/bin/bash
#by linuxfan
rpm -e httpd httpd-manual --nodeps
ls /root/httpd*
if [ $? -eq 0 ];then
tar zxvf /root/httpd-2.2.17.tar.gz -C /usr/src/
cd /usr/src/httpd-2.2.17/
./configure --prefix=/usr/local/httpd --enable-rewrite --enable-so --disable-access 1>/dev/null
make &&make install
fi
[iyunv@www bin]#
执行安装:
[iyunv@www bin]# sh -x apache_install.sh
验证:
[iyunv@www bin]# yum -y install tree
[iyunv@www bin]# tree -L 2 /usr/local/httpd/
/usr/local/httpd/
├── bin
│   ├── ab
│   ├── apachectl
│   ├── apr-1-config
│   ├── apu-1-config
│   ├── apxs
│   ├── checkgid
│   ├── dbmmanage
(2)优化httpd:
[iyunv@www bin]# cp /usr/local/httpd/bin/apachectl /etc/init.d/httpd  ##复制启动文件
[iyunv@www bin]# vi /etc/init.d/httpd
:set nu
      1 #!/bin/bash
      2 # chkconfig: 35 85 15
      3 # description: A scripts for apache httpd deamon.
      83  echo "httpd is $ARGV ! "
:wq
[iyunv@www bin]# chkconfig --add httpd   ##添加为系统服务
[iyunv@www bin]# chmod +x /etc/init.d/httpd  # #授权
[iyunv@www bin]# /etc/init.d/httpd start
httpd is start !
[iyunv@www bin]# netstat -utpln |grep 80
tcp        0      0 :::80           :::*              LISTEN      53516/httpd
(3)安装mysql数据库:脚本内容:
[iyunv@www bin]# cat mysql_install.sh
#!/bin/bash
##第一配置yum,安装ncurses依赖包
yum -y install ncurses-*
#解压cmake,安装基础环境
tar zxvf /root/cmake-2.8.6.tar.gz -C /usr/src/
cd /usr/src/cmake-2.8.6
#配置,编译安装cmake
./configure &&gmake &&gmake install
##解压mysql
tar zxvf /root/mysql-5.5.22.tar.gz -C /usr/src/
cd /usr/src/mysql-5.5.22/
#cmake进行配置mysql
cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql   #指定安装目录\
-DDEFAULT_CHARSET=utf8   #指定字符集为utf8 \
-DDEFAULT_COLLATION=utf8_general_ci   ##指定字符校验 \
-DWITH_EXTRA_CHARSETS=all   ##支持额外字符集\
-DSYSCONFDIR=/etc/  ##指定配置文件位置
make &&make install   #编译安装
if [ -e /usr/local/mysql ];then
echo "mysql install successfully."
fi
[iyunv@www bin]#
安装:
[iyunv@www bin]# sh -x mysql_install.sh
。。。。。省略。。。。。
+ echo 'mysql install successfully.'
mysql install successfully.
[iyunv@www bin]# ls /usr/local/mysql/
bin      data  include         lib  mysql-test  scripts  sql-bench
COPYING  docs  INSTALL-BINARY  man  README      share    support-files
mysql只需要安装,不需要配置和启动。
(4)安装php环境:a.脚本内容:
[iyunv@www bin]# cat php_install.sh
#!/bin/bash
##by linuxfan 20150611
#1.卸载已经安装rpm包
rpm -qa |grep php
if [ $? -eq 0 ];then
rpm -e php php-mysql --nodeps
fi
#2.安装mcrypt支持,安装的顺序必须libmcrypt-->mhash-->mcrypt,每安装都必须ln链接到系统库中,echo "/usr/local/lib/" >>/etc/ld.conf&&ldconfig
##########install mcrypt###########
tar zxvf /root/libmcrypt-2.5.8.tar.gz -C /usr/src/
cd /usr/src/libmcrypt-2.5.8/
./configure &&make &&make install
ln -s /usr/local/lib/libmcrypt.* /usr/lib

tar zxvf /root/mhash-0.9.9.9.tar.gz -C /usr/src/
cd /usr/src/mhash-0.9.9.9/
./configure &&make &&make install
ln -s /usr/local/lib/libmhash* /usr/lib/

tar zxvf /root/mcrypt-2.6.8.tar.gz -C /usr/src/
cd /usr/src/mcrypt-2.6.8/
./configure &&make &&make install
#3.安装php
##############install php #############
yum -y install libxml2-* zlib-*
PHV=php-5.3.28
tar zxvf /root/$PHV.tar.gz -C /usr/src/
cd /usr/src/$PHV/
./configure --prefix=/usr/local/php5 --with-mcrypt --with-apxs2=/usr/local/httpd/bin/apxs --with-mysql=/usr/local/mysql/ \
--with-config-file-path=/usr/local/php5 --enable-mbstring &&make &&make install
if [ -e /usr/local/php5 ]
then
echo "php install success."
fi
[iyunv@www bin]#

b.执行安装脚本:
[iyunv@www bin]# sh -x php_install.sh
+ echo 'php install success.'
php install success.

c. php配置脚本内容:
[iyunv@www bin]# cat php_config.sh
#!/bin/bash
##by linuxfan
##############config php############
PHV=php-5.3.28
cp /usr/src/$PHV/php.ini-development /usr/local/php5/php.ini
#修改配置项支持php标记<?php ?>
sed -i 's/short_open_tag = Off/short_open_tag = On/g' /usr/local/php5/php.ini
##设置默认字符集utf8
echo "default_charset = "utf8" " >>/usr/local/php5/php.ini
###########add module zend############
ZDV=ZendGuardLoader-php-5.3-linux-glibc23-x86_64
tar zxvf /root/$ZDV.tar.gz -C /root/
cp -rf /root/$ZDV/php-5.3.x/ZendGuardLoader.so /usr/local/php5/lib/php/
cat <<END >>/usr/local/php5/php.ini
zend_extension=/usr/local/php5/lib/php/ZendGuardLoader.so
zend_enable=1
END
[iyunv@www bin]#

d.执行php配置脚本:
[iyunv@www bin]# sh -x php_config.sh
lamp配置脚本内容:
[iyunv@www bin]# cat lamp_config.sh
#!/bin/bash
##by scfa 2015-06-30
################# Setting  apache  with  php  ################
#1.修改apache的配置文件
APACHE_C=/usr/local/httpd/conf/httpd.conf
##添加ServerName设置FQDN
sed -i '/^#ServerName/a ServerName www.linuxfan.cn' $APACHE_C
##在第310行后一行添加php应用类型的支持
sed -i '310a \    AddType application/x-httpd-php .php' $APACHE_C
##修改默认首页,支持index.php
sed -i 's/DirectoryIndex index.html/DirectoryIndex index.html index.php/g' $APACHE_C
netstat -uptln |grep 80 &>/dev/null
if [ $? -eq 0 ]
then
/usr/local/httpd/bin/apachectl  stop && /usr/local/httpd/bin/apachectl  start
netstat -uptln |grep 80
echo "apache  restart successful"
else
/usr/local/httpd/bin/apachectl start
netstat -utpln |grep 80
fi
[iyunv@www bin]#

e.执行lamp配置脚本:
[iyunv@www bin]# sh -x lamp_config.sh
测试页面脚本内容:
[iyunv@www bin]# cat webpage.sh
#!/bin/bash
##by scfa 2015-06-30
#################  Test  Pages for php  and  mysql ############
DCT=/usr/local/httpd/htdocs/
cat  <<END > $DCT/testa.php
<?php
phpinfo();
?>
END

cat  <<END > $DCT/testm.php   ##由于本地mysql未启用
<?php
\$link=mysql_connect('192.168.100.112','root','123123');
if(\$link) echo "mysql ok!";
mysql_close();
?>
END
H_IP=$(ifconfig eth0 |awk -F '[ :]+' 'NR==2 {print $4}')
echo "Usage: http://$H_IP/testa.php  for test apache with php"
echo "Usage: http://$H_IP/testm.php  for test apache with mysql"
[iyunv@www bin]#

f.执行脚本:
[iyunv@www bin]# sh -x webpage.sh

g.测试:
QQ截图20170320105618.jpg

QQ截图20170320105622.jpg

因为mysql还没有部署,才报的错误。

部署DB: 下载软件:
[iyunv@db ~]# wget ftp://192.168.100.100/tools/lamp ... p-2015-07-16.tar.xz
[iyunv@db ~]# tar Jxvf lamp_install_publis-app-2015-07-16.tar.xz
安装mysql数据:
mysql配置脚本内容:
[iyunv@db ~]# cd bin/
[iyunv@db bin]# cat mysql_config.sh
#!/bin/bash
#1.复制配置文件
cp /usr/src/mysql-5.5.22/support-files/my-medium.cnf /etc/my.cnf
#2.添加系统服务
cp /usr/src/mysql-5.5.22/support-files/mysql.server /etc/init.d/mysqld
chmod +x /etc/init.d/mysqld
chkconfig --add mysqld
chkconfig mysqld  on
#3.优化PATH路径,执行命令时方便,单引号双引号都行
grep mysql /etc/profile
if [ $? -eq 0 ];then
echo "PATH is set."
else
echo "export PATH=$PATH:/usr/local/mysql/bin"  >>/etc/profile
source /etc/profile  ##执行文件
fi
#4.初始化mysql,创建用户,赋权
useradd -M -s /sbin/nologin mysql
chown -R mysql:mysql /usr/local/mysql
/usr/local/mysql/scripts/mysql_install_db  \
--basedir=/usr/local/mysql \
--datadir=/usr/local/mysql/data --user=mysql
#5.启动mysql,并设置为开机启动
if [ -e /tmp/mysql.sock ];then
/etc/init.d/mysqld restart
else
/etc/init.d/mysqld start
fi
chkconfig mysqld on
#6.修改密码,并提示密码
mysqladmin -u root password '123123'  &&echo "mysql root password is 123123"

[iyunv@db bin]# sh  -x  mysql_install.sh  &&sh  -x  mysql_config.sh
[iyunv@db bin]# source /etc/profile
[iyunv@db bin]# mysql -uroot -p123123
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.5.22-log Source distribution

Copyright (c) 2000, 2011, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql>
5.授权访问:mysql> flush privileges;
mysql> grant all on *.* to 'root'@'192.168.100.111' identified by '123123';
Query OK, 0 rows affected (0.00 sec)

QQ截图20170320105628.jpg

6.项目上线:(1)简单优化mysql:
a.删除空密码和空用户名的用户:
mysql> delete from mysql.user where user='';
Query OK, 2 rows affected (0.00 sec)

mysql> delete from mysql.user where password='';
Query OK, 3 rows affected (0.00 sec)


运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-352240-1-1.html 上篇帖子: Linux-php安装,搭建LAMP 下篇帖子: 自动安装lamp和lnmp环境
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

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