安装注意:
本地光盘得挂载好需要安装一些依赖包及充当yum源;
源码包存放的位置与脚本中要一致;
使用脚本形式安装,安装前先看脚本内容,稍作调整后再进行安装;
安装mcrypt支持,安装的顺序必须libmcrypt-->mhash-->mcrypt,每安装都必须ln链接到系统库中;
防火墙和selinux先关闭最后在打开。
需提前准备好以下源码包及yum的配置
源码包:
httpd-2.2.17.tar.gz ##apache的httpd cmake-2.8.6.tar.gz ##mysql使用cmake安装
mysql-5.5.22.tar.gz ##mysql使用cmake安装
libmcrypt-2.5.8.tar.gz ##mcrypt支持
mhash-0.9.9.9.tar.gz ##mcrypt支持
mcrypt-2.6.8.tar.gz ##mcrypt支持
php-5.3.28.tar.gz ##php
ZendGuardLoader-php-5.3-linux-glibc23-x86_64.tar.gz ##php中添加模块
yum的配置:
mount /dev/cdrom /mnt ##挂载本地光盘
rm -rf /etc/yum.repos/* ##删除多余的yum文件配置
vi /etc/yum.repos/centos.repo ##新加yum文件配置
[local]
name=local
baseurl=file:///mnt
enabled=1
gpgcheck=0
:wq
一,安装apache
vi apache_install.sh ##编辑apache的脚本安装文件
#!/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
:wq
给脚本加执行权限
chmod +x apache_install.sh ##加权
./apache_install.sh ##执行脚本
添加apache为系统服务
cp /usr/local/httpd/bin/apachectl /etc/init.d/httpd ##复制启动文件
vi /etc/init.d/httpd
:set nu
1 #!/bin/bash
2 # chkconfig: 35 85 15 ##运行级别调整
3 # description: A scripts for apache httpd deamon.
:wq
chkconfig --add httpd ##添加为系统服务
chmod +x /etc/init.d/httpd ##授权
/etc/init.d/httpd start ##启动
netstat -utpln |grep 80 ##端口检测
二、安装mysql数据库
vi mysql_install.sh
#!/bin/bash
##############install mysql###############
##第一配置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
#############mysql优化调整##############
#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"
:wq
给脚本加执行权限--执行---启动---检测端口
chmod +x mysql_install.sh
./mysql_install.sh
/etc/init.d/mysqld start
netstat -utpln |grep 3306
三、php
vi 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
###############优化php###############
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
:wq
chmod +x php_install.sh
./php_install.sh
四、lamp环境调试
vi lamp_config.sh
#!/bin/bash
##by scfa
################# 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
################# Test Pages for php and mysql ############
DCT=/usr/local/httpd/htdocs/
cat <<END > $DCT/testa.php
<?php
phpinfo();
?>
END
cat <<END > $DCT/testm.php
<?php
\$link=mysql_connect(‘localhost‘,‘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"
:wq
chmod +x lamp_config.sh
./lamp_config.sh
测试访问:
注意关掉防火墙和selinux
http://IP地址/testa.php
http://IP地址/testm.php
设置iptables:
iptables -I INPUT -m state --state NEW -p tcp --dport 80 -j ACCEPT
iptables -I INPUT -m state --state NEW -s 192.168.100.0/24 -p tcp --dport 22 -j ACCEPT
iptables -I INPUT -i lo -j ACCEPT
iptables -I INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
iptables -A INPUT -p tcp --dport 80 -m recent --name BAD_HTTP_ACCESS --update --seconds 30 --hitcount 20 -j REJECT
iptables -A INPUT -p tcp --dport 80 -m recent --name BAD_HTTP_ACCESS --set -j ACCEPT
iptables -I INPUT -p tcp --dport 80 -m connlimit --connlimit-above 50 -j REJECT
iptables -P INPUT DROP
iptables -P FORWARD DROP
/etc/init.d/iptables save
chkconfig iptables on
设置selinux:
sed -i ‘/^SELINUX/s/disabled/enforcing/g‘ /etc/selinux/config ##开启selinux
reboot
chcon -R -t httpd_sys_content_t /usr/local/httpd/htdocs/
setsebool -P httpd_enable_cgi=on
getsebool -a |grep http |grep on$
vi /etc/rc.local ##将selinux命令添加到rc.local文件中使他开机执行
chcon -R -t httpd_sys_content_t /usr/local/httpd/htdocs/
setsebool -P httpd_enable_cgi=on
:wq