写一个Linux CentOs7的系统配置初始化的脚本
时间: 2024-05-21 10:10:25 浏览: 107
CentOS系统初始化优化脚本
#!/bin/bash
# 设置主机名
echo "请输入主机名:"
read hostname
hostnamectl set-hostname $hostname
# 设置时区
timedatectl set-timezone Asia/Shanghai
# 安装常用软件
yum -y install net-tools wget vim
# 关闭防火墙
systemctl stop firewalld
systemctl disable firewalld
# 关闭SELinux
sed -i 's/SELINUX=enforcing/SELINUX=disabled/g' /etc/selinux/config
setenforce 0
# 修改SSH端口号
echo "请输入新的SSH端口号:"
read ssh_port
sed -i "s/#Port 22/Port $ssh_port/g" /etc/ssh/sshd_config
systemctl restart sshd
# 添加新用户
echo "请输入新用户的用户名:"
read username
useradd $username
echo "请输入新用户的密码:"
read password
echo $password | passwd $username --stdin
# 设置sudo权限
echo "$username ALL=(ALL) NOPASSWD: ALL" >> /etc/sudoers.d/$username
# 安装常用程序
yum -y install epel-release
yum -y install htop iftop iotop lrzsz tree
# 安装Nginx
yum -y install nginx
systemctl start nginx
systemctl enable nginx
# 安装MySQL
yum -y install mariadb mariadb-server
systemctl start mariadb
systemctl enable mariadb
mysql_secure_installation
# 安装PHP
yum -y install php php-fpm php-mysql
systemctl start php-fpm
systemctl enable php-fpm
# 安装Node.js
curl -sL https://rpm.nodesource.com/setup_14.x | bash -
yum -y install nodejs
# 安装Docker
yum -y install docker
systemctl start docker
systemctl enable docker
echo "系统初始化完成!"
阅读全文