以下是一个简化的示例,展示如何在CentOS 7上进行基础配置和安装常用服务(如Redis、Elasticsearch、Kafka和MariaDB)的脚本:
#!/bin/bash
# 更新系统
sudo yum update -y
# 安装必要的工具
sudo yum install -y epel-release
sudo yum install -y wget net-tools telnet tree nmap sysstat lrzsz
# 安装本地YUM源
sudo rpm --import https://www.elrepo.org/RPM-GPG-KEY-elrepo.org
sudo rpm -Uvh https://www.elrepo.org/elrepo-release-7.0-5.el7.elrepo.noarch.rpm
# 安装Redis
sudo yum install -y redis
sudo systemctl start redis
sudo systemctl enable redis
# 安装Elasticsearch
sudo rpm --import https://artifacts.elastic.co/GPG-KEY-elasticsearch
echo '[elasticsearch-7.x]
name=Elasticsearch repository for 7.x packages
baseurl=https://artifacts.elastic.co/packages/7.x/yum
gpgcheck=1
gpgkey=https://artifacts.elastic.co/GPG-KEY-elasticsearch
enabled=1
autorefresh=1
type=rpm-md' | sudo tee /etc/yum.repos.d/elasticsearch.repo
sudo yum install -y elasticsearch
sudo systemctl start elasticsearch
sudo systemctl enable elasticsearch
# 安装Kafka
sudo wget https://packages.confluent.io/rpm/5.5/confluent-oss-5.5.0.rpm
sudo rpm -ivh confluent-oss-5.5.0.rpm
sudo systemctl start kafka
sudo systemctl enable kafka
# 安装MariaDB
sudo yum install -y mariadb-server mariadb
sudo systemctl start mariadb
sudo systemctl enable mariadb
sudo mysql_secure_installation
# 设置防火墙
sudo firewall-cmd --permanent --add-service=http
sudo firewall-cmd --permanent --add-service=https
sudo firewall-cmd --reload
# 设置SELinux为permissive模式(如果需要)
sudo setenforce 0
sudo sed -i 's/^SELINUX=enforcing/SELINUX=permissive/' /etc/selinux/config
# 调整文件描述符限制
echo '* - nofile 65535' | sudo tee -a /etc/security/limits.conf
# 调整系统时间同步
sudo yum install -y ntp
sudo systemctl start ntpd
sudo systemctl enable ntpd
# 输出完成信息
echo "所有服务安装完成。"
这个脚本提供了一个简化的示例,展示了如何在CentOS 7上安装和配置基本的服务。它包括了基础的系统更新、安装必要的工具、配置本地YUM源、安装Redis、Elasticsearch、Kafka和MariaDB,并进行了基本的系统安全设置。这个脚本可以作为开发者构建服务器环境的参考。