Linux新机器下各种环境搭建
网卡配置
centos 7
shell
cd /etc/sysconfig/network-scripts
vi ifcfg-ens33
txt
TYPE=Ethernet
PROXY_METHOD=none
BROWSER_ONLY=no
BOOTPROTO=static # 静态
DEFROUTE=yes
IPV4_FAILURE_FATAL=no
IPV6INIT=yes
IPV6_AUTOCONF=yes
IPV6_DEFROUTE=yes
IPV6_FAILURE_FATAL=no
IPV6_ADDR_GEN_MODE=stable-privacy
NAME=ens33
UUID=8c937384-60e8-4b7d-a6e1-1dc6c4cb8647
DEVICE=ens33
ONBOOT=yes
IPADDR=192.168.198.204 # 配置静态IP
NETMASK=255.255.255.0 # 子网掩码
GATEWAY=192.168.198.2 # 网关
DNS1=8.8.8.8 # DNS服务器,一般都是网关也可以是其他的
配置国内镜像
阿里云镜像源 https://developer.aliyun.com/mirror/
安装wget工具 yum install -y wget
yum
备份
shellmv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup
下载新的 CentOS-Base.repo 到 /etc/yum.repos.d/
shellwget -O /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-7.repo
运行 yum makecache 生成缓存
epel
备份(如有配置其他epel源)
shellmv /etc/yum.repos.d/epel.repo /etc/yum.repos.d/epel.repo.backup mv /etc/yum.repos.d/epel-testing.repo /etc/yum.repos.d/epel-testing.repo.backup
下载新repo 到/etc/yum.repos.d/
shellwget -O /etc/yum.repos.d/epel.repo https://mirrors.aliyun.com/repo/epel-7.repo
安装Docker
shell
curl -fsSL get.docker.com -o get-docker.sh # 拉取docker官方脚本
sh get-docker.sh --mirror Aliyun # 执行脚本,使用阿里云镜像
systemctl enable docker # 把docker服务加入开机自启
systemctl start docker # 启动docker服务 restart 重启 status 状态 stop停止
docker -v
# 【可选】推荐将当前用户加入docker组
groupadd docker
usermod -aG docker $USER
# 【可选】配置阿里云加速
sudo mkdir -p /etc/docker
sudo tee /etc/docker/daemon.json <<-'EOF'
{
"registry-mirrors": ["https://09w3lr09.mirror.aliyuncs.com"]
}
EOF
sudo systemctl daemon-reload
sudo systemctl restart docker
安装Docker-Compose
从GitHub下载二进制文件,放到指定文件目录下更改下可执行权限即可
shell
sudo curl -L https://github.com/docker/compose/releases/download/1.25.0/docker-compose-`uname -s`-`uname -m` -o /usr/local/bin/docker-compose
chmod +x /usr/local/bin/docker-compose
docker compose version
部署MySQL,Redis
新建目录 docker-database 编辑文件 docker-compose-db.yml
yaml
version: '3.8'
services:
mysql:
container_name: mysql
image: mysql
restart: always
ports:
- "3306:3306"
volumes:
- ./mysql/conf:/etc/mysql/conf.d
- ./mysql/logs:/logs
- ./mysql/data:/var/lib/mysql
- ./mysql/db:/docker-entrypoint-initdb.d/ # 初始化的脚本,初始化我们存放的init.sql文件
environment:
- "MYSQL_ROOT_PASSWORD=root"
- "TZ=Asia/Shanghai"
redis:
container_name: redis
image: redis
restart: always
ports:
- "6379:6379"
volumes:
- ./redis/conf/redis.conf:/etc/redis/redis.conf
- ./redis/data:/data
command: redis-server /etc/redis/redis.conf
执行 docker compose up -d 即可部署安装成功
基础组件库gcc,make等
shell
yum install -y tree ncurses-devel libaio-devel net-tools vim wget zlib zlib-devel openssl openssl-devel pcre pcre-devel mnttpd-tools make cmake gcc gcc-c++ autoconf automake bash-completion lrzsz expect nc nmap dos2unix htop iftop iotop unzip telnet sl psmisc nethogs glance bc ntpdate openldap-devel
安装Jdk和Maven
官网下载对应版本的安装包 jdk-8u181-linux-x64.tar.gz apache-maven-3.8.6-bin.tar.gz
解压到 /usr/local/ 下
配置环境变量 vi /etc/profile
shell
# Maven Environment Config
export MAVEN_HOME=/usr/local/apache-maven-3.8.6
export PATH=$PATH:$JAVA_HOME/bin:$MAVEN_HOME/bin
# Java Environment Config
export JAVA_HOME=/usr/local/jdk1.8.0_181
export JRE_HOME=${JAVA_HOME}/jre
export CLASSPATH=.:${JAVA_HOME}/lib:${JRE_HOME}/lib
export PATH=${JAVA_HOME}/bin:$PATH
刷新环境变量 source /etc/profile
配置 maven 本地仓库和阿里云镜像【可选】
vi /usr/local/apache-maven-3.8.6/conf/settings.xml
xml
<!-- 修改本地仓库路径:新建一个目录repo -->
<localRepository>/usr/local/apache-maven-3.8.6/repo</localRepository>
<!-- 配置阿里云镜像 -->
<mirror>
<id>aliyunmaven</id>
<mirrorOf>*</mirrorOf>
<name>阿里云公共仓库</name>
<url>https://maven.aliyun.com/repository/public</url>
</mirror>
编译安装Nginx
- 下载源码
shell
wget http://nginx.org/download/nginx-1.23.3.tar.gz
- 解压
shell
tar -zxvf nginx-1.23.3.tar.gz
- 编译安装(编译安装记得安装基础组件比如gcc等)
shell
cd nginx-1.23.3
./configure --prefix=/usr/local/nginx-1.23.3/ --with-http_ssl_module --with-http_flv_module --with-http_gzip_static_module --with-http_stub_status_module --with-threads --with-file-aio
make && make install
- 测试访问,curl localhost,外部无法访问,请检查防火墙
配置防火墙放开端口
- 检查防火墙状态
shell
firewall-cmd --state
- 启动防火墙
shell
systemctl start firewalld.service
- 关闭防火墙
shell
systemctl stop firewalld.service
- 刷新防火墙
shell
firewall-cmd --reload
- 查看某个端口是否开放
shell
firewall-cmd --query-port=80/tcp
- 查看开放的端口
shell
firewall-cmd --list-ports
- 开放端口
shell
firewall-cmd --add-port=80/tcp --permanent
- 关闭端口
shell
firewall-cmd --remove-port=80/tcp --permanent