首页 > 代码库 > 一键搭建LNMP脚本
一键搭建LNMP脚本
还有不足的地方,请谅解 2天时间刚做到安装mysql这里。。。。
[root@localhost ~]# cat /etc/centos-release
CentOS release 6.7 (Final)
[root@localhost ~]# uname -a
Linux localhost 2.6.32-573.el6.x86_64 #1 SMP Thu Jul 23 15:44:03 UTC 2015 x86_64 x86_64 x86_64 GNU/Linu
以下是 一键安装脚本
#!/bin/bash
clear
mount /dev/sr0 /mnt/usb1
yum -y install httpd gcc* pcre-devel zlib-devel openssl openssl-devel perl-Digest-SHA1.x86_64 ncurses-devel
useradd -M -s /sbin/nologin nginx
for i in ./*.gz
do
tar -zxvf $i
done
for p in ./*.bz2
do
tar -jxvf $p
done
cd nginx-1.0.8
./configure --prefix=/usr/local/nginx --user=nginx --group=nginx --with-http_stub_status_module --with-http_ssl_module
make && make install
/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
b=80
k=`netstat -anpt|grep $b |awk -F ":" ‘{print $2}‘|awk -F " " ‘{print $1}‘`
#echo "$k"
if [[ $k -ne $b ]];then
service Nginx start
else
chmod 755 /etc/init.d/Nginx #这里执行/etc/init.d/Nginx另一个 启动|重启|停止 脚本
chkconfig --add Nginx
fi
cd ..
#安装mysql
#yum install ncurses-devel
cd mysql-5.1.55
./configure --prefix=/usr/local/mysql --with-collation=utf8_general_ci --with-charset=utf8 --with-extra-charsets=gbk,gb2312
y
make && make install
cp support-files/my-medium.cnf /etc/my.cnf
cp support-files/mysql.server /etc/init.d/mysqld
#tian jia dao xi tong fu wu
chmod 755 /etc/init.d/mysqld
chkconfig --add mysqld
#做软连接
ln -s /usr/local/mysql/bin/* /usr/local/bin
ln -s /usr/local/mysql/lib/mysql/* /usr/lib
ln -s /usr/local/mysql/include/mysql/* /usr/include
#tian jia yonghu bing chushihua mysql
useradd -M -s /sbin/nologin mysql
cd /usr/local/mysql/bin
./mysql_install_db --user=mysql
service mysqld start
待续未完。。。。
以下是Nginx的 重启|停止|启动 脚本
#!/bin/bash
#chkconfig:2345 99 20
a="/usr/local/nginx/sbin/nginx" #yuandizhi
conf=/usr/local/nginx/conf/nginx.conf
#b="/usr/local/nginx/logs/nginx.pid" #it‘s pid
case $1 in
start)
$a -c $conf
echo"Nginx start"
;;
stop)
killall -9 nginx
echo "Nginx stop"
;;
restart)
$0 stop &>/dev/null
$0 start &>/dev/null
echo "Nginx restart"
;;
*)
echo "pppp error" #这里可以随便写,只是个“标记”而已。。。
esac
问题总结:
编写后台进程的管理脚本,使用service deamon-name stop的时候,出现如下提示:
/sbin/service: line 66: 23299 Terminated env -i LANG="$LANG" PATH="$PATH" TERM="$TERM" "${SERVICEDIR}/${SERVICE}" ${OPTIONS}
原因:
把管理脚本的名称设为和后台进程名称一样,即:
后台进程名称:deamon-name,
脚本名称:/etc/init.d/deamon-name
脚本中有一句:
killall deamon-name
执行service deamon-name stop,本意是调用deamon-name脚本,结束后台进程deamon-name,结果连“service deamon-name stop”这条进程也被结束了。
解决方法:
把后台进程与脚本设置不同名称即可。
待续未完。。。
一键搭建LNMP脚本