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.测试:
因为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)
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)