文件名:auto_vhost.sh

#lnmp自动创建vhost
auto_vhost (){
    check_expect
    git_pull $2 $3 $4
   /usr/bin/expect<<EOF

    set timeout 30

    spawn  sudo lnmp vhost add

    expect     {

        "Please enter domain"       { send    "${1}\n";  exp_continue }
        "Enter more domain name"   { send    "\n"; exp_continue }
        "Default directory:"    { send    "${2}\n";  exp_continue }
        "Allow Rewrite rule?"             { send    "y\n";  exp_continue }
        "Default rewrite: other)"             { send    "thinkphp\n";  exp_continue }
        "Enable PHP Pathinfo?"             { send    "y\n";  exp_continue }
        "Allow access log?"             { send    "y\n";  exp_continue }
        "Enter access log filename("             { send    "\n";  exp_continue }
        "Enter your choice ("             { send    "11\n";  exp_continue }
        "Create database and"             { send    "n\n";  exp_continue }
        "Add SSL Certificate"             { send    "n\n\n";  exp_continue }
    }

EOF
}
git_pull(){
#!/bin/bash
git clone -b master_pdvm_20210331 git@gitee.com:shaue/pdvm-php-v2.git  $1
cp $2 ${1}/.env
sed -i "s/dev_pdvm/${3}/g" $1/.env 
}
check_expect(){
 if [ ! -e “/usr/bin/expect” ]
then
sudo yum -y install expect >/dev/null
else
“已经安装”
fi
}

auto_vhost $1 $2 $3 $4

php调用:exec(‘./auto_vhost.sh www.test.com /home/www/test /var/www/backend_dev_shaue/.env bc’);

第一个参数$1 :vhost的新域名 ; 第二个参数$2:创建的vhost的根目录 ; 第三个参数$3:拷贝.env的根目录;第四个参数$4: .env修改的新数据库名称(原来的名称是dev_pdvm)

liunx执行命令:

./auto_vhost.sh www.new_ceshi.com /home/www/new_ceshi /home/www/backend_aq/.env new_ceshi

注意:如果 lnmp 的创建账户是root,而当前执行lnmp命令的用户 是www,则需要给www用户加上sudo权限,最好可免密码执行脚本。 也可以在一开始就用www账户去安装lnmp环境。 否则报错:www is not in the sudoers file. This incident will be reported.

1.切换到root用户下:

su root

2.添加sudo文件的写权限:
chmod u+w /etc/sudoers

3.编辑sudoers文件:
vi /etc/sudoers
找到这行 root ALL=(ALL) ALL,在他下面添加xxx ALL=(ALL) ALL (这里的xxx是你的用户名)

ps:这里说下你可以sudoers添加下面四行中任意一条,建议用第四条
www            ALL=(ALL)                ALL
%www           ALL=(ALL)                ALL
www            ALL=(ALL)                NOPASSWD: ALL
%www           ALL=(ALL)                NOPASSWD: ALL

第一行:允许用户www执行sudo命令(需要输入密码).
第二行:允许用户组www里面的用户执行sudo命令(需要输入密码).
第三行:允许用户www执行sudo命令,并且在执行的时候不输入密码.
第四行:允许用户组www里面的用户执行sudo命令,并且在执行的时候不输入密码.

4.撤销sudoers文件写权限:
chmod u-w /etc/sudoers

自动生成密钥对并发送给其他服务器

原文链接:https://blog.csdn.net/Operations_white/article/details/104576620

发表评论

电子邮件地址不会被公开。 必填项已用*标注