shell脚本一键编译安装discuz

#!/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"
fi
done

 

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 

echo "[Unit]
Description=nginx
After=network.target
[Service]
Type=forking
ExecStart=$systemd_ExecStartpwd
ExecReload=$systemd_ExecStartpwd -s reload
ExecStop=$systemd_ExecStartpwd -s stop
[Install]
WantedBy=multi-user.target" > /usr/lib/systemd/system/nginx.service


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 '/fastcgi_pass 127.0.0.1:9000;/i location ~ \.php$ {\n root html;\n fastcgi_pass 127.0.0.1:9000;\n fastcgi_index index.php;\n fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;\n include fastcgi_params;\n}' nginx.conf

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' nginx.conf


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"
fi
done


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-fpm
After=network.target
[Service]
Type=forking
ExecStart=$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' php-fpm.conf

sed -i '190s/;//g' php-fpm.conf

echo 'export PATH=$PATH:/usr/local/php/sbin/:/usr/local/php/bin/' >> /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"
fi
done


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.0
port=3306
datadir=/data/mysql
user=mysql
skip-name-resolve
long_query_time=2
slow_query_log_file=/data/mysql/mysql-slow.log
expire_logs_days=2
innodb-file-per-table=1
innodb_flush_log_at_trx_commit = 2
log_warnings = 1
max_allowed_packet = 512M
connect_timeout = 60
net_read_timeout = 120

[mysqld_safe]
log-error=/data/mysql/mysqld.log
pid-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=mysqld
After=network.target
[Service]
Type=forking
ExecStart=/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##*/}

echo $programName

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

 

cd $nginx_souecepwd/html/

#wget 'https://gitee.com/Discuz/DiscuzX/releases/download/v3.4-20220811/Discuz_X3.4_SC_UTF8_20220811.zip'

wget 'http://192.168.80.113/Discuz_X3.4_SC_UTF8_20220811.zip'

yum install -y unzip

unzip Discuz_X3.4_SC_UTF8_20220811.zip

mv upload discuz

cd $nginx_souecepwd/html/discuz/

chown -R nobody:nobody config/ data/ uc_client/ uc_server

 

 


#systemctl restart php-fpm.service

##client_max_body_size 20m; #nginx.conf

 

 

 

 

 

#下面是安装phpmyadmin

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实践哥课程编写脚本,,,,本文版权归作者所有,欢迎转载,转载请注明链接,如果文章有写的不足的地方,或者是写得错误的地方,请你一定要指出,因为这样不光是对我写文章的一种促进,也是一份对后面看此文章的人的责任。谢谢

 

shell脚本一键安装discuz - LY龙 - 博客园 (cnblogs.com)

posted @ 2023-02-22 13:57  LY龙  阅读(39)  评论(0编辑  收藏  举报