Linux平台LNMP环境部署

1, Nginx 部署

1.1 脚本一键部署方式,以1.18.0为例

#!/bin/bash
. /etc/init.d/functions
ver='nginx-1.18.0'
# 检查依赖关系
rpm -qa|grep openssl-devel &>/dev/null
if [ $? -eq 0 ];then
    action 'openssl_devel依赖已安装' /bin/false
else
    yum install -y openssl-devel &>/dev/null
    [ $? -eq 0 ] && action '安装openssl-devel is .....' /bin/true || action '安装openssl-devel is .....' /bin/false;exit 
fi

rpm -qa|grep pcre-devel &>/dev/null
if [ $? -eq 0 ];then
    action 'pcre-devel依赖已安装' /bin/false
else
    yum install -y pcre-devel &>/dev/null
    [ $? -eq 0 ] && action '安装pcre-devel is .....' /bin/true || action '安装pcre-devel is .....' /bin/false;exit
fi

# create user for www
if ! id -u www &>/dev/null;then                                                                                                                                         
   useradd -s /sbin/nologin -M www
   action '创建用户www成功!' /bin/true
fi

# 解压缩
cd /root/soft/
test -d $ver && rm -rf $ver;tar xf ${ver}.tar.gz || tar xf ${ver}.tar.gz
cd $ver
./configure --prefix=/usr/local/nginx --user=www --group=www  --with-http_stub_status_module --with-http_ssl_module --with-http_realip_module
[ $? -eq 0 ] && make install
/usr/local/nginx/sbin/nginx
echo '/usr/local/nginx/sbin/nginx' >> /etc/rc.local
ln -s /usr/local/nginx/sbin/nginx /usr/bin/nginx
[ $? -eq 0 ] && action '安装nginx完成!' /bin/true || action '安装nginx失败!' /bin/false

1.2 软件我这里是放在/root/soft目录中

[root@web01 soft]# pwd
/root/soft
[root@web01 soft]# ls
nginx-1.18.0  nginx-1.18.0.tar.gz

1.3 nginx命令常用参数选项

-?,-h         : this help
   -v            : show version and exit
   -V            : show version and configure options then exit
   -t            : test configuration and exit
   -T            : test configuration, dump it and exit
   -q            : suppress non-error messages during configuration testing
   -s signal     : send signal to a master process: stop, quit, reopen, reload
   -p prefix     : set prefix path (default: /usr/local/nginx/)
   -c filename   : set configuration file (default: conf/nginx.conf)
   -g directives : set global directives out of configuration file

1.4 最常用参数

参数功能
-s signal 向主进程发送信号:停止、退出、重新打开、重新加载  
-V(大写) 显示版本和配置选项,然后退出
-t测试配置文件并退出

2, 部署MySQL

2.1 下载mysql二进制软件

2.2 安装代码

#!/bin/sh
BASEDIR='/usr/local/mysql'
MYSQL_VER='mysql-5.7.34-linux-glibc2.12-x86_64'
# define color
RED='\E[31m'
GREEN='\E[32m'
YELLOW='\E[33m'
RES='\033[0m'

. /etc/init.d/functions

[ -e $BASEDIR ] && rm -rf  $BASEDIR;action '删除baseDir is ...' /bin/true
# create user for mysql
if ! id mysql &>/dev/null;then
  useradd -s /sbin/nologin -M mysql
  action '创建mysql用户成功!' /bin/true
else
  action 'mysql用户已存在' /bin/true
fi

# uncompress mysql soft
if [ -e $MYSQL_VER ];then
  action '软件已解压' /bin/true
else
  tar xf ${MYSQL_VER}.tar.gz
  action '解压完成!' /bin/true
fi

# move dir to /usr/local/mysql
mv ${MYSQL_VER} /usr/local/mysql
cd $BASEDIR
mkdir mysql-files
chown mysql:mysql mysql-files
chmod 750 mysql-files

# delete my.cnf
[ -e /etc/my.cnf ]&& rm -f /etc/my.cnf
# init database
bin/mysqld --initialize --user=mysql --basedir=$BASEDIR &>/tmp/mysqlPasswd.txt

# enable ssl
bin/mysql_ssl_rsa_setup --datadir=${BASEDIR}/data &>/dev/unll
[ $? -eq 0 ] && action '开启SSL支持 is ...' /bin/true

# output password
PASS=`grep 'root@localhost' /tmp/mysqlPasswd.txt |awk '{print "您的密码为: "$NF}'`
echo -e "${GREEN}$PASS $RES"

# set environment ver
grep mysql /etc/profile &>/dev/null
[ $? -ne 0 ] && echo "export PATH=${BASEDIR}/bin:$PATH" >>/etc/profile
source /etc/profile
[ ! -e /etc/init.d/mysqld ] && cp support-files/mysql.server /etc/init.d/mysqld
/etc/init.d/mysqld start
chkconfig --add mysqld &>/dev/null

提示: 脚本和软件放在同一目录中执行

请使用source命令执行脚本

创作不易 请尊重他人劳动成果,未经授权禁止转载!
暂无评论

发送评论 编辑评论


				
|´・ω・)ノ
ヾ(≧∇≦*)ゝ
(☆ω☆)
(╯‵□′)╯︵┴─┴
 ̄﹃ ̄
(/ω\)
∠( ᐛ 」∠)_
(๑•̀ㅁ•́ฅ)
→_→
୧(๑•̀⌄•́๑)૭
٩(ˊᗜˋ*)و
(ノ°ο°)ノ
(´இ皿இ`)
⌇●﹏●⌇
(ฅ´ω`ฅ)
(╯°A°)╯︵○○○
φ( ̄∇ ̄o)
ヾ(´・ ・`。)ノ"
( ง ᵒ̌皿ᵒ̌)ง⁼³₌₃
(ó﹏ò。)
Σ(っ °Д °;)っ
( ,,´・ω・)ノ"(´っω・`。)
╮(╯▽╰)╭
o(*////▽////*)q
>﹏<
( ๑´•ω•) "(ㆆᴗㆆ)
😂
😀
😅
😊
🙂
🙃
😌
😍
😘
😜
😝
😏
😒
🙄
😳
😡
😔
😫
😱
😭
💩
👻
🙌
🖕
👍
👫
👬
👭
🌚
🌝
🙈
💊
😶
🙏
🍦
🍉
😣
Source: github.com/k4yt3x/flowerhd
颜文字
Emoji
小恐龙
花!
上一篇
下一篇