Linux centos下编译安装Lnmp shell脚本

2021-01-29 10:59:10 浏览数 (1)

代码语言:javascript复制
#!/bin/bash
repo="/etc/yum.repos.d/CentOS7-Base-163.repo"
if [ ! -e $repo ]; then                 # -e 判断文件存在;参考:Shell if 条件判断文件或目录
yum install -y wget
cd /etc/yum.repos.d/
mkdir bak
mv * bak
#wget http://mirrors.aliyun.com/repo/Centos-7.repo
#wget http://mirrors.aliyun.com/repo/epel-7.repo
                                        # 移动两个文件到 目录
wget http://mirrors.163.com/.help/CentOS7-Base-163.repo
#sed -i  's/$releasever/7/g' /etc/yum.repos.d/CentOS-Base.repo
                                        # yum源没有对应版本包匹配;修改yum为centos7
yum clean all                           # 清除原有缓存
yum makecache                           # 生成新的缓存
                                        # make cache [meɪk]  [kaʃ]  制作 缓存{ka xi}
yum  list                               # 校验yum
cd
else 
echo "yum已经切换"
fi
################## nginx  ##################
aznginx(){
lsnginx=(`find / -name "nginx.conf" | sed "s/ //g"`) # shell 小括号属性是 定义数组变量 lsnginx   它的值是一条命令的执行结果
echo "
nginx 配置文件总个数为:${#lsnginx[*]}
列出 nginx 配置文件"    ${lsnginx[*]}         # [*]  星号列出所有元素, 星号改成1 为指定角标1,含义为第二个元素,默认从0开始
if [ ${#lsnginx[*]} -lt 1 ]                     # -lt 小于; $ 为空,! 非运算; $? 判断上一条命令执行状态,0正常;  参考:linux shell $$,$! 等的特殊用法
then
echo "配置文件为空,正在安装nginx"
yum install -y gcc gcc-c  
yum install -y pcre pcre-devel openssl openssl-devel zlib zlib-devel
useradd -s /bin/false -M nginx
mkdir -p /www/server/nginx/download                                     # 下载目录
mkdir -p /www/server/nginx/18                                           # 安装目录
cd /www/server/nginx/download
#
#wget http://nginx.org/download/nginx-1.18.0.tar.gz
wget http://work.eisc.cn/ruanjian/rpm/lnmp/nginx-1.18.0.tar.gz
tar -zxf nginx-1.18.0.tar.gz
cd nginx-1.18.0
# 编译 安装目录参数 :--prefix
./configure --user=nginx 
--group=nginx 
--prefix=/www/server/nginx/18 
--with-http_v2_module 
--with-http_ssl_module 
--with-http_sub_module 
--with-http_stub_status_module 
--with-http_gzip_static_module 
--with-pcre
make && make install
ln -s /www/server/nginx/18/nginx-1.18.0 /www/server/nginx/18/nginx
                                                    #给nginx-1.12.0创建软链接去掉末尾的版本号
ln -s /www/server/nginx/18/sbin/* /usr/local/sbin/ #创建nginx命令软链接到环境变量
############ 添加支持 php############
firewall-cmd --permanent --add-port=80/tcp
firewall-cmd --permanent --add-port=9000/tcp # 首先放行防火墙端口
firewall-cmd --reload                   # 重启防火墙
mkdir -p /www/wwwroot/html              # web路径
nginxconf="/www/server/nginx/18/conf/nginx.conf"
sed -i "/#/d" $nginxconf ; sed -i "/^$/d" $nginxconf 
cp $nginxconf $nginxconf.backup
                                        # 重点: 修改启动软链,需要写入文件,否则reboot失效无法启动nginx
sed -i "1 apid    /usr/bin/nginx.pid; " $nginxconf
/usr/local/sbin/nginx                   # 启动nginx
NR=`cat -n $nginxconf | grep "error_page" | awk -F" " '{print $1}'` ; echo $NR
sed -i "$NR i  location ~ .php$ { n                         root           /www/wwwroot;  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                 }" $nginxconf
                                                                                        # 修改支持php解析目录位置
NR=`cat -n $nginxconf | grep "root" | grep "html" | awk -F" " 'NR==1{print $1}' | sed "s/ //g" ` ; echo "查找nginx的web目录行号为:" $NR 
sed -i "$NR s/root.*/root  /www/wwwroot;/g" $nginxconf
                                        # 修改web目录
echo "                                                                          # 写入php测试文件
<?php
phpinfo()
?>
" > /www/wwwroot/html/index.php
####################################
cd
nginx -s stop                           # 停止
nginx
nginx -t                                #已经软连接过了
nginx
yum install -y net-tools                # 端口工具包
netstat -ntlp                           # 查看端口
nginx -s reload                         # nginx  重载配置;重启
firewall-cmd --permanent --add-port=80/tcp # 防火墙放行80端口
systemctl restart firewalld
 cat /var/log/nginx/error.log           # nginx 日志
else                                    # 如果想直接结束:exit 与 fi 配合
 echo "nginx.conf存在已经安装nginx"
fi
}
aznginx
################## php7.2 ##################
azphp(){
lsphp=(`find / -name "php.ini" | sed "s/ //g"`) # shell 小括号属性是 定义数组变量 lsnginx   它的值是一条命令的执行结果
echo "
nginx 配置文件总个数为:${#lsphp[*]}
列出 nginx 配置文件"    ${lsphp[*]}     # [*]  星号列出所有元素, 星号改成1 为指定角标1,含义为第二个元素,默认从0开始
if [ ${#lsphp[*]} -lt 1 ]               # -lt 小于; $ 为空,! 非运算; $? 判断上一条命令执行状态,0正常;  参考:linux shell $$,$! 等的特殊用法
then
echo "配置文件为空,正在安装php"
yum install epel-release -y             # 安装扩展包并更新系统内核
yum list
yum -y install wget vim pcre pcre-devel openssl openssl-devel libicu-devel gcc gcc-c   autoconf libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel libxml2 libxml2-devel zlib zlib-devel glibc glibc-devel glib2 glib2-devel ncurses ncurses-devel curl curl-devel krb5-devel libidn libidn-devel openldap openldap-devel nss_ldap jemalloc-devel cmake boost-devel bison automake libevent libevent-devel gd gd-devel libtool* libmcrypt libmcrypt-devel mcrypt mhash libxslt libxslt-devel readline readline-devel gmp gmp-devel libcurl libcurl-devel openjpeg-devel
                                        # 安装php依赖组件(包含Nginx依赖)
downloadPHP="/www/server/php/download"
installPHP="/www/server/php/72"
mkdir -p $downloadPHP
mkdir -p $installPHP                    # 创建下载和安装目录
groupadd www                            # 创建一个 www 的组
useradd -g www www                      # 创建用户www   归属于 www组
yum install -y wget ; yum install -y star
                                        # 安装wget 下载工具和star 解压缩工具
cd $downloadPHP                         # 进入下载目录后下载文件
#wget http://am1.php.net/distributions/php-7.2.1.tar.gz
wget http://work.eisc.cn/ruanjian/rpm/lnmp/php-7.2.1.tar.gz
tar xvf php-7.2.1.tar.gz                # tar -xvf 是解压,-cvf 是创建压缩包
cd php-7.2.1
# 创建用户和组,并下载php安装包解压
cp -frp /usr/lib64/libldap* /usr/lib/  # 复制dap库
#### 编译安装 是一条命令的开始
./configure --prefix=/www/server/php/72 
--with-config-file-path=/www/server/php/72/etc 
--enable-fpm 
--with-fpm-user=www 
--with-fpm-group=www 
--enable-mysqlnd 
--with-mysqli=mysqlnd 
--with-pdo-mysql=mysqlnd 
--enable-mysqlnd-compression-support 
--with-iconv-dir 
--with-freetype-dir 
--with-jpeg-dir 
--with-png-dir 
--with-zlib 
--with-libxml-dir 
--enable-xml 
--disable-rpath 
--enable-bcmath 
--enable-shmop 
--enable-sysvsem 
--enable-inline-optimization 
--with-curl 
--enable-mbregex 
--enable-mbstring 
--enable-intl 
--with-mcrypt 
--with-libmbfl 
--enable-ftp 
--with-gd 
--enable-gd-jis-conv 
--enable-gd-native-ttf 
--with-openssl 
--with-mhash 
--enable-pcntl 
--enable-sockets 
--with-xmlrpc 
--enable-zip 
--enable-soap 
--with-gettext 
--disable-fileinfo 
--enable-opcache 
--with-pear 
--enable-maintainer-zts 
--with-ldap=shared 
--without-gdbm
#### 编译安装 是一条命令结束
make -j 4 && make install                           # 让make -j 4 最多同时进行4个编译命令同时进行
cp php.ini-development $installPHP/etc/php.ini
cp $installPHP/etc/php-fpm.conf.default $installPHP/etc/php-fpm.conf
cp $installPHP/etc/php-fpm.d/www.conf.default $installPHP/etc/php-fpm.d/www.conf
setphpini=`find $installPHP -name "php.ini"`    ; echo $setphpini # 定义一个变量名字为:setphpini他的值为一个 find 查找文件 php.ini 命令返回的结果
cp $setphpini $setphpini.backup                    # 备份,反斜杠,不询问
sed -i "s/expose_php.*/expose_php=off/g" $setphpini
                                                    # sed -i 修改文件,匹配前一个字符串及其后面所有字符串,修改为后一个;  转译特殊字符   $setphpini 是一个文件路径变量
sed -i "s/short_open_tag.*/short_open_tag=ON/g" $setphpini
sed -i "s/max_execution_time.*/max_execution_time=1s/g" $setphpini
                                                    #execution  [ˌɛksəˈkjuʃ(ə)n] 执行
sed -i "s/max_input_time.*/max_input_time=1s/g" $setphpini
sed -i "s/memory_limit.*/memory_limit=128M/g" $setphpini
                                                    #  [ˈmeməri ˈlɪmɪt] 内存限制
sed -i "s/post_max_size.*/post_max_size=30M/g" $setphpini
sed -i "s/date.timezone.*/date.timezone=Asia/Shanghai/g" $setphpini
sed -i "s/memory_limit.*/memory_limit=128M/g" $setphpini
sed -i "s/mbstring.func_overload.*/mbstring.func_overload=2/g" $setphpini
NR=`cat -n $setphpini | grep "mbstring.func_overload" | awk -F" " '{print $1}' | sed "s/ //g"` ; echo $NR
                                                    # 定义行号变量 NR  ; grep匹配字符串所在行, 打印第一列,删除空格
sed -i "$NR aextension = /www/server/php/72/lib/php/extensions/no-debug-zts-20170718/ldap.so" $setphpini
                                                    # 写入一个字符串, 在行 $NR 的  a 下一行写入 、
NR=`cat -n $setphpini | grep "[opcache" | awk -F" " '{print $1}' | sed "s/ //"` ; echo $NR
sed -i "$NR azend_extension=/www/server/php/72/lib/php/extensions/no-debug-zts-20170718/opcache.so" $setphpini 
sed -i "s/opcache.max_accelerated_files.*/opcache.max_accelerated_files=4000/g" $setphpini
                                                    # 缓存
sed -i "s/opcache.revalidate_freq.*/opcache.revalidate_freq=60/g" $setphpini
sed -i "s/opcache.fast_shutdown.*/opcache.fast_shutdown=1/g" $setphpini
sed -i "s/opcache.enable_cli.*/opcache.enable_cli=1/g" $setphpini
sed -i "s/disable_functions.*/disable_functions=passthru,exec,system,chroot,chgrp,chown,shell_exec,proc_open,proc_get_status,popen,ini_alter,ini_restore,dl,openlog,syslog,readlink,symlink,popepassthru/g" $setphpini
 NR=`cat -n $setphpini | grep disable_functions | awk -F" " '{print $1}' | sed "s/ //g"`
sed -i "$NR alisten = /var/run/www/php-cgi.sock " $setphpini
############################
wwwconf=`find $installPHP -name "www.conf" ` ; echo "修改配置文件:"$wwwconf
cp $wwwconf $wwwconf.backup
############################
NR=`cat -n $wwwconf | grep "listen = " | awk -F" " '{print $1}' | sed "s/ //g"`
                                                    # cat -n 查看文件显示行号,  awk 字段处理打印第一列为行号
sed -i "$NR s/listen.*/listen = /var/run/www/php-cgi.sock/g" $wwwconf
                                                    # 获取到行号,sed -i 指定行号的内容进行修改
NR=`cat -n $wwwconf | grep "listen.owner = www" | awk -F" " '{print $1}' | sed "s/ //g"`
sed -i "$NR alisten.owner = www" $wwwconf
                                                    # sed -i 在指定行号$NR的 a  的下一行插入字符串
                                                                                         
NR=`cat -n $wwwconf | grep "listen.group = www" | awk -F" " '{print $1}' | sed "s/ //g"`
sed -i "$NR alisten.group = www"  $wwwconf
NR=`cat -n $wwwconf | grep "listen.mode =" | awk -F" " '{print $1}' | sed "s/ //g"`
sed -i "$NR alisten.mode = 0660" $wwwconf 
NR=`cat -n $wwwconf | grep "listen.allowed_clients" | awk -F" " '{print $1}' | sed "s/ //g"`
sed -i "$NR alisten.allowed_clients = 127.0.0.1" $wwwconf 
NR=`cat -n $wwwconf | grep "listen.backlog" | awk -F" " '{print $1}' | sed "s/ //g"`
sed -i "$NR alisten.backlog = -1" $wwwconf 
NR=`cat -n $wwwconf | grep "pm.max_children =" | awk -F" " '{print $1}' | sed "s/ //g"`
sed -i "$NR s/pm.max_children =.*/pm.max_children = 180/g" $wwwconf 
NR=`cat -n $wwwconf | grep "pm.start_servers =" | awk -F" " '{print $1}' | sed "s/ //g"`
sed -i "$NR s/pm.start_servers =.*/pm.start_servers = 50/g" $wwwconf 
NR=`cat -n $wwwconf | grep "pm.min_spare_servers =" | awk -F" " '{print $1}' | sed "s/ //g"`
sed -i "$NR s/pm.min_spare_servers =.*/pm.min_spare_servers = 50/g" $wwwconf 
NR=`cat -n $wwwconf | grep "pm.max_spare_servers =" | awk -F" " '{print $1}' | sed "s/ //g"`
sed -i "$NR s/pm.max_spare_servers =.*/pm.max_spare_servers = 180/g" $wwwconf 
NR=`cat -n $wwwconf | grep "request_terminate_timeout =" | awk -F" " '{print $1}' | sed "s/ //g"`
sed -i "$NR arequest_terminate_timeout = 120" $wwwconf 
                                                                                # $NR 在制定行,  a 是下一行插入字符串
NR=`cat -n $wwwconf | grep "request_slowlog_timeout =" | awk -F" " '{print $1}' | sed "s/ //g"`
sed -i "$NR arequest_slowlog_timeout = 50" $wwwconf 
NR=`cat -n $wwwconf | grep "slowlog =" | awk -F" " '{print $1}' | sed "s/ //g"` ; 
sed -i "$NR aslowlog = var/log/slow.log" $wwwconf 
mkdir /var/run/www/
chown -R www:www /var/run/www                   # 创建php-cgi.sock存放目录
NR=`cat -n $installPHP/etc/php-fpm.conf | grep "pid =" | awk -F" " '{print $1}' | sed "s/ //g"` ; echo $NR
sed -i "$NR apid = /www/server/php/72/var/run/php-fpm.pid" /www/server/php/72/etc/php-fpm.conf
echo -e "
[Unit]
Description=The PHP FastCGI Process Manager
After=syslog.target network.target
[Service]
Type=simple
PIDFile=$installPHP/var/run/php-fpm.pid
ExecStart=$installPHP/sbin/php-fpm --nodaemonize --fpm-config $installPHP/etc/php-fpm.conf
ExecReload=/bin/kill -USR2 $MAINPID
[Install]
WantedBy=multi-user.target
" > /usr/lib/systemd/system/php-fpm.service
NR=`cat -n /www/server/php/72/etc/php-fpm.d/www.conf | grep "listen =" | awk -F" " '{print $1}' | sed "s/ //g"` ; echo $NR
                                                # grep 匹配字符串所在行,awk -F 指定空格为分隔符,打印第一列
sed -i "$NR s/listen =.*/listen = 127.0.0.1:9000/g" $installPHP/etc/php-fpm.d/www.conf
                                                # 修改配置文件,监听900端口
ln -s /www/server/php/72/bin/php  /usr/bin      # 创建快捷方式,直接使用 php
  systemctl start php-fpm
  systemctl stop php-fpm
  systemctl restart php-fpm
  systemctl reload php-fpm
else 
echo "php.ini 文件存在,已经安装php"
fi
}
azphp
azmariadb(){
lsphp=(`find / -name "mysql.server" | sed "s/ //g"`) # shell 小括号属性是 定义数组变量 lsnginx   它的值是一条命令的执行结果
echo "
nginx 配置文件总个数为:${#lsphp[*]}
列出 nginx 配置文件"    ${lsphp[*]}             # [*]  星号列出所有元素, 星号改成1 为指定角标1,含义为第二个元素,默认从0开始
if [ ${#lsphp[*]} -lt 1 ]                       # -lt 小于; $ 为空,! 非运算; $? 判断上一条命令执行状态,0正常;  参考:linux shell $$,$! 等的特殊用法
then
echo "配置文件为空,正在安装mariadb"
yum install -y openssl openssl-devel ncurses ncurses-devel bison bison-devel jemalloc jemalloc-devel centos-release-scl devtoolset-7  gcc gcc-c  
                                                # 安装gcc等依赖
yum remove cmake -y
ln -s /usr/local/bin/cmake /usr/bin/            # 移除旧版本cmake
cd
wget work.eisc.cn/ruanjian/rpm/lnmp/cmake-3.19.1.tar.gz
tar -xvf cmake-3.19.1.tar.gz                            # cmake版本要高于3.10
cd cmake-3.19.1 
rm -f CMakeCache.txt                                    # 清除历史编译
./bootstrap && gmake && gmake install
/usr/local/bin/cmake --version                  # 查看编译后的cmake版本
# wget https://github.com/libevent/libevent/releases/download/release-2.1.10-stable/libevent-2.1.10-stable.tar.gz
                                                                        # 安装libevent
cd
wget work.eisc.cn/ruanjian/rpm/lnmp/libevent-2.1.10-stable.tar.gz
tar -xvf libevent-2.1.10-stable.tar.gz 
cd tar -xvf libevent-2.1.10-stable
./configure --prefix=/usr --disable-static && make && make install
yum install -y centos-release-scl devtoolset-7 # 安装C  高版本
gcc --version
scl enable devtoolset-7 bash & echo " 单个 & 符号并列执行 后面的命令"                               
### 使用新版本 gcc 重启失效 ###
gcc --version 
echo "后面的命令没有scl 那样要求中断,所以得到了继续执行"
cd  
wget http://work.eisc.cn/ruanjian/rpm/lnmp/mariadb-10.5.8.tar.gz
# https://downloads.mariadb.org/                                # 官网镜像
tar -zxvf mariadb-10.5.8.tar.gz
cd mariadb-10.5.8
sed -i "s/MYSQL_VERSION_MAJOR.*/MYSQL_VERSION_MAJOR=101/g" VERSION
                                                                # 修改版本号
sed -i "s/MYSQL_VERSION_MINOR.*/MYSQL_VERSION_MINOR=42/g" VERSION 
sed -i "s/MYSQL_VERSION_PATCH.*/MYSQL_VERSION_PATCH=63/g" VERSION 
groupadd -g 41 mysql && useradd -c "MySQL Server" -d /srv/mysql -g mysql -s /bin/false -u 41 mysql
                                                                                # 为mariadb创建用户组和用户
# sed -i "s@data/test@${INSTALL_MYSQLTESTDIR}@g" sql/CMakeLists.txt  && mkdir build && cd    build
cmake -DCMAKE_BUILD_TYPE=Release                      
      -DCMAKE_INSTALL_PREFIX=/usr                     
      -DINSTALL_DOCDIR=share/doc/mariadb-10.5.8       
      -DINSTALL_DOCREADMEDIR=share/doc/mariadb-10.5.8 
      -DINSTALL_MANDIR=share/man                      
      -DINSTALL_MYSQLSHAREDIR=share/mysql             
      -DINSTALL_MYSQLTESTDIR=share/mysql/test         
      -DINSTALL_PLUGINDIR=lib/mysql/plugin            
      -DINSTALL_SBINDIR=sbin                          
      -DINSTALL_SCRIPTDIR=bin                         
      -DINSTALL_SQLBENCHDIR=share/mysql/bench         
      -DINSTALL_SUPPORTFILESDIR=share/mysql           
      -DMYSQL_DATADIR=/srv/mysql                      
      -DMYSQL_UNIX_ADDR=/run/mysqld/mysqld.sock       
      -DWITH_EXTRA_CHARSETS=complex                   
      -DWITH_EMBEDDED_SERVER=ON                       
      -DSKIP_TESTS=ON                                 
      -DTOKUDB_OK=0                       
make && make install
:<<!                                                            # 多行注释
-DCMAKE_INSTALL_PREFIX=                                 指向mysql安装目录
-DINSTALL_SBINDIR=sbin                          指向可执行文件目录(prefix/sbin)
-DMYSQL_DATADIR=/var/lib/mysql          指向mysql数据文件目录(/var/lib/mysql)
-DSYSCONFDIR=/etc/mysql                                 指向mysql配置文件目录(/etc/mysql)
-DINSTALL_PLUGINDIR=lib/mysql/plugin    指向插件目(prefix/lib/mysql/plugin)
-DINSTALL_MANDIR=share/man                      指向man文档目录(prefix/share/man)
-DINSTALL_SHAREDIR=share                        指向aclocal/mysql.m4安装目录(prefix/share)
-DINSTALL_LIBDIR=lib/mysql                      指向对象代码库目录(prefix/lib/mysql)
-DINSTALL_INCLUDEDIR=include/mysql      指向头文件目录(prefix/include/mysql)
-DINSTALL_INFODIR=share/info                    指向info文档存放目录(prefix/share/info)
prefix官方推荐设为/usr
!
install -v -dm 755 /etc/mysql                                   # 创建文件/etc/mysql/my.cnf
cat > /etc/mysql/my.cnf << "EOF"
# Begin /etc/mysql/my.cnf
# The following options will be passed to all MySQL clients
[client]
#password       = your_password
port            = 3306
socket          = /run/mysqld/mysqld.sock
# The MySQL server
[mysqld]
init-connect='SET NAMES utf8'  
character-set-server = utf8
port            = 3306
socket          = /run/mysqld/mysqld.sock
datadir         = /srv/mysql
skip-external-locking
key_buffer_size = 16M
max_allowed_packet = 1M
sort_buffer_size = 512K
net_buffer_length = 16K
myisam_sort_buffer_size = 8M
# Don't listen on a TCP/IP port at all.
#skip-networking
# 注意此处 skip 打开会导致 3306端口异常
# required unique id between 1 and 2^32 - 1
server-id       = 1
# Uncomment the following if you are using BDB tables
#bdb_cache_size = 4M
#bdb_max_lock = 10000
# InnoDB tables are now used by default
innodb_data_home_dir = /srv/mysql
innodb_log_group_home_dir = /srv/mysql
# All the innodb_xxx values below are the default ones:
innodb_data_file_path = ibdata1:12M:autoextend
# You can set .._buffer_pool_size up to 50 - 80 %
# of RAM but beware of setting memory usage too high
innodb_buffer_pool_size = 128M
innodb_log_file_size = 48M
innodb_log_buffer_size = 16M
innodb_flush_log_at_trx_commit = 1
innodb_lock_wait_timeout = 50
[mysqldump]
quick
max_allowed_packet = 16M
[mysql]
no-auto-rehash
# Remove the next comment character if you are not familiar with SQL
#safe-updates
[isamchk]
key_buffer = 20M
sort_buffer_size = 20M
read_buffer = 2M
write_buffer = 2M
[myisamchk]
key_buffer_size = 20M
sort_buffer_size = 20M
read_buffer = 2M
write_buffer = 2M
[mysqlhotcopy]
interactive-timeout
# End /etc/mysql/my.cnf
EOF
:<<!
cd /usr/bin
mv mysql_install_db mysql_install_db_bak
cp /root/mysql_install_db /usr/bin
!
mysql_install_db --basedir=/usr --datadir=/srv/mysql --user=mysql &&
chown -R mysql:mysql /srv/mysql                         # 初始化数据库以及修改所有者权限
cp /root/mariadb-10.5.8/support-files/mysql.server /etc/init.d/mysqld
 chmod  x /etc/init.d/mysqld
 # update-rc.d mysqld defaults
 chkconfig --add mysqld
 /etc/init.d/mysqld restart
 systemctl status mysqld
'/usr/bin/mysqladmin' -u root password 'root'           # 为mysql 设置密码
#mysql                                                  # 登录,默认没有密码
mysql -e "set password = password('WWWeisccn')"         # 为root 用户设置密码
mysql -uroot -pWWWeisccn -e "create database eisc character set utf8 collate utf8_bin;"
                                                        # 登录数据库并且创建数据库名字为
##################################################################################################################################
####  防火墙配置  ####
systemctl restart firewalld
firewall-cmd --permanent --add-port=3306/tcp            # 开放端口 3306
firewall-cmd --permanent --add-port=9000/tcp
firewall-cmd --permanent --add-port=80/tcp
systemctl restart firewalld                             # 重启防火墙
firewall-cmd --zone=public --list-ports                 # 列出防火墙已经开放的端口
netstat -ntlp                                           # 监听运行中的端口运用
####  自动启动配置  ####
#说明:编译安装的运用reboot 后不会自动启动,所以需要加入开机启动配置文件 /etc/rc.d/rc.local
echo "
source /etc/profile
bash /www/server/StartLnmp.sh
" >> /etc/rc.d/rc.local
chmod  x /etc/rc.d/rc.local

echo "
nginx
systemctl restart php-fpm
/etc/init.d/mysqld restart
echo '   LNMP 启动时间 ==========>> `date`' >> /root/LNMPlog.txt
" >> /www/server/StartLnmp.sh
##################################################################################################################################
else
echo "数据库已经安装"
fi
}
azmariadb
## 一键执行脚本: wget eisc.cn/file/shell/centos-LNMP.sh ; sh centos-LNMP.sh

0 人点赞