#!/bin/bash
nginx_install() {
if [ -f /root/nginx-1.18.0.tar.gz ];then
echo "nginx源码包存在,开始解压..."
cd /root && tar xzf nginx-1.18.0.tar.gz
echo "开始安装nginx编译所需环境"
yum -y install gcc pcre-devel openssl-devel > /dev/null
echo "开始检测编译安装nginx"
cd nginx-1.18.0 && ./configure > /dev/null && make > /dev/null && make install > /dev/null
echo "开始修改nginx配置文件"
#修改默认端口
sed -i '36 s/80/8000/' /usr/local/nginx/conf/nginx.conf
#修改连接数
sed -i '13 s/1024/10240/' /usr/local/nginx/conf/nginx.conf
#修改默认首页
sed -i '45 s/index.html/index.php/' /usr/local/nginx/conf/nginx.conf
sed -i '65,71 s/#//' /usr/local/nginx/conf/nginx.conf
sed -i '69 s/\/scripts/$document_root/' /usr/local/nginx/conf/nginx.conf
echo "创建测试页面"
echo "" > /usr/local/nginx/html/index.php
else
echo "nginx源码包不存在,请先上传!!!"
exit
fi
}
mysql_insatll() {
rpm -qa|grep -q mariadb-server
if [ $? -eq 0 ];then
echo "mysql服务已经安装"
else
echo "mysql服务未安装,现在开始安装"
yum -y install mariadb mariadb-server > /dev/null
fi
}
php_install() {
num=$(rpm -qa|grep -c php)
if [ $num -eq 7 ];then
echo "php组件已经全部安装"
else
echo "缺少PHP组件,现在开始安装"
yum -y install php php-mysql php-fpm php-gd > /dev/null
fi
}
start_nginx() {
ss -ntlp|grep -wq 8000
if [ $? -eq 0 ];then
echo "8000端口已经被占用,请查看确认"
else
echo "正在开启nginx服务"
/usr/local/nginx/sbin/nginx
fi
}
start_mysql() {
ss -ntlp|grep -wq 3306
if [ $? -eq 0 ];then
echo "mysql服务已经存在,请查看确认"
else
echo "正在启动mysql服务"
systemctl start mariadb
fi
}
start_php() {
ss -ntlp|grep -wq 9000
if [ $? -eq 0 ];then
echo "php-fpm服务已经存在,请查看确认"
else
echo "正在启动php-fpm服务"
systemctl start php-fpm
fi
}
IP=$(ifconfig |awk '/broadcast/{print $2}')
echo "--------------开始安装nginx---------------"
nginx_install
echo "--------------开始安装mysql---------------"
mysql_insatll
echo "--------------开始安装php-----------------"
php_install
echo "--------------开启nginx服务---------------"
start_nginx
echo "--------------开启mysql服务---------------"
start_mysql
echo "--------------开启php服务-----------------"
start_php
echo "一键部署lnmp脚本已经执行完成,请在浏览器输入 http://$IP:8000 访问测试页面"
[root@host-135 ~]# ./lnmp.sh
--------------开始安装nginx---------------
nginx源码包存在,开始解压...
开始安装nginx编译所需环境
开始检测编译安装nginx
开始修改nginx配置文件
创建测试页面
--------------开始安装mysql---------------
mysql服务未安装,现在开始安装
--------------开始安装php-----------------
缺少PHP组件,现在开始安装
--------------开启nginx服务---------------
正在开启nginx服务
--------------开启mysql服务---------------
正在启动mysql服务
--------------开启php服务-----------------
正在启动php-fpm服务
一键部署lnmp脚本已经执行完成,请在浏览器输入 http://192.168.153.135:8000 访问测试页面
#!/bin/bash
read -p "请输入要创建的用户的个数:" num
for i in `seq 1 $num`
do
id user$i
if [ $? -eq 0 ];then
echo "user$i 用户已经存在"
else
echo "user$i 用户不存在,开始创建并设定密码"
pwd=$(openssl rand -hex 4)
useradd user$i && echo "$pwd" |passwd --stdin user$i
[ -f /root/www.txt ] || touch /root/www.txt
grep -wq user$i /root/www.txt
if [ $? -eq 0 ];then
echo "user$i 用户已经存在于/root/www.txt中"
else
echo "user$i $pwd" >> /root/www.txt
fi
fi
done
[root@host-135 ~]# ./adduser.sh
请输入要创建的用户的个数:5
id: user1: no such user
user1 用户不存在,开始创建并设定密码
Changing password for user user1.
passwd: all authentication tokens updated successfully.
id: user2: no such user
user2 用户不存在,开始创建并设定密码
Changing password for user user2.
passwd: all authentication tokens updated successfully.
id: user3: no such user
user3 用户不存在,开始创建并设定密码
Changing password for user user3.
passwd: all authentication tokens updated successfully.
id: user4: no such user
user4 用户不存在,开始创建并设定密码
Changing password for user user4.
passwd: all authentication tokens updated successfully.
id: user5: no such user
user5 用户不存在,开始创建并设定密码
Changing password for user user5.
passwd: all authentication tokens updated successfully.
[root@host-135 ~]# cat www.txt
user1 88319848
user2 a327cf95
user3 fbc70938
user4 55baa243
user5 96404845
#!/bin/bash
os=$(cat /etc/redhat-release)
cpu_cores=$(grep -c processor /proc/cpuinfo)
mem_total=$(free -h|awk '/Mem/{print $2}')
mem_free=$(free -h|awk '/Mem/{print $4}')
disk_total=$(lsblk |awk '/disk/{print $4}')
disk_use=$(df -h|awk '/root/{
print $(NF-1)}')
ip=$(ifconfig |awk '/broadcast/{
print $2}')
echo "服务器系统版本为:$os"
echo "服务器CPU核心数为:$cpu_cores"
echo "服务器内存总数为:$mem_total"
echo "剩余内存为:$mem_free"
echo "磁盘总大小为:$disk_total"
echo "磁盘使用率为:$disk_use"
echo "网卡ip地址为:$ip"
[root@host-134 ~]# sh system.sh
服务器系统版本为:CentOS Linux release 7.7.1908 (Core)
服务器CPU核心数为:4
服务器内存总数为:1.8G
剩余内存为:1.4G
磁盘总大小为:40G
磁盘使用率为:4%
网卡ip地址为:192.168.153.134
搭建教程链接>> https://blog.csdn.net/m0_46674735/article/details/112971571
参考一键安装LNMP脚本即可
/etc/yum.repos.d/
yum -y install zabbix-agent
创建脚本目录
mkdir /etc/zabbix/scripts
编写nginx.sh脚本
vim /etc/zabbix/scripts/nginx.sh
脚本内容如下
#!/bin/bash
num=$(ps -ef|grep "nginx: master process"|grep -cv grep)
echo $num
给脚本增加执行权限
chmod +x /etc/zabbix/scripts/nginx.sh
vim /etc/zabbix/zabbix_agentd.conf
修改如下四行内容
117 Server=192.168.153.139 #zabbix-server的ip地址
158 ServerActive=192.168.153.139 #zabbix-server的ip地址
328 UnsafeUserParameters=1 # 开启自定义监控项
337 UserParameter=nginx.status,/etc/zabbix/scripts/nginx.sh
systemctl start zabbix-agent
yum -y install zabbix-get
[root@host-139 ~]# zabbix_get -s 192.168.153.135 -k nginx.status
1
/usr/lib/zabbix/alertscripts
目录下,并增加执行权限/usr/local/nginx/sbin/nginx -s stop