#!/bin/bash
nginx_souecepwd=/usr/local/nginx #源碼安裝路徑
cdnginx_configpwd=/usr/local/nginx/conf
systemd_ExecStartpwd=/usr/local/nginx/sbin/nginx
if [ ! -d $nginx_souecepwd ];then
mkdir $nginx_souecepwd
echo =========================開始安裝Nginx===========================
sed -i s/SELINUX=enforcing/\SELINUX=disabled/ /etc/selinux/config #關閉selinux
for nginx_depend_pack in wget gcc pcre pcre-devel zlib zlib-devel;do nginx_depend_result=$(rpm -qa $nginx_depend_pack) if [ -z $nginx_depend_result ];then yum install -y $nginx_depend_pack else echo $nginx_depend_pack is 判斷是否安裝NGINX依賴包OK fidone
nginxdownloadurl=http://192.168.80.113/nginx-1.22.0.tar.gz
cd $nginx_souecepwd
wget $nginxdownloadurl
nginx_targzname=$(echo $nginxdownloadurl | sed s#.*/##)
tar -zxvf $nginx_targzname
dirname=$(echo $nginx_targzname | sed s/.tar.gz//) )
cd $dirname #進入
./configure --prefix=$nginx_souecepwd
make -j4 && make install || exit 1
cp /etc/profile /etc/profile.bak
sed -i $ a export PATH=$PATH:/usr/local/nginx/sbin /etc/profile #注意:這行可能導致配置文件消失 環境變量全無 (之前筆者由于多寫或寫多了一個字符就發生血案0.0)##往/etc/profile文件最后一行添加環境變量 添加環境變量的好處 可以便管理員直接執行“nginx”命令就可以調用Nginx的主程序#
echo [Unit]Description=nginxAfter=network.target[Service]Type=forkingExecStart=$systemd_ExecStartpwdExecReload=$systemd_ExecStartpwd -s reloadExecStop=$systemd_ExecStartpwd -s stop[Install]WantedBy=multi-user.target > /usr/lib/systemd/system/nginx.service #為了使Nginx服務器以systemctl運行
chmod 754 /lib/systemd/system/nginx.service
systemctl start nginx.service
systemctl enable nginx.service
cd $cdnginx_configpwd
cp nginx.conf nginx.conf.bak
sed -i 45s/index index.html index.htm;/ index index.php index.html index.htm ;/g nginx.conf
sed -i 65,71s/#/ /g nginx.conf
sed -i s#/scripts#$document_root#g
source /etc/profile
nginx -t
firewall-cmd --zone=public --add-port=80/tcp --permanent
firewall-cmd --reload
programName=${0##*/}
echo $programName
source /etc/profile $programName
else
echo =========================安裝Nginx失敗已經安裝過Nginx===========================
fi
#下面是編譯PHP安裝
php_souece_pwd=/usr/local/php
cd_php_configpwd=/usr/local/php/etc
phpfpm_systemd_ExecStartpwd=/usr/local/php/sbin/php-fpm
cp_phpconf_ini=/usr/local/php/etc/php-fpm.conf.default
cd_phpconf_ini=usr/local/php/etc/php-fpm.conf
if [ ! -d $php_souece_pwd ];then
mkdir $php_souece_pwd
echo =========================開始安裝php===========================
yum -y install epel-release
for php_depend_pack in gcc gcc-c++ make pcre pcre-devel zlib zlib-devel openssl openssl-devel libxml2 libxml2-devel libcurl libcurl-devel libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel openldap openldap-devel libmcrypt libmcrypt-devel;do php_depend_result=$(rpm -qa $php_depend_pack) if [ -z $php_depend_result ];then yum install -y $php_depend_pack else echo $php_depend_pack is 判斷是否安裝php依賴包OK fidone
phpdownloadurl=http://192.168.80.113/php-5.6.40.tar.gz
cd $php_souece_pwd
wget $phpdownloadurl
php_targz_name=$(echo $phpdownloadurl | sed s#.*/##)
tar -zxvf $php_targz_name
php_dir_name=$(echo $php_targz_name | sed s/.tar.gz//)
cd $php_dir_name
./configure --prefix=/usr/local/php --with-config-file-path=/usr/local/php/etc --enable-ctype --with-mysql=mysqlnd --with-mysqli=mysqlnd --with-freetype-dir --with-jpeg-dir --with-png-dir --with-zlib --with-libxml-dir=/usr --enable-xml --disable-rpath --enable-bcmath --enable-shmop --enable-sysvsem --enable-inline-optimization --with-curl --enable-mbregex --enable-mbstring --with-mcrypt --with-gd --enable-gd-native-ttf --with-openssl --with-mhash --enable-pcntl --enable-sockets --with-ldap-sasl --with-xmlrpc --enable-zip --enable-soap --with-gettext --enable-fpm
#./configure --prefix=/usr/local/php --with-config-file-path=/usr/local/php/etc --enable-ctype --with-mysql=mysqlnd --with-mysqli=mysqlnd --with-freetype-dir --with-jpeg-dir --with-png-dir --with-zlib --with-libxml-dir=/usr --enable-xml --disable-rpath --enable-bcmath --enable-shmop --enable-sysvsem --enable-inline-optimization --with-curl --enable-mbregex --enable-mbstring --with-mcrypt --with-gd --enable-gd-native-ttf --with-openssl --with-mhash --enable-pcntl --enable-sockets --with-ldap-sasl --with-xmlrpc --enable-zip --enable-soap --with-gettext --enable-fpm
#./configure --prefix=/usr/local/php7 --with-config-file-path=/usr/local/php7/etc --with-mhash --with-openssl --with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd --with-zlib --enable-bcmath --enable-gd --with-jpeg --with-freetype --enable-mbstring --enable-ftp --enable-sockets --with-gettext --enable-session --with-curl --enable-fpm --with-fpm-user=php --with-fpm-group=php --enable-pdo -enable-tokenizer --with-zip
make -j4 && make install
cp php.ini-production /usr/local/php/etc/php.ini
echo [Unit]Description=php-fpmAfter=network.target[Service]Type=forkingExecStart=$phpfpm_systemd_ExecStartpwd[Install]WantedBy=multi-user.target > /usr/lib/systemd/system/php-fpm.service
chmod 754 /usr/lib/systemd/system/php-fpm.service
mv /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf
cd $cd_php_configpwd
cp /etc/profile /etc/profile.php
#sed -i 164c listen = 0.0.0.0:9000
sed -i 190s/;//g php-fpm.conf
echo export PATH=$PATH:/usr/local/php/sbin/:/usr/local/php/bin/ >> /etc/profile
source /etc/profile
programName=${0##*/}
echo $programName
source /etc/profile $programName
systemctl start php-fpm.service
systemctl enable php-fpm.service
systemctl restart php-fpm.service
systemctl restart nginx.service
firewall-cmd --zone=public --add-port=9000/tcp --permanent
firewall-cmd --zone=public --add-port=9000/udp --permanent
firewall-cmd --reload
else
echo =========================安裝php失敗已經安裝過php===========================
fi
mysql_souece_pwd=/usr/local/mysql
cd_mysql_cnfmypwd=/usr/local/mysql/etc/my.cnf
data_mysql=/data/mysql
cd_mysqlslow_log=/data/mysql/mysql-slow.log
cp_mysqlmy_conf_ini=
cd_mysqlmy_conf_ini=
if [ ! -d $mysql_souece_pwd ];then
mkdir $mysql_souece_pwd
echo =========================開始安裝mysql===========================
yum -y install epel-release
useradd -s /sbin/nologin mysql
for mysql_depend_pack in gcc gcc-c++ make tar openssl openssl-devel cmake ncurses ncurses-devel;do mysql_depend_result=$(rpm -qa $mysql_depend_pack) if [ -z $mysql_depend_result ];then yum install -y $mysql_depend_pack else echo $mysql_depend_pack is 判斷是否安裝mysql依賴包OK fidone
mysqldownloadurl=http://192.168.80.113/mysql-5.6.39.tar.gz
cd $mysql_souece_pwd
wget $mysqldownloadurl
mysql_targz_name=$(echo $mysqldownloadurl | sed s#.*/##)
tar -zxvf $mysql_targz_name
mysql_dir_name=$(echo $mysql_targz_name | sed s/.tar.gz//)
cd $mysql_dir_name
cmake -DCMAKE_INSTALL_PREFIX=$mysql_souece_pwd -DMYSQL_DATADIR=$data_mysql -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DWITH_EXTRA_CHARSETS:STRING=all -DWITH_DEBUG=0 -DWITH_SSL=yes -DWITH_READLINE=1 -DENABLED_LOCAL_INFILE=1 2>/tmp/aa
make -j4 && make install
cp support-files/mysql.server /etc/init.d/mysqld
chmod a+x /etc/init.d/mysqld
cd $mysql_dir_name
cp my.cnf my.cnf.bak
mkdir /usr/local/mysql/etc
mv my.cnf /usr/local/mysql/etc/my.cnf.bak
rm -rf /usr/local/mysql/my.cnf
mkdir -pv /data
chmod 777 /data
chown -R mysql:mysql /data/
mkdir -pv /data/mysql
chmod 777 /data/mysql
chown -R mysql:mysql /data/mysql
chown -R mysql:mysql /usr/local/mysql/data
chown -R mysql:mysql /usr/local/mysql /data/mysql
echo [mysqld]bind-address=0.0.0.0port=3306datadir=/data/mysqluser=mysqlskip-name-resolvelong_query_time=2slow_query_log_file=/data/mysql/mysql-slow.logexpire_logs_days=2innodb-file-per-table=1innodb_flush_log_at_trx_commit = 2log_warnings = 1max_allowed_packet = 512Mconnect_timeout = 60net_read_timeout = 120
[mysqld_safe]log-error=/data/mysql/mysqld.logpid-file=/data/mysql/mysqld.pid > /usr/local/mysql/etc/my.cnf
chmod 777 /usr/lib/systemd/system/mysqld.service
mkdir /var/lib//mysql
chmod 777 /var/lib//mysql
yum install -y perl-Module-Install
/usr/local/mysql/scripts/mysql_install_db --basedir=/usr/local/mysql --user=mysql --datadir=/data/mysql/
echo [Unit]Description=mysqldAfter=network.target[Service]Type=forkingExecStart=/etc/init.d/mysqld start[Install]WantedBy=multi-user.target > /usr/lib/systemd/system/mysqld.service
chmod 777 /usr/lib/systemd/system/mysqld.service
ln -s /usr/local/mysql/bin/mysql /usr/bin
echo export PATH=$PATH:/usr/local/mysql/bin/ >>/etc/profile
programName=${0##*/}
source /etc/profile $programName
#systemctl daemon-reload
systemctl enable mysqld
systemctl restart mysqld.service
systemctl enable mysqld.service
firewall-cmd --zone=public --add-port=3306/tcp --permanent
firewall-cmd --reload
else
echo =========================安裝mysql失敗已經安裝過mysql===========================
fi
#下面是安裝wordpress
#mysqladmin -h 127.0.0.1 -u root password sjgtest666_SJG
mysql -uroot -h 127.0.0.1
mysql -uroot -h 127.0.0.1 -psjgtest666_SJG
cd /usr/local/src
wget http://192.168.80.113/wordpress-6.0.1-zh_CN.zip
yum install -y unzip
#unzip latest-zh_CN.zip
unzip wordpress-6.0.1-zh_CN
mv wordpress/ /usr/local/nginx/html/
cd /usr/local/nginx/html/wordpress/
cp wp-config-sample.php wp-config.php
sed -i 23c define(DB_NAME, wordpress); /usr/local/nginx/html/wordpress/wp-config.php
sed -i 26c define(DB_USER, wordpress); /usr/local/nginx/html/wordpress/wp-config.php
sed -i 29c define(DB_PASSWORD, sjgtest666_SJG); /usr/local/nginx/html/wordpress/wp-config.php
sed -i 32c define(DB_HOST, 127.0.0.1); /usr/local/nginx/html/wordpress/wp-config.php
#chmod 757 /usr/local/nginx/conf/nginx.conf/wp-content/
chmod 757 /usr/local/nginx/html/wordpress/wp-content/
yum install unzip wget -y
cd /usr/local/nginx/html/
wget http://192.168.80.113/phpMyAdmin-4.8.1-all-languages.zip
unzip phpMyAdmin-4.8.1-all-languages.zip
mv phpMyAdmin-4.8.1-all-languages phpmyadmin4.8.1
cd phpmyadmin4.8.1
cp libraries/config.default.php config.inc.php
sed -i 131c $cfg[Servers][$i][host] = 127.0.0.1; /usr/local/nginx/html/phpmyadmin4.8.1/config.inc.php
sed -i 262c $cfg[Servers][$i][user] = root; /usr/local/nginx/html/phpmyadmin4.8.1/config.inc.php
sed -i 269c $cfg[Servers][$i][password] = sjgtest666_SJG; /usr/local/nginx/html/phpmyadmin4.8.1/config.inc.php
systemctl restart nginx.service
根據51cto實踐哥課程編寫腳本,,,,本文版權歸作者所有,歡迎轉載,轉載請注明鏈接,如果文章有寫的不足的地方,或者是寫得錯誤的地方,請你一定要指出,因為這樣不光是對我寫文章的一種促進,也是一份對后面看此文章的人的責任。愛掏網 - it200.com謝謝
一鍵安裝wordpress - LY龍 - 博客園 (cnblogs.com)