由于最近买了一个burst的vps, 于是开始看些linux下的东西, 挺有意思, 开始在网上进行一些centos的设置, 并且记录在我的wiki上, 最近开始接触到脚本, 发现很强大, 省得学习时重装系统后繁琐的重复设置, 于是自己尝试写了一点, 主要为了偷懒, 而且写得十分粗燥, 不过总算在centos5.4和fedora12中测试通过.
如果安装成功, 能在最后看到各种服务的启动[OK]或是successfully, 由于不是编译安装, 所以基本不是最新版, 但应该是稳定版, 而且由于是默认安装, 以后升级也方便, 出了问题也容易google排查, 因为都是默认安装路径, 不会出现找不到文件的情况. 当然也可以选择LNMP之类的一键包, 只要有人维护, 这类包升级也方便.
OK, 安装很简单, 尽量在新装的系统中应用, 如果原先装过mysql, 则可能造成root密码为原先的密码.
1. 首先下载脚本centos.sh
2. 更改权限 chmod +x centos.sh
3. 运行./centos.sh
4. 输入mysql root的密码
5. 等待完成, 最后一排绿色[OK]和一个spawn-fcgi的successfully的字样就完成了
在fedora12和centos5.4中成功, 如果是debian或是ubuntu的话, 可能改成apt-get就行了, 暂时没有测试
#!/bin/bash
# molezz centos shell: http://www.molezz.net/
# version: 0.2
# 2010-04-23
#
# Reference:
# http://www.centospub.com/
# http://www.atans.cn/post/93/
# http://www.zquan.me/article.asp?id=31
#
# check root
if [ $(id -u) != "0" ]; then
echo "ERROR: You are not root, please use root"
exit 1
fi
echo "---------------------set mysql root password--------------------"
mysqlrootpasswd="root"
echo "please input the mysql root password: "
read -p "(defalt password: root):" mysqlrootpasswd
if [ "$mysqlrootpasswd" = "" ]; then
mysqlrootpasswd = "root"
fi
echo "---------------------installation start-------------------------"
# update and clear
yum -y update
ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
rpm -qa|grep httpd
rpm -e httpd
rpm -qa|grep nginx
rpm -e nginx
rpm -qa|grep spawn-fcgi
rpm -e spawn-fcgi
rpm -qa|grep php
rpm -e php-mysql
rpm -qa|grep mysql
rpm -e mysql-server
rpm -e perl-DBD-MySQL
rpm -e mysql
echo "--------------------------install nginx-------------------------"
rpm -Uvh http://download.fedora.redhat.com/pub/epel/5/i386/epel-release-5-3.noarch.rpm
yum -y install nginx
chkconfig --level 235 nginx on
service nginx start
echo "--------------------------install mysql-------------------------"
yum -y install mysql-server
chkconfig --level 235 mysqld on
echo "-----------------install php and spawn-fcgi-----------------------"
yum -y install php-cgi php-mysql
yum -y install spawn-fcgi
echo "spawn-fcgi -C 5 -a 127.0.0.1 -p 9000 -u nginx -g nginx -f /usr/bin/php-cgi" >> /etc/rc.local
# modify the nginx.conf, I hope I can write beautiful later................
sed '104,111s/#//g' /etc/nginx/nginx.conf > /etc/nginx/nginx.conf.out
mv -f /etc/nginx/nginx.conf.out /etc/nginx/nginx.conf
sed 's/index.html index.htm/index.html index.htm index.php/g' /etc/nginx/nginx.conf > /etc/nginx/nginx.conf.out
mv -f /etc/nginx/nginx.conf.out /etc/nginx/nginx.conf
sed 's:/scripts:/usr/share/nginx/html:g' /etc/nginx/nginx.conf > /etc/nginx/nginx.conf.out
mv -f /etc/nginx/nginx.conf.out /etc/nginx/nginx.conf
service mysqld start
/usr/bin/mysqladmin -u root password $mysqlrootpasswd
sed '/22 -j/{h;p;g;s/22 -j/80 -j/g}' /etc/sysconfig/iptables > /etc/sysconfig/iptables.out
mv -f /etc/sysconfig/iptables.out /etc/sysconfig/iptables
service iptables restart
spawn-fcgi -C 5 -a 127.0.0.1 -p 9000 -u nginx -g nginx -f /usr/bin/php-cgi
service nginx restart
echo "" >> /usr/share/nginx/html/test.php
echo "********************************************************************"
echo "********************************************************************"
echo "** completed! **"
echo "********************************************************************"
echo "** **"
echo "** php info: http://127.0.0.1/test.php **"
echo "** nginx config file: /etc/nginx/nginx.conf **"
echo "** web dir: /usr/share/nginx/html **"
echo "** mysql dir: /usr/bin **"
echo "** mysql database dir: /var/lib/mysql **"
echo "** php location: /usr/bin **"
echo "** **"
echo "********************************************************************"
echo "** **"
echo "** for mysql security, you should run secure setting **"
echo "** /usr/bin/mysql_secure_installation **"
echo "** **"
echo "********************************************************************"
echo "mysql root password : $mysqlrootpasswd "
懒人啊... 习惯yum, apt-get
使用Nginx的话可以看看张宴的《实战Nginx取代Apache的高性能Web服务器》 及其 他的个人博客文章 作为操作手册或学习都挺不错 个人也刚在看
@luckythree 汗.... 纯属西拼八凑, 再自己写点.... 请看reference....
今天我只开始学习shell script,你已经在写了,作为cs毕业的我,惭愧啊
@Yousri 恩, 我上次看了他的blog才决定玩玩nginx而不是apache的.....