首页 > 系统相关 >初始化centos环境脚本

初始化centos环境脚本

时间:2022-10-31 15:23:35浏览次数:50  
标签:脚本 初始化 node centos -- redis etc docker data

#! /bin/bash
echo "java环境初始化开始"
#功能描述: Centos8.5系统自动初始化脚本
#自动配置:IP地址\Yum源\docer\docker-compose v2.7.0\ZSH\Portainer\Cockpit\zabbix-agent2\chronyd
#脚本执行方法
#  1.刚安装完的系统最好重启一下, 如果是虚拟机的一定要重启!!! 
#  2.删除所有#开头的注释, vim打开本文件光标停在首行并执行"set ff=unix"回车一直过滤到最后一行,保存退出!
#  3.执行命令"bash 01Auto_default_v1.5.sh"
#程序: 01Auto_default_v1.5.sh
#日期: 2022-8-25
#制作人: zl

#配置网卡IP地址
#nmcli con modify eth0 connection.autoconnect yes
#nmcli con modify eth0 ipv4.address 192.168.1.7/24
#nmcli con modify eth0 ipv4.method manual
#nmcli con modify eth0 ipv4.gateway 192.168.1.1
#nmcli con modify eth0 ipv4.dns "114.114.114.114 8.8.8.8"
#nmcli c reload
#nmcli c down eth0
#nmcli c up eth0
#nmcli d reapply eth0
#systemctl restart NetworkManager

#配置sshd和修改端口号为2538并添加进selinux和firewalld中
echo "Port 22">>/etc/ssh/sshd_config
echo "Port 8338">>/etc/ssh/sshd_config
echo "ListenAddress 0.0.0.0:22">>/etc/ssh/sshd_config
echo "ListenAddress 0.0.0.0:2538">>/etc/ssh/sshd_config
echo "Protocol 2">>/etc/ssh/sshd_config
echo "HostKey /etc/ssh/ssh_host_rsa_key">>/etc/ssh/sshd_config
echo "PermitRootLogin yes">>/etc/ssh/sshd_config
echo "StrictModes yes">>/etc/ssh/sshd_config
echo "MaxAuthTries 5">>/etc/ssh/sshd_config
echo "MaxSessions 3">>/etc/ssh/sshd_config
echo "PasswordAuthentication yes">>/etc/ssh/sshd_config
echo "AllowUsers root baiinfo">>/etc/ssh/sshd_config
echo "PermitEmptyPasswords no">>/etc/ssh/sshd_config
dnf install policycoreutils-python-utils
semanage port -a -t ssh_port_t -p tcp 2538
systemctl restart sshd
firewall-cmd --permanent --add-port=2538/tcp --zone=public
firewall-cmd --reload

