好物优选点击查看详情 京东购买

暂无内容

shell脚本:一键部署网站含内容管理器

真正的小白可操作,让搭建网站一部成功!

环境:

系统:CentOS Linux release 7.9.2009 (Core)

网络:外网通讯良好

安装包下载链接(不用wget,防止版本问题)

https://www.huoshichong.cn/index.php/download.html

具体需要下载的包请看截图:

shell脚本:一键部署网站含内容管理器插图

总共7个包哦

用Scrt或者Xshell连接centos7服务器,将上述7个包上传到/usr/src

然后在root目录下用vim创建如下脚本:

#!/bin/bash #function:install apache mysql php #author:tommypeng 20220701 final version ########################################## if [ "$USER" != "root" ] then echo "错误:非root用户,权限不足!" exit 0 fi ###############防火墙及SElinux############ systemctl stop firewalld && systemctl disable firewalld && echo "防火墙已经关闭" sed -i 's/SELINUX=.*/SELINUX=disabled/g' /etc/selinux/config && echo "关闭selinux" sleep 10 echo "###########清理旧版本###########" rpm -qa | grep mariadb > /root/888.txt rpm -qa | grep mysql >> /root/888.txt PLIST=$(cat /root/888.txt) for PKGNAME in $PLIST do rpm -e --nodeps $PKGNAME && echo "老旧包已经清理完毕" done rm -rf /root/888.txt && echo "临时文件已删除" sleep 8 tarbagp=/usr/src #判断文件是否存在,如果存在就不用下载了 function is_exist() { if [ ! -f $tarbagp/$1 ];then echo "请上传$1到/usr/src" return 2 fi } #Install httpd web server function httpd_install() { if [[ "$1" -eq "1" ]];then cd $tarbagp; #判断文件是否存在 is_exist httpd-2.4.25.tar.gz if [ $? -eq "2" ] ;then echo "请上传httpd-2.4.25.tar.gz到$tarbagp" exit 0 fi if [ $? -eq 0 ];then yum -y install gcc* apr-devel apr-util-devel pcre-devel sleep 10 tar zxvf $tarbagp/httpd-2.4.25.tar.gz -C $tarbagp && cd $tarbagp/httpd-2.4.25 ./configure \ --prefix=/usr/local/httpd \ --enable-so \ --enable-rewrite \ --enable-charset-lite \ --enable-cgi if [ $? -eq 0 ];then make && make install if [ $? -eq 0 ];then echo "#chkconfig:35 85 21" >> /etc/init.d/httpd && echo "http安装成功" fi fi else echo "遇到致命错误,即将退出" exit 1 fi fi } #Install Mysql server function mysql_install(){ if [[ "$1" -eq "2" ]];then cd $tarbagp; #判断文件是否存在 is_exist mysql-5.5.62.tar.gz if [ $? -eq "0" ] ;then ###########安装依赖包############## yum -y install make gcc-c++ cmake bison-devel ncurses-devel perl openssl-devel autoconf ############添加用户及组########### groupadd mysql && useradd mysql -g mysql -M -s /sbin/nologin #########解压安装包########## cd $tarbagp && tar -zxvf mysql-5.5.62.tar.gz && cd mysql-5.5.62 ############开始编译########## cmake \ -DCMAKE_INSTALL_PREFIX=/usr/local/mysql \ -DMYSQL_DATADIR=/usr/local/mysql/data \ -DSYSCONFDIR=/etc \ -DWITH_MYISAM_STORAGE_ENGINE=1 \ -DWITH_INNOBASE_STORAGE_ENGINE=1 \ -DWITH_MEMORY_STORAGE_ENGINE=1 \ -DWITH_READLINE=1 \ -DMYSQL_UNIX_ADDR=/tmp/mysqld.sock \ -DMYSQL_TCP_PORT=3306 \ -DENABLED_LOCAL_INFILE=1 \ -DWITH_PARTITION_STORAGE_ENGINE=1 \ -DEXTRA_CHARSETS=all \ -DDEFAULT_CHARSET=utf8 \ -DDEFAULT_COLLATION=utf8_general_ci ##########开始安装############# make && make install #########账户权限配置########### chown mysql:mysql /usr/local/mysql ###########安全初始化########## yum -y install autoconf && echo "Dumper模块安装成功" cd /usr/local/mysql && ./scripts/mysql_install_db --user=mysql --datadir=/usr/local/mysql/data else echo "请上传mysql-5.5.62.tar.gz到$tarbagp" exit 1 fi fi } ####mysql_conf######### function mysql_conf(){ ############重建my-default.cnf############# cat >> /usr/local/mysql/support-files/my-default.cnf << EOF # Example MySQL config file for medium systems. [client] default-character-set=utf8 #password = your_password port = 3306 socket = /tmp/mysql.sock ##################socket=/var/lib/mysql/mysql.sock [mysqld] character-set-server=utf8 init_connect='SET NAMES utf8 port = 3306 socket = /tmp/mysql.sock skip-external-locking key_buffer_size = 16M max_allowed_packet = 1M table_open_cache = 64 sort_buffer_size = 512K net_buffer_length = 8K read_buffer_size = 256K read_rnd_buffer_size = 512K myisam_sort_buffer_size = 8M character-set-server=utf8 init_connect='SET NAMES utf8' log-bin=mysql-bin binlog_format=mixed server-id = 1 [mysqldump] quick max_allowed_packet = 16M [mysql] no-auto-rehash # Remove the next comment character if you are not familiar with SQL #safe-updates default-character-set=utf8 [myisamchk] key_buffer_size = 20M sort_buffer_size = 20M read_buffer = 2M write_buffer = 2M [mysqlhotcopy] interactive-timeout EOF ############配置文件############# cp /usr/local/mysql/support-files/my-default.cnf /etc/my.cnf ##/usr/local/mysql/support-files/my-default.cnf### cat >> /root/mysql.txt << EOF datadir=/usr/local/mysql/data default-storage-engine=InnoDB lower_case_table_names=1 EOF sed -i '/\[mysqld\]/r /root/mysql.txt' /etc/my.cnf sed -i 's#PATH=\$PATH:\$HOME/bin#PATH=\$PATH:\$HOME/bin:/usr/local/mysql/bin:/usr/local/mysql/lib#g' /root/.bash_profile sleep 10 rm -rf /usr/bin/mysql* source /root/.bash_profile source /root/.bash_profile #############删除临时文件############## rm -rf mysql.txt && echo "临时文件已经删除" ##########启动数据库################ /usr/local/mysql/support-files/mysql.server start && echo "数据库配置成功,并且已启动" ln -s /usr/local/mysql/bin/mysql* /usr/bin && echo "完成,请使用mysql -u root 登录(无密码)" sleep 10 } #install phpex function install_phpex(){ cd $tarbagp; #判断文件是否存在 is_exist libmcrypt-2.5.8.tar.gz if [ $? -ne "0" ] ;then echo "请上传libmcrypt-2.5.8.tar.gz到$tarbagp" exit 0 fi if [ $? -eq 0 ];then yum –y install zlib* libxml2* sleep 10 tar zxvf $tarbagp/libmcrypt-2.5.8.tar.gz -C $tarbagp && cd $tarbagp/libmcrypt-2.5.8 && ./configure if [ $? -eq 0 ];then make && make install if [ $? -eq 0 ];then echo "libmcrypt安装成功" fi else echo "遇到致命错误,即将退出" exit 1 fi fi ################## cd $tarbagp; #判断文件是否存在 is_exist mhash-0.9.9.9.tar.gz if [ $? -ne "0" ] ;then echo "请上传mhash-0.9.9.9.tar.gz到$tarbagp" exit 0 fi if [ $? -eq 0 ];then tar zxvf $tarbagp/mhash-0.9.9.9.tar.gz -C $tarbagp && cd $tarbagp/mhash-0.9.9.9 && ./configure if [ $? -eq 0 ];then make && make install fi if [ $? -eq 0 ];then ln -s /usr/local/lib/libmhash* /usr/lib/ && echo "mhash安装成功" fi else echo "遇到致命错误,即将退出" exit 1 fi ################################ cd $tarbagp; #判断文件是否存在 is_exist mcrypt-2.6.8.tar.gz if [ $? -ne "0" ] ;then echo "请上传mcrypt-2.6.8.tar.gz到$tarbagp" exit 0 fi if [ $? -eq 0 ];then tar zxvf $tarbagp/mcrypt-2.6.8.tar.gz -C $tarbagp && cd $tarbagp/mcrypt-2.6.8 && export LD_LIBRARY_PATH=/usr/local/lib:$LD_LIBRARY_PATH && ./configure if [ $? -eq 0 ];then make && make install if [ $? -eq 0 ];then echo "mcrypt安装成功" fi fi else echo "遇到致命错误,即将退出" exit 14 fi } #Install PHP server function php_install() { yum install -y gcc libxml2 libxml2-devel mysql_conf sleep 15 install_phpex sleep 15 cd $tarbagp if [ ! -f $tarbagp/php-5.5.38.tar.gz ];then echo "请上传php-5.5.38.tar.gz到$tarbagp" exit 1 else if [[ "$1" -eq "3" ]];then tar zxf $tarbagp/php-5.5.38.tar.gz -C $tarbagp && cd $tarbagp/php-5.5.38 sleep 10 #mkdir /usr/local/php5 ./configure \ --prefix=/usr/local/php5 \ --with-mcrypt \ --with-apxs2=/usr/local/httpd/bin/apxs \ --with-mysql=/usr/local/mysql \ --with-mysqli=/usr/local/mysql/bin/mysql_config \ --with-config-file-path=/usr/local/php5 \ --enable-mbstring if [ $? -eq 0 ];then make && make install echo -e "\n\033[32m-----------------------------------------------\033[0m" echo -e "\033[32mThe php Server Install Success !\033[0m" else echo -e "\033[32mThe Make or Make install ERROR,Please Check......" exit 0 fi fi fi } function lamp_config() { if [[ "$1" -eq "4" ]];then sed -i '/ AddType application\/x-gzip .gz .tgz/a\\ AddType application\/x-httpd-php-source .phps' /usr/local/httpd/conf/httpd.conf sed -i '/ AddType application\/x-gzip .gz .tgz/a\\ AddType application\/x-httpd-php .php' /usr/local/httpd/conf/httpd.conf sed -i '/DirectoryIndex/s/index.html/index.php index.html/g' /usr/local/httpd/conf/httpd.conf /usr/local/httpd/bin/apachectl start /usr/local/mysql/support-files/mysql.server start ###echo "AddType application/x-httpd-php .php" >>/usr/local/httpd/conf/httpd.conf echo "ServerName localhost:80" >> /usr/local/httpd/conf/httpd.conf /usr/local/mysql/bin/mysql -u root -e "grant all on *.* to 'youdian'@'%' identified by 'pwd@123';" /usr/local/mysql/bin/mysql -u root -e "flush privileges;" /usr/local/mysql/bin/mysql -u root -e "flush privileges;" #chmod 777 -R /usr/local/httpd/htdocs sleep 5 sed -i 's/#password = your_password/password = your_password/g' /etc/my.cnf IP=$(ip a | grep "inet "|grep "ens33" | awk '{print $2}' | awk -F / '{print $1}') echo "通过如下地址访问 http://$IP/ 数据库已创建用户youdian,密码为pwd@123 " cat >/usr/local/httpd/htdocs/index.php <<EOF <?php phpinfo(); ?> EOF fi } ############cms#### function cms_install(){ if [[ "$1" -eq "5" ]];then if [ ! -f $tarbagp/youdiancms9.3.0.zip ];then echo "请上传youdiancms9.3.0.zip到$tarbagp" exit 1 else rm -rf /usr/local/httpd/htdocs/* cp /usr/src/youdiancms9.3.0.zip /usr/local/httpd/htdocs/ cd /usr/local/httpd/htdocs/ && unzip youdiancms9.3.0.zip && chmod 777 -R /usr/local/httpd/htdocs IP=$(ip a | grep "inet "|grep "ens33" | awk '{print $2}' | awk -F / '{print $1}') echo "通过如下地址访问友点CMS http://$IP/ 数据库默认已创建用户youdian,密码为pwd@123 " fi fi } #select choice PS3="请你选择需要安装的服务,无人值守请按6:" select i in http mysql php config cms all exit do case $i in http) httpd_install 1 ;; mysql) mysql_install 2 ;; php) php_install 3 ;; config) lamp_config 4 ;; cms) cms_install 5 ;; all) httpd_install 1 mysql_install 2 php_install 3 lamp_config 4 cms_install 5 ;; exit) echo "The system exit" exit esac done 

具体操作如下:

shell脚本:一键部署网站含内容管理器插图1

脚本名称可自行定义。

按i键进入编辑模式,右键粘贴脚本文本,最后输入:wq (注意冒号不能丢),回车后就保存好了

sh 66.sh开始运行脚本,无人值守安装请按6。

shell脚本:一键部署网站含内容管理器插图2

等待即可。

安装完成页面会提示数据库账号和密码,以及登录地址,用浏览器打开登录地址完成cms设置。

现在你需要的就是更改网站的内容了,赶紧部署你自己的网站吧!!!

原文链接:https://blog.csdn.net/qq_28608175/article/details/125571434

© 版权声明
THE END
喜欢就支持一下吧
点赞10 分享