centos7新服务器初始化配置、安装nginx、pg

背景:新安装的centos系统,需要进行初始化配置、关闭防火墙、修改主机名、新建用户、安装nginx等操作,故编写此脚本
注意:本文仅供参考

vim newnode.sh

#!/bin/bash
pg_passwd=password
#修改句柄数
sed -i '$a * soft nofile 100000' /etc/security/limits.conf
sed -i '$a * hard nofile 100000' /etc/security/limits.conf
#关闭防火墙
systemctl stop firewalld.service
systemctl disable firewalld.service
#关闭selinux
sed -i 's/SELINUX=enforcing/SELINUX=disabled/g' /etc/selinux/config
#修改主机名
read -p '请输入主机名: ' name
hostnamectl set-hostname $name
hostname
#更新系统
yum -y update
#修改镜像为阿里云地址
mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.bak
wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
#重新生成缓存
yum makecache
#创建用户test,密码为password
useradd test && echo "password" | passwd --stdin test
#用户授权
sed -i "101a test    ALL=(ALL)       NOPASSWD: \/usr\/bin\/jps,\/bin\/kill,\/bin\/sh,\/bin\/bash,\/usr\/bin\/netstat" /etc/sudoers

#安装jdk
yum -y install java-1.8.0-openjdk.x86_64
yum -y install java-1.8.0-openjdk-devel-1.8.0.312.b07-1.el7_9.x86_64

sleep 3
#安装nginx(可选项)
cat > /etc/yum.repos.d/nginx.repo << EOF
# nginx.repo
[nginx]
name=nginx repo
baseurl=http://nginx.org/packages/centos/7/$basearch/
gpgcheck=0
enabled=1
EOF
sed -i '4s/baseurl=http:\/\/nginx.org\/packages\/centos\/7\/\//baseurl=http:\/\/nginx.org\/packages\/centos\/7\/$basearch\//' /etc/yum.repos.d/nginx.repo
yum repolist
#yum list nginx --showduplicates | sort -r
yum -y install nginx-1.18.0-1.el7.ngx.x86_64

sleep 3
#安装postgresql(可选项)
#安装存储库
yum -y install https://download.postgresql.org/pub/repos/yum/10/redhat/rhel-7-x86_64/pgdg-redhat-repo-42.0-11.noarch.rpm
yum install -y https://download.postgresql.org/pub/repos/yum/reporpms/EL-7-x86_64/pgdg-redhat-repo-latest.noarch.rpm
yum -y install postgresql10-10.15-1PGDG.rhel7
yum -y install postgresql10-server-10.15-1PGDG.rhel7.x86_64
#初始化数据库
/usr/pgsql-10/bin/postgresql-10-setup initdb
systemctl enable postgresql-10 --now
sudo -u postgres psql -c "ALTER USER postgres with encrypted password '$pg_passwd';"
sed -i '59a listen_addresses = '\''*'\''' /var/lib/pgsql/10/data/postgresql.conf
sed -i '119a max_prepared_transactions = 2' /var/lib/pgsql/10/data/postgresql.conf
sed -i '64a max_connections = 500' /var/lib/pgsql/10/data/postgresql.conf
sed -i '83a host    all             all             0.0.0.0\/0               md5' /var/lib/pgsql/10/data/pg_hba.conf

systemctl restart postgresql-10.service

执行完毕之后需要重启服务器

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

l3478127890

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值