#配置dnf源, 可以自行更换为阿里等公共源, 这里用的是私Yum库
mkdir -p /etc/yum.repos.d/backup && mv /etc/yum.repos.d/*.repo /etc/yum.repos.d/backup
curl http://192.168.1.139:22538/os/x86_64/centos8.repo -o /etc/yum.repos.d/centos8.repo
dnf clean all && dnf makecache
dnf install -y mtr vim bash-completion

#配置docker和docker-compose
dnf erase -y podman buildah
dnf remove docker*
rm -fr /var/lib/docker/
dnf config-manager --add-repo=https://download.docker.com/linux/centos/docker-ce.repo
systemctl daemon-reload
dnf clean all && dnf makecache
dnf install -y docker-ce
systemctl start docker
systemctl enable docker
curl -L https://get.daocloud.io/docker/compose/releases/download/v2.7.0/docker-compose-`uname -s`-`uname -m` > /usr/local/bin/docker-compose
chmod +x /usr/local/bin/docker-compose
ln -s /usr/local/bin/docker-compose /usr/bin/docker-compose
#docker-compose version && docker version
cat >/etc/docker/daemon.json<<DD
{
  "log-driver":"json-file",
  "log-opts": {"max-size":"500m", "max-file":"2"},
  "bip":"10.10.136.1/24"
}
DD
systemctl daemon-reload
systemctl restart docker

#配置Portainer管理器, 访问URL: https://local_ip:9443
docker image load -i ./Portainer-CN/6053537portainer-celatest.tar
#docker pull 6053537/portainer-ce (在线安装方式)
mkdir -p /data/Portainer_data/
docker run -d -p 8000:8000 -p 9443:9443 --name portainer \
    --restart=always \
    -v /var/run/docker.sock:/var/run/docker.sock \
    -v /data/Portainer_data/:/data \
    6053537/portainer-ce

#配置cockpit系统运维工具,访问URL: https://local_IP:9090
dnf install -y cockpit
systemctl enable --now cockpit.socket
firewall-cmd --permanent --zone=public --add-service=cockpit
firewall-cmd --reload

#配置Zabbix-Agent端, Zabbix服务端为192.168.25.38, 如果有server=127.0.0.1一定要注销
rpm -ivh ./zabbix/zabbix-agent-6.2.3-release1.el8.x86_64.rpm
sed -i '/Server=/d' /etc/zabbix/zabbix_agentd.conf
sed -i '/ServerActive=/d' /etc/zabbix/zabbix_agentd.conf 
sed -i '/Hostname=/d' /etc/zabbix/zabbix_agentd.conf
echo "Server=192.168.25.38">>/etc/zabbix/zabbix_agentd.conf 
echo "Hostname=$(hostname)">>/etc/zabbix/zabbix_agentd.conf
systemctl enable --now zabbix-agent
firewall-cmd --zone=public --add-port=10050/tcp --permanent
firewall-cmd --reload
usermod -a -G docker zabbix
systemctl restart zabbix-agent

#配置时钟服务器为192.168.25.38
sed -i 's/pool 2.centos.pool.ntp.org iburst/server 192.168.25.38 iburst/g' /etc/chrony.conf
systemctl restart chronyd.service

# 安装Java环境
yum install -y java-1.8.0-openjdk
echo "export JAVA_HOME=/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.312.b07-1.el8_4.x86_64/">>/etc/profile
echo "export CLASSPATH=.:$JAVA_HOME/jre/lib/rt.jar:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar">>/etc/profile
echo "export PATH=$PATH:$JAVA_HOME/bin">>/etc/profile
source /etc/profile

# 安装nexus3正式仓库 (用于正式环境java项目被引用jar的存放,需审核无误后上传至该仓库中)
# 第一次登录要改admin密码,初始化密码在nexus容器/nexus-data/admin.password
# 修改admin密码后,选择Disable anonymous access,防止游客访问
yum install -y maven
mkdir -p /data/nexus-data && chmod -R 777 /data/nexus-data
mkdir -p /data/software/nexus
docker image load -i ./nexus3/nexus3.tar.gz
cat >/data/software/nexus/docker-compose.yml<<DD
version: '3.1'
services:
  nexus3:
    image: sonatype/nexus3:3.36.0
    restart: always
    container_name: nexus
    network_mode: host 
    ports:
      - 28081:8081
      - 28082:8082
    volumes:
      - /data/nexus-data:/nexus-data
DD
firewall-cmd --permanent --add-port=28081/tcp && \
firewall-cmd --permanent --add-port=28082/tcp && \
firewall-cmd --reload

# 导入MySql8,密码为:1+1=2.abcd1234(注意引用时加''或转义字符\)
mkdir -p /data/mysql/{data,conf,logs}
mkdir -p /data/software/mysql/
docker image load -i ./mysql8/mysql8.tar.gz
cat >/data/software/mysql/docker-compose.yml<<DD
version: '3.1'
services:
  db:
    image: mysql:8
    restart: always
    container_name: bi-mysql8
    network_mode: host   
    environment:
      MYSQL_ROOT_PASSWORD: 1+1=2.abcd1234
    command:
      --default-authentication-plugin=mysql_native_password
      --character-set-server=utf8mb4
      --collation-server=utf8mb4_general_ci
      --explicit_defaults_for_timestamp=true
      --lower_case_table_names=1
    volumes:
      - /data/mysql/data:/var/lib/mysql
      - /data/mysql/conf:/etc/mysql/conf.d
      - /data/mysql/logs:/logs
DD

# NACOS镜像
mkdir -p /data/software/nscos
docker image load -i ./nacos/nacos-server.tar.gz

# nginx1.23.1镜像
mkdir -p /data/nginx/{data,conf,logs}
mkdir -p /data/software/nginx/
docker image load -i ./nginx/nginx.tar.gz
cat >/data/nginx/conf/nginx_conf<<DD
upstream baiinfo_cluster {
    server 192.168.10.34;
    server 192.168.10.35;
}
server {
    listen       80;
    server_name  localhost;
    access_log  /wwwlogs/access.log  main;
    error_log /wwwlogs/error.log;
    location / {
        proxy_pass http://dsj.baiinfo.com;
        proxy_set_header Host $host:$server_port;
        }
}
DD
cat >/data/software/nginx/docker-compose.yml<<DD
version: '3.1'
services:
  nginx:
    restart: always
    container_name: nginx
    network_mode: host 
    image: nginx
    ports:
      - 80:80
    volumes:
      - /data/nginx/data:/usr/share/nginx/html
      - /data/nginx/logs:/wwwlogs
      - /data/nginx/conf/nginx_conf:/etc/nginx/conf.d/default.conf
    privileged: true
DD
firewall-cmd --permanent --add-port=80/tcp && \
firewall-cmd --reload

# skywalking监控(单节点)镜像, URL: 192.168.10.35:18082
mkdir -p /data/elasticsearch/data
chmod -R 777 /data/elasticsearch/data
mkdir -p /data/software/skywalking
docker image load -i ./skywalking/elasticsearch.tar.gz
docker image load -i ./skywalking/skywalking-oap-server.tar.gz
docker image load -i ./skywalking/skywalking-ui.tar.gz

# minio(多节点)镜像, 访问URL:http://local_IP:9001
mkdir -p /data/software/minio
docker image load -i ./minio/minio.tar.gz

# redis集群(cluster)镜像
mkdir -p /data/software/redis
mkdir -p /data/redis/share/redis-node-{1,2,3,4}
mkdir -p /data/redis/conf
mkdir -p /data/redis/logs
touch /data/redis/logs/redis-node-{1,2,3,4}-log.txt
chmod -R 777 /data/redis/logs
docker image load -i ./redis7/redis7.tar.gz
cat >/data/software/redis/docker-compose.yml<<DD
version: '3.1'
services:
DD
for port in $(seq 1 4)
do
cat >/data/redis/conf/redis-node-${port}.conf<<DD
protected-mode no
bind 0.0.0.0
port 638${port}
cluster-enabled yes 
appendonly yes 
logfile "/logs/redis-node-${port}-log.txt"
requirepass bai_redis_2538 
masterauth bai_redis_2538
DD
cat >>/data/software/redis/docker-compose.yml<<DD
  redis-node-${port}:
    image: redis:latest
    restart: always
    network_mode: host
    container_name: redis-node-${port}
    privileged: true
    ports:
      - 638${port}:638${port}
    environment:
      TZ: Asia/Shanghai
    volumes:
      - /data/redis/share/redis-node-${port}:/data
      - /data/redis/conf/redis-node-${port}.conf:/etc/redis/redis.conf
      - /data/redis/logs:/logs
    command: ["redis-server","/etc/redis/redis.conf"]
DD
done
firewall-cmd --permanent --add-port=6381-6384/tcp && \
firewall-cmd --permanent --add-port=16381-16384/tcp && \
firewall-cmd --reload

# elasticsearch集群(cluster) 
docker image load -i ./es7/elasticsearch_7.1.0.tar.gz
mkdir -p /data/es-cluster/node/data4
mkdir -p /data/es-cluster/node/config4
mkdir -p /data/es-cluster/node/logs4
mkdir -p /data/es-cluster/node/plugins4
chmod 777 -R /data/es-cluster
# 写入es节点配文件, 需要手动修改节点配置
cat >/data/es-cluster/node/config3/es.yml<<DD
# 设置集群名称,集群内所有节点的名称必须一致
cluster.name: baiinfo-es-cluster
# 设置节点名称,集群内节点名称必须唯一
node.name: node3
# 表示该节点会不会作为主节点,true表示会;false表示不会
node.master: true
# 当前节点是否用于存储数据,是:true、否:false
node.data: true
# 监听地址,用于访问该es
network.host: 0.0.0.0
# 发布地址,一个单一地址,用于通知集群中的其他节点
network.publish_host: 192.168.10.36
# es对外提供的http端口,默认 9200
http.port: 9200
# TCP的默认监听端口,默认 9300
transport.tcp.port: 9300
# 集群中的节点可以有N个有master资格的节点: 默认为1,对于大的集群来说,可以设置大一点的值(2-4)
discovery.zen.minimum_master_nodes: 1
# 写入候选主节点的设备地址,在开启服务后可以被选为主节点
discovery.seed_hosts: ["192.168.10.35:9300", "192.168.10.35:9301","192.168.10.34:9300","192.168.10.36:9300","192.168.10.37"]
discovery.zen.fd.ping_timeout: 1m
discovery.zen.fd.ping_retries: 5
# 初始化一个新的集群时需要此配置来选举master
cluster.initial_master_nodes: ["node1", "node2","node3"]
xpack.security.enabled: true
xpack.security.transport.ssl.enabled: true
xpack.security.transport.ssl.keystore.type: PKCS12
xpack.security.transport.ssl.verification_mode: certificate
xpack.security.transport.ssl.keystore.path: elastic-certificates.p12
xpack.security.transport.ssl.truststore.path: elastic-certificates.p12
xpack.security.transport.ssl.truststore.type: PKCS12
xpack.security.audit.enabled: true
DD
firewall-cmd --permanent --add-port=9200/tcp && \
firewall-cmd --permanent --add-port=9300/tcp && \
firewall-cmd --reload
echo "vm.max_map_count=262144">>/etc/sysctl.conf
sysctl -p
# 写入es节点启动文件, 需要手动修改节点配置
mkdir -p /data/software/es-cluster
cat >>/data/software/es-cluster/docker-compose.yml<<DD
version: '3.1'
services:
  es3:
    image: elasticsearch:7.1.0
    restart: always
    network_mode: host
    container_name: baiinfo-es-node3
    privileged: true
    environment:
      - 'ES_JAVA_OPTS=-Xms6144m -Xmx6144m'
    volumes:
      - /data/es-cluster/node/config3/es.yml:/usr/share/elasticsearch/config/elasticsearch.yml
      - /data/es-cluster/node/data3:/usr/share/elasticsearch/data
      - /data/es-cluster/node/plugins3:/usr/share/elasticsearch/plugins
      - /data/es-cluster/node/config3/elastic-certificates.p12:/usr/share/elasticsearch/config/elastic-certificates.p12
DD

# 安装nodejs, 版本node-v14.18.2.tar.gz 
cp ./nodejs/node-v14.18.2-linux-x64.tar.gz /data/software
cd /data/software
tar -zxvf node-v14.18.2-linux-x64.tar.gz
ln -s /data/software/node-v14.18.2-linux-x64/bin/npm /usr/local/bin/
ln -s /data/software/node-v14.18.2-linux-x64/bin/node /usr/local/bin/
ln -s /data/software/node-v14.18.2-linux-x64/bin/npx /usr/local/bin/
rm node-v14.18.2-linux-x64.tar.gz

#配置ZSH解释器
dnf install -y zsh
cp -a ./oh-my-zsh/ ~/.oh-my-zsh
bash ~/.oh-my-zsh/tools/install.sh
sed -i 's/ZSH_THEME="robbyrussell"/ZSH_THEME\=\"ys\"/g' ~/.zshrc
source ~/.zshrc

标签:脚本,初始化,node,centos,--,redis,etc,docker,data
From: https://www.cnblogs.com/zhaolongisme/p/16844400.html

相关文章

  • CentOS7 linux查看端口号的
    文章目录​​1.查看已开放的端口​​​​firewall-cmd--list-ports​​​​2.查询端口号8080是否开启​​​​firewall-cmd--query-port=8080/tcp​​​​3.开放端口(开放......
  • Windows - Windows 开机运行脚本文件
    Windows开机运行脚本文件 按快捷键win+r,输入gpedit.msc进入本地策略管理器点击windows设置->脚本->(启动/关机),然后双击启动点击添加点击浏览选择你想要......
  • webpack : 无法加载文件 C:\Users\13573\AppData\Roaming\npm\webpack.ps1,因为
    问题:C:\Users\XXX\AppData\Roaming\npm\webpack.ps1因为在此系统上禁止运行脚本管理员输入  set-ExecutionPolicyRemoteSigned  回车输入A或者Y即可解决 ......
  • centos 防火墙开放端口
    centos防火墙开放端口开启防火墙systemctlstartfirewalld开放指定端口firewall-cmd--zone=public--add-port=<PORT>/tcp--permanent命令含义:--zone#作用......
  • 问题:小窗口cmd执行脚本
    问题:小窗口cmd执行脚本描述始终会弹出小黑窗,该怎么“隐藏”窗口解决小至任务栏①exit则是在任务栏里一闪即消失,pause可保留。@echooff%1(start/mincmd.exe/c......
  • centos7通过端口号杀死进程脚本
    #!/bin/sh#Killservicesofportnumber#检查用户是否输入端口号port=$1if[[$port==""]]thenecho"Pleaseinputportnumber!"exit8fi#查看当前端口是否有......
  • frp Linux-centos7、windows 开机自动启动
    一、下载客户端和服务端https://github.com/fatedier/frp/releases二、配置服务端和客户端服务端解压文件夹,配置文件夹中的frps.ini文件#服务端frp配置[common]bind_port=......
  • 构造XSS脚本
    弹窗警告<script>alert('xss')</script><script>alert(document.cookie)</script>页面嵌套<iframesrc=http://www.baidu.comwidth=300height=300></iframe><iframesr......
  • CentOS如何快速安装docker
    centos6.x$sudoyuminstallhttp://mirrors.yun-idc.com/epel/6/i386/epel-release-6-8.noarch.rpm$sudoyuminstalldocker-ioCentOS7.xCentOS7系统CentOS-Extras......
  • Python脚本IMAP登陆邮箱 搜索邮件
    功能:python脚本登陆邮箱查找指定邮件。  代码:#!/usr/bin/envpython#-*-coding:UTF-8-*-##pythontversion:3.8.8#导入模块importimaplib,string......