该脚本有很多辅助的部分,主要是为了让脚本在中途运行失败可以多次运行,所产生的结果是预期的,与第一运行并成功的结果是一样的。初次摄入bash脚本有很多不足,敬请指正。 所需要的软件 apr-1.5.2.tar.bz2 apr-util-1.5.4.tar.bz2 Discuz_X3.2_SC_UTF8.zip freetype-2.5.4.tar.gz httpd-2.4.18.tar.bz2 jpegsrc.v9a.tar.gz libgd-2.1.0.tar.gz libmcrypt-2.5.8.tar.gz libpng-1.6.20.tar.xz libvpx-v1.3.0.tar.bz2 mysql-5.6.21.tar.gz pcre-8.37.tar.bz2 php-5.6.16.tar.bz2 t1lib-5.1.2.tar.gz tiff-4.0.3.tar.gz yasm-1.3.0.tar.gz #!/bin/bash #A key to install LAMP #set iptables iptables -F iptables -X iptables -Z iptables -P INPUT DROP iptables -P OUTPUT DROP iptables -P FORWARD DROP iptables -A INPUT -i lo -j ACCEPT iptables -A INPUT -m state --state ESTABLISHED,RELATED,NEW -j ACCEPT iptables -A INPUT -p icmp -j ACCEPT iptables -A INPUT -p tcp -m multiport --dports 80,53,22,3306 -j ACCEPT iptables -A INPUT -p udp -m multiport --dports 53 -j ACCEPT iptables -A OUTPUT -m state --state ESTABLISHED,RELATED -j ACCEPT iptables -A OUTPUT -p icmp -j ACCEPT iptables -A OUTPUT -p tcp -m multiport --dport 53,123 -j ACCEPT iptables -A OUTPUT -p udp -m multiport --dport 53,123 -j ACCEPT /etc/init.d/iptables save 1>/dev/null 2>&1 #set date update date/time each hour。此实验例子可以上互联网 ntpdate s1a.time.edu.cn 1>/dev/null 2>&1 if [ /etc/cron.hourly/ntpdate ] then touch /etc/cron.hourly/ntpdate; echo "ntpdate s1a.time.edu.cn" >/etc/cron.hourly/ntpdate fi #mount cdrom 主要是让安装软件速度快些,连接互联网的速度太慢了 if [ ! -d /mnt/cdrom ] then mkdir /mnt/cdrom fi umount /dev/sr0 1>/dev/null 2>&1 mount /dev/sr0 /mnt/cdrom 1>/dev/null 2>&1 #set yum source if [ -f /etc/yum.repos.d/CentOS-Base.repo ] then mv /etc/yum.repos.d/CentOS-Base.repo{,.bak} fi if [ -f /etc/yum.repos.d/CentOS-Media.repo ] then mv /etc/yum.repos.d/CentOS-Media.repo{,.bak} fi touch /etc/yum.repos.d/CentOS-Media.repo echo -e "[c6-mdeia]\n \ name=centos6\n \ baseurl=file:///mnt/cdrom\n \ gpgcheck=1\n \ enabled=1\n \ gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-6" \ >/etc/yum.repos.d/CentOS-Media.repo yum clean all && yum makecache 1>/dev/null 2>&1 yum grouplist Development tools | grep "Available Groups" 1>/dev/null 2>&1 && \ yum -y groupinstall Development tools 1>/dev/null 2>&1 #install Apache,before need install apr、apr-util and pcre. #install httpd before remove older version httpd service stop httpd 1>/dev/null 2>&1 rpm -q httpd 1>/dev/null 2>&1 && yum -y remove httpd 1>/dev/null 2>&1 if [ ! -d /usr/src/apr/bin ] then [ -d /usr/src/apr ] || mkdir /usr/src/apr 2>/dev/null; [ -d /root/apr-1.5.2 ] || \ tar -xvf /root/apr-1.5.2.tar.bz2 -C /root 1>/dev/null 2>&1; cd /root/apr-1.5.2 2>/dev/null ./configure --prefix=/usr/src/apr 1>/dev/null 2>&1; if [ $? -eq 0 ] then make 1>/dev/null 2>&1 if [ $? -eq 0 ] then make install 1>/dev/null 2>&1 if [ $? -ne 0 ] then make clean 1>/dev/null 2>&1 fi else make clean 1>/dev/null 2>&1 fi fi fi #install apr-util need --with-apr if [ ! -d /usr/src/apr-util/bin ] then [ -d /usr/src/apr-util ] || mkdir /usr/src/apr-util 2>/dev/null; [ -d /root/apr-util-1.5.4 ] || \ tar xvf /root/apr-util-1.5.4.tar.bz2 -C /root 1>/dev/null 2>&1; cd /root/apr-util-1.5.4 2>/dev/null; ./configure --prefix=/usr/src/apr-util \ --with-apr=/usr/src/apr 1>/dev/null 2>&1; if [ $? -eq 0 ] then make 1>/dev/null 2>&1 if [ $? -eq 0 ] then make install 1>/dev/null 2>&1 if [ $? -ne 0 ] then make clean 1>/dev/null 2>&1 fi else make clean 1>/dev/null 2>&1 fi fi fi # install pcre if [ ! -d /usr/src/pcre/bin/ ] then [ -d /usr/src/pcre ] || mkdir /usr/src/pcre 2>/dev/null; [ -d /root/pcre-8.37 ] || \ tar -xvf /root/pcre-8.37.tar.bz2 -C /root 1>/dev/null 2>&1; cd /root/pcre-8.37 2>/dev/null; ./configure --prefix=/usr/src/pcre 1>/dev/null 2>&1; if [ $? -eq 0 ] then make 1>/dev/null 2>&1 if [ $? -eq 0 ] then make install 1>/dev/null 2>&1 if [ $? -ne 0 ] then make clean 1>/dev/null 2>&1 fi else make clean 1>/dev/null 2>&1 fi fi fi # install Apache --with-apr --with-apr-util --with-pcre if [ ! -d /usr/src/apache/bin ] then [ -d /usr/src/apache ] || mkdir /usr/src/apache 2>/dev/null; [ -d /root/httpd-2.4.18 ] || \ tar -xvf /root/httpd-2.4.18.tar.bz2 -C /root 1>/dev/null 2>&1; cd /root/httpd-2.4.18 2>/dev/null; ./configure --prefix=/usr/src/apache \ --with-apr=/usr/src/apr \ --with-apr-util=/usr/src/apr-util \ --with-pcre=/usr/src/pcre 1>/dev/null 2>&1; if [ $? -eq 0 ] then make 1>/dev/null 2>&1 if [ $? -eq 0 ] then make install 1>/dev/null 2>&1 if [ $? -ne 0 ] then make clean 1>/dev/null 2>&1 fi else make clean 1>/dev/null 2>&1 fi fi fi # config Apache support php # add x-httpd-php httpdconf="/usr/src/apache/conf/httpd.conf" grep "AddType application/x-httpd-php .php" $httpdconf 1>/dev/null 2>&1 || \ sed -i '/AddType application\/x-gzip .gz .tgz/a\ \ AddType application/x-httpd-php .php\n \ AddType application/x-httpd-php-source .php5' $httpdconf #AddType前面的空格主要是为了在配置文件里面对其所添加的 #加grep 主要是让脚本能够多次运行。以防止前一次某些地方运行错误,导致配置文件里面多次加 #入上述内容。下面的grep所实现的功能是一样的 #add index.php grep "index.php" /usr/src/apache/conf/httpd.conf 1>/dev/null 2>&1 || \ sed -i '/index.html/s/$/ index.php/' /usr/src/apache/conf/httpd.conf #set ServerNamdde IP=`(ifconfig eth0 | grep "inet addr" | awk '{print$2}' | cut -d ':' -f 2)` grep "$IP" /usr/src/apache/conf/httpd.conf 1>/dev/null 2>&1 || \ sed -i "/#ServerName www.example.com:80/a\ServerName $IP:80" $httpdconf #start httpd /usr/src/apache/bin/apachectl -k start #开启 httpd 开机自动启动 echo "/usr/src/apache/bin/apachectl -k start" >/etc/rc.d/rc.local #set PATH touch /etc/profile.d/httpd.sh echo "/usr/src/apache/bin:$PATH" #remove old-version mysql even if mysql's client rpm -q mysql-libs 1>/dev/null 2>&1 && yum -y remove mysql-libs # mysql need ncurses-devel ncurses provide character terminal processing library rpm -q ncurses-devel 1>/dev/null 2>&1 || yum -y install ncurses-devel 1>/dev/null 2>&1 [ -d /root/mysql-5.6.21 ] || \ tar -xvf /root/mysql-5.6.21.tar.gz -C /root 1>/dev/null 2>&1 # Compile install mysql need cmake rpm -q cmake 1>/dev/null 2>&1 || yum -y install cmake 1>/dev/null 2>&1 [ -d /usr/src/mysql ] || mkdir /usr/src/mysql 2>/dev/null cd /root/mysql-5.6.21 # compile mysql and install if [ ! -f /usr/src/mysql/support-files/mysql.server ] then cmake -DCMAKE_INSTALL_PREFIX=/usr/src/mysql \ -DMYSQL_DATADIR=/data \ -DSYSCONFIGDIR=/etc \ -DWITH_ARCHIVE_STORAGE_ENGINE=1 \ -DWITH_INNOBASE_STORAGE_ENGINE=1 \ -DWITH_BLACKHOLE_STORAGE_ENGINE=1 \ -DWITH_PARTITION_STORAGE_ENGINE=1 \ -DMYSQL_UNIX_ADDR=/var/lib/mysql/mysql.sock \ -DMYSQL_TCP_PORT=3306 \ -DENABLED_LOCAL_INFILE=1 \ -DEXTRA_CHARSETS=all \ -DDEFAULT_CHARSET=utf8 \ -DDEFAULT_COLLATION=utf8_general_ci \ -DMYSQL_USER=mysql 1>/dev/null 2>&1 if [ $? -eq 0 ] then make 1>/dev/null 2>&1 if [ $? -eq 0 ] then make install 1>/dev/null 2>&1 if [ $? -ne 0 ] then make clean 1>/dev/null 2>&1 fi else make clean 1>/dev/null 2>&1 fi else rm -f /root/mysql-5.6.21/CMakeCache.txt 2>/dev/null; fi fi # create user and group fro mysql grep "mysql" /etc/group || groupadd -r mysql grep "mysql" /etc/passwd || useradd -r -g mysql -s /sbin/nolog -M mysql chown -R mysql:mysql /usr/src/mysql #Initialize the mysql cd /usr/src/mysql dasedir="/usr/src/mysql" datadir="/usr/src/mysql/data" scripts/mysql_install_db --basedir=$basedir --datadir=$datadir --user=mysql #start mysql cp support-files/mysql.server /etc/init.d/mysql chkconfig mysql on service mysql start #如果mysql安装目录和数据目录属主和属组不是mysql,会启动失败 #set mysql root user local and remote password #local_root_password=1234567.asd #remote_root_password=1qaz.2wsx 密码写入脚本应注意保密 mysqladmin -uroot password '1qaz2wsx.' mysql="mysql -uroot -p1qaz2wsx." sql="GRANT ALL PRIVILEGES ON *.* TO 'root'@'192.168.91.%' IDENTIFIED BY '1234.qwer' \ WITH GRANT OPTION" $mysql -e "$sql #install PHP but first install php extension #install yasm if [ ! -f /usr/local/bin/yasm ] then [ -d /root/yasm-1.3.0 ] || \ tar -xvf /root/yasm-1.3.0.tar.gz -C /root 1>/dev/null 2>&1 cd /root/yasm-1.3.0 2>/dev/null && ./configure 1>/dev/null 2>&1; if [ $? -eq 0 ] then make 1>/dev/null 2>&1 if [ $? -eq 0 ] then make install 1>/dev/null 2>&1 if [ $? -ne 0 ] then make clean 1>/dev/null 2>&1 fi else make clean 1>/dev/null 2>&1 fi fi fi # install ibmcrypt if [ ! -d /usr/src/libmcrypt/bin ] then [ -d /usr/src/libmcrypt ] || mkdir /usr/src/libmcrypt 2>/dev/null; [ -d /root/libmcrypt-2.5.8 ] || \ tar -xvf /root/libmcrypt-2.5.8.tar.gz -C /root 1>/dev/null 2>&1; cd /root/libmcrypt-2.5.8 2>/dev/null; ./configure --prefix=/usr/src/libmcrypt 1>/dev/null 2>&1; if [ $? -eq 0 ] then make 1>/dev/null 2>&1 if [ $? -eq 0 ] then make install 1>/dev/null 2>&1 if [ $? -ne 0 ] then make clean 1>/dev/null 2>&1 fi else make clean 1>/dev/null 2>&1 fi fi fi # install libgd but libgd need libvpx freetype libpng fontconfig libXpm tiff jpeg-9a # install libvpx if [ ! -d /usr/src/libvpx/bin ] then [ -d /usr/src/libvpx ] || mkdir /usr/src/libvpx 2>/dev/null; [ -d /root/libvpx-v1.3.0 ] || \ tar -xvf /root/libvpx-v1.3.0.tar.bz2 -C /root 1>/dev/null 2>&1; cd /root/libvpx-v1.3.0; ./configure --prefix=/usr/src/libvpx \ --enable-shared --enable-vp9 1>/dev/null 2>&1; if [ $? -eq 0 ] then make 1>/dev/null 2>&1 if [ $? -eq 0 ] then make install 1>/dev/null 2>&1 if [ $? -ne 0 ] then make clean 1>/dev/null 2>&1 fi else make clean 1>/dev/null 2>&1 fi fi fi # install freetype if [ ! -d /usr/src/freetype/bin ] then [ -d /usr/src/freetype ] || mkdir /usr/src/freetype 2>/dev/null; [ -d /root/freetype-2.5.4 ] || \ tar -xvf /root/freetype-2.5.4.tar.gz -C /root 1>/dev/null 2>&1; cd /root/freetype-2.5.4; ./configure --prefix=/usr/src/freetype 1>/dev/null 2>&1; if [ $? -eq 0 ] then make 1>/dev/null 2>&1 if [ $? -eq 0 ] then make install 1>/dev/null 2>&1 if [ $? -ne 0 ] then make clean 1>/dev/null 2>&1 fi else make clean 1>/dev/null 2>&1 fi fi fi # install libpng but libpng need zlib zlib-devel rpm -q zlib-devel 1>/dev/null || yum -y install zlib-devel 1>/dev/null 2>&1 if [ ! -d /usr/src/libpng/bin ] then [ -d /usr/src/libpng ] || mkdir /usr/src/libpng 2>/dev/null; [ -d /root/libpng-1.6.20 ] || \ tar -xvf /root/libpng-1.6.20.tar.xz -C /root 1>/dev/null 2>&1; cd /root/libpng-1.6.20 2>/dev/null; ./configure --prefix=/usr/src/libpng 1>/dev/null 2>&1; if [ $? -eq 0 ] then make 1>/dev/null 2>&1 if [ $? -eq 0 ] then make install 1>/dev/null 2>&1 if [ $? -ne 0 ] then make clean 1>/dev/null 2>&1 fi else make clean 1>/dev/null 2>&1 fi fi fi # install fontconfig and fontconfig-devel rpm -q fontconfig-devel 1>/dev/null || yum -y install fontconfig-devel 1>/dev/null 2>&1 # install tiff if [ ! -d /usr/src/tiff/bin ] then [ -d /usr/src/tiff ] || mkdir /usr/src/ltiff 2>/dev/null; [ -d /root/tiff-4.0.3 ] || \ tar -xvf /root/tiff-4.0.3.tar.gz -C /root 1>/dev/null 2>&1; cd /root/tiff-4.0.3 2>/dev/null; ./configure --prefix=/usr/src/tiff 1>/dev/null 2>&1; if [ $? -eq 0 ] then make 1>/dev/null 2>&1 if [ $? -eq 0 ] then make install 1>/dev/null 2>&1 if [ $? -ne 0 ] then make clean 1>/dev/null 2>&1 fi else make clean 1>/dev/null 2>&1 fi fi fi # install jpeg-9a if [ ! -d /usr/src/jpeg/bin ] then [ -d /usr/src/jpeg ] || mkdir /usr/src/jpeg 2>/dev/null; [ -d /root/jpeg-9a ] || \ tar -xvf /root/jpegsrc.v9a.tar.gz -C /root 1>/dev/null 2>&1; cd /root/jpeg-9a 2>/dev/null; ./configure --prefix=/usr/src/jpeg 1>/dev/null 2>&1; if [ $? -eq 0 ] then make 1>/dev/null 2>&1 if [ $? -eq 0 ] then make install 1>/dev/null 2>&1 if [ $? -ne 0 ] then make clean 1>/dev/null 2>&1 fi else make clean 1>/dev/null 2>&1 fi fi fi # install libXpm rpm -q libXpm-devel 1>/dev/null || yum -y install libXpm-devel 1>/dev/null 2>&1 # install libgd if [ ! -d /usr/src/libgd/bin ] then [ -d /usr/src/libgd ] || mkdir /usr/src/libgd 2>/dev/null; [ -d /root/libgd-2.1.0 ] || \ tar -xvf /root/libgd-2.1.0.tar.gz -C /root 1>/dev/null 2>&1; cd /root/libgd-2.1.0 2>/dev/null; ./configure --prefix=/usr/src/libgd \ --with-png=/usr/src/libpng \ --with-tiff=/usr/src/tiff \ --with-vpx=/usr/src/libvpx \ --with-jpeg=/usr/src/jpeg \ --with-freetype=/usr/src/freetype \ --with-fontconfig=/usr/src/freetyp \ --with-xpm=/usr/ --with-zlib=/usr/ 1>/dev/null 2>&1; if [ $? -eq 0 ] then make 1>/dev/null 2>&1 if [ $? -eq 0 ] then make install 1>/dev/null 2>&1 if [ $? -ne 0 ] then make clean 1>/dev/null 2>&1 fi else make clean 1>/dev/null 2>&1 fi fi fi # install php but php need libxml2-devel rpm -q libxml2-devel 1>/dev/null 2>&1 || yum -y install libxml2-devel 1>/dev/null 2>&1 if [ ! -d /usr/src/php/bin ] then [ -d /usr/src/php ] || mkdir /usr/src/php 2>/dev/null; [ -d /root/php-5.6.16 ] || \ tar -xvf /root/php-5.6.16.tar.bz2 -C /root 1>/dev/null 2>&1; cd /root/php-5.6.16 2>/dev/null; ./configure --prefix=/usr/src/php --with-apxs2=/usr/src/apache/bin/apxs \ --with-mysql=/usr/src/mysql/ \ --with-mysqli=/usr/src/mysql/bin/mysql_config 1>/dev/null 2>&1; if [ $? -eq 0 ] then make 1>/dev/null 2>&1 if [ $? -eq 0 ] then make install 1>/dev/null 2>&1 if [ $? -ne 0 ] then make clean 1>/dev/null 2>&1 fi else make clean 1>/dev/null 2>&1 fi fi fi [ -f /usr/src/apache/htdocs/index.php ] || touch /usr/src/apache/htdocs/index.php [ -s /usr/src/apache/htdocs/index.php ] || \ echo -e "<?php\nphpinfo();\n?>">/usr/src/apache/htdocs/index.php /usr/src/apache/bin/apachectl -k stop /usr/src/apache/bin/apachectl -k start #install discuz [ -d /root/discuz ] || mkdir /root/discuz && \ unzip Discuz_X3.2_SC_UTF8.zip -d /root/discuz 1>/dev/null 2>&1 [ -d /usr/src/apache/htdocs/upload ] || \ cp -r /root/discuz/upload /usr/src/apache/htdocs/ chmod -R 755 /usr/src/apache/htdocs/upload 浏览器通过访问http://192.168.91.134/upload/forum.php首次登陆需要安装下 第二次登陆就可以看到论坛界面。不知道为什么插不了图片了。图片就省略。
原创文章,作者:jslijb,如若转载,请注明出处:http://www.178linux.com/13921
评论列表(1条)
太偷懒了,文章能通过不代表这次的文章是一篇合格质量的文章