Linux 初始化


目录:
1、初始化
# 修改hostname
hostnamectl set-hostname xxxx

# yum源修改
sudo cp -r /etc/yum.repos.d /etc/yum.repos.d.bak
sudo yum install wget -y
sudo wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
sudo yum clean all
sudo yum makecache
sudo yum update -y

# 工具软件安装
yum install -y unzip zip vim git net-tools htop lrzsz telnet bind-utils dos2unix sysstat irqbalance ntp tree nmap iptraf gcc gcc-c++ rsync net-snmp openssh-clients lvm2 wget bc glibc-headers python3 telnet iotop iftop

# 关闭防火墙和selinux
systemctl stop firewalld
systemctl disable firewalld
getenforce
setenforce 0
sed -i s/"SELINUX=enforcing"/"SELINUX=disabled"/g /etc/selinux/config

# 系统内核参数调优

# 修改密码

# 挂载新磁盘
fdisk /dev/sdb
n
p
1


w
mkfs.xfs /dev/sdb1
mkdir /data
mount /dev/sdb1 /data

vim /etc/fstab
/dev/sdb1       /data   xfs     defaults        0 0
systemctl daemon-reload


# 时钟同步
crontab -e

#Ansible: 时钟同步
*/30 * * * * /usr/sbin/ntpdate ntp.sjtu.edu.cn
2、swap分区
3、web & proxy

yum或编译安装nginx

4、nodejs
#wget下载tar包
wget https://npm.taobao.org/mirrors/node/v10.18.0/node-v10.18.0-linux-x64.tar.gz

#解包
tar zxvf node-v10.18.0-linux-x64.tar.gz

#移动至安装安装目录
mv node-v10.18.0-linux-x64 /usr/local/node

#创建软链接
ln -s /usr/local/node/bin/node /usr/bin/node
ln -s /usr/local/node/bin/npm /usr/bin/npm

#进入/usr/local/node/路径下:
cd /usr/local/node/
mkdir node_global
mkdir node_cache
npm config set prefix "node_global"
npm config set cache "node_cache"

#当你觉得npm慢的时候,可以安装cnpm
npm install cnpm -g --registry=https://registry.npm.taobao.org
5、php-fpm及扩展
6、jdk
mkdir -p /usr/local/jdk14
cd /usr/local/jdk14
# 地址:https://www.oracle.com/java/technologies/downloads/
wget https://download.oracle.com/otn/java/jdk/8u321-b07/df5ad55fdd604472a86a45a217032c7d/jdk-8u321-linux-x64.tar.gz?AuthParam=1647942976_e94b714af35510a739f43f6b0edcb3ee
tar zxvf jdk-8u311-linux-x64.tar.gz
mv jdk1.8.0_311/* ./
rm jdk-8u311-linux-x64.tar.gz\?AuthParam\=1637058410_b05134c49bebb93d9cb0ba6f068e07a7

cat >> /etc/profile <<EOF
{
export JAVA_HOME=/usr/local/jdk14
export PATH=$PATH:/usr/local/jdk14/bin
}
EOF
source /etc/profile

java -version
7、中间件
8、docker & docker-compose
#docker、docker-compose安装
wget https://download.docker.com/linux/static/stable/x86_64/docker-20.10.9.tgz
tar zxvf docker-20.10.9.tgz
sudo cp docker/* /usr/bin/

touch /etc/systemd/system/docker.service
cat >> /etc/systemd/system/docker.service <<EOF
[Unit]
Description=Docker Application Container Engine
Documentation=https://docs.docker.com
After=network-online.target firewalld.service
Wants=network-online.target
[Service]
Type=notify
# the default is not to use systemd for cgroups because the delegate issues still
# exists and systemd currently does not support the cgroup feature set required
# for containers run by docker
ExecStart=/usr/bin/dockerd
ExecReload=/bin/kill -s HUP $MAINPID
# Having non-zero Limit*s causes performance problems due to accounting overhead
# in the kernel. We recommend using cgroups to do container-local accounting.
LimitNOFILE=infinity
LimitNPROC=infinity
LimitCORE=infinity
# Uncomment TasksMax if your systemd version supports it.
# Only systemd 226 and above support this version.
#TasksMax=infinity
TimeoutStartSec=0
# set delegate yes so that systemd does not reset the cgroups of docker containers
Delegate=yes
# kill only the docker process, not all processes in the cgroup
KillMode=process
# restart the docker process if it exits prematurely
Restart=on-failure
StartLimitBurst=3
StartLimitInterval=60s
[Install]
WantedBy=multi-user.target
EOF

touch /etc/systemd/system/docker.socket
cat >> /etc/systemd/system/docker.socket <<EOF
[Unit]
Description=Docker Socket for the API
PartOf=docker.service
[Socket]
# If /var/run is not implemented as a symlink to /run, you may need to
# specify ListenStream=/var/run/docker.sock instead.
ListenStream=/run/docker.sock
SocketMode=0660
SocketUser=root
SocketGroup=docker
[Install]
WantedBy=sockets.target
EOF

sudo systemctl daemon-reload
sudo systemctl start docker
sudo systemctl status docker
sudo systemctl enable docker

sudo tee /etc/docker/daemon.json <<-'EOF'
{
  "registry-mirrors": [
    "https://registry.docker-cn.com",
    "http://hub-mirror.c.163.com",
    "https://docker.mirrors.ustc.edu.cn",
    "https://cr.console.aliyun.com"
  ],
  "bip": "192.168.200.1/24"
}
EOF
sudo systemctl restart docker

wget https://github.com/docker/compose/releases/download/v2.2.3/docker-compose-linux-x86_64
mv docker-compose-linux-x86_64 /usr/bin/docker-compose
chmod +x /usr/bin/docker-compose