当前位置:网站首页>centos8-操作记录-命令版-yum-redis-mysql-nacos-jdk
centos8-操作记录-命令版-yum-redis-mysql-nacos-jdk
2022-06-27 23:10:00 【privateobject】
在centos8的服务器上面,搭建项目环境的操作记录,操作命令记录。
- 磁盘挂载;
- yum配置源-centos-8;
- 系统语言切换;
- 用户或组管理;
- 防火墙配置;
- 部署jdk-8u201-linux-x64.rpm;
- 安装nginx-1.22.0-1.el8.ngx.x86_64;
- 安装 redis-4.0.9;
- 部署 nacos-server-2.1.0;
- 安装mysql-8.0.29-1.el8.x86_64;
参考
CentOS安装MySQL详解
centos7 磁盘挂载
Centos挂载硬盘完整图文教程(查看、分区、格式化、挂载)磁盘
CentOS 8 上MySQL 8.0 安装部署与配置教程
centos8安装mysql8.0.22教程(超详细)
linux(CentOS)安装mysql详解
centos7以普通用户开机启动某个服务或者指定脚本
linux centos8 nologin用户执行crontab命令
CentOS让一个用户没有登录权限
CentOS 用户和用户组管理
Centos 7 文件目录权限chmod、更改所有者和所属组chown、umask、隐藏权限lsattr/chattr
使用nginx做数据库端口转发
nginx通过四层代理实现端口转发
mysql 8 create user_MySQL8.0 创建用户及授权
操作记录
磁盘挂载
# 磁盘 挂载情况
df -kh
df /var/lib/ -kh
fdisk -l
#用于列出所有可用块设备的信息
lsblk
lsblk -f
### 创建分区 ###
parted /dev/vdb
##########vvv
(parted) ? #可以查看所有命令
(parted) mklabel #创建磁盘标签,设置标签格式为GPT
New disk label type? gpt # 大分区类型,好像支持18EB
(parted) mkpart #创建分区
Partition name? []? #指定分区名称,直接回车
File system type? [ext2] xfs #指定分区类型,可以存储超大文件
Start? 0 #指定起始位置
End? 500G #指定结束位置(也可写100G,重复以上操作创建第二个分区,也可备用)
#生成的分区没有正确地对齐以实现最佳性能。忽略/取消?
Warning: The resulting partition is not properly aligned
for best performance. 34s / 2048s != 0s
Ignore/Cancel? cancel
# 输入是2048扇区,而不是2048字节,也不是2048兆字节
(parted) mkpart primary 2048s 100% #对齐的方式分区,提升性能
# 检查分区是否对齐了
(parted) align-check optimal 1
1 aligned
(parted) p #显示分区信息
(parted) q #退出
##########
lsblk #再次查看硬盘信息,进行确认
mkfs.xfs /dev/vdb1 #格式化
lsblk -f #查看uuid
# [[uuid]]
blkid -s UUID /dev/vdb1 #查看uuid
#创建挂载目录,目录位置随意安排
mkdir [[挂载目录]]
#做个备份,文件改坏了,只要没重启系统就能补救
cp /etc/fstab /etc/fstab.bak
cat /etc/fstab
mount -U [[uuid]] [[挂载目录]]
# 查看是否挂载上
df -h
# 永久挂载方式1
########## 这是一行命令回车请忽略,中间的空格不能缺少
echo UUID=[[uuid]] [[挂载目录]] xfs defaults 0 0 >> /etc/fstab
vim /etc/fstab # 编辑内容对齐
##########
##格式
#第一列:设备名 UUID=1276eec6-7141-4858-9f37-9ab1d4c7b602(用/dev/sdb1也行)
#第二列:设备挂载目录 /mnt/data/ (挂载前自己创建的)
#第三列:设备文件系统 xfs (做分区时候自己设定的)
#第四列:挂载参数 defaults (选默认就行了,其它太多了)
#第五列:指明是否要备份 0 (0为不备份,1为要备份,一般根分区备份)
#第六列:指明自检顺序 0 (0为不自检,1或者2为要自检,如根分区为1,其他分区只能2)
# 磁盘 挂载情况
df -kh
df /var/lib/ -kh
fdisk -l
yum配置源
# 使用阿里的源,因为没有wget故使用curl下载
curl -O http://mirrors.aliyun.com/repo/Centos-8.repo
ll
pwd
cp Centos-8.repo /etc/yum.repos.d/CentOS-Base.repo
yum -y install wget
# yum 可以使用了
wget --help
# 对于新部署的服务器,也是推荐upgrade全部的软件包,已获得最新的安全补丁
yum -y upgrade
# 更新后,需要备份一下源,并重新使用阿里源
mv /etc/yum.repos.d/CentOS-* /etc/yum.repos.d/bak/
# rm -rf /etc/yum.repos.d/CentOS-* # 或者直接删除
cp Centos-8.repo /etc/yum.repos.d/CentOS-Base.repo
# :%s/原文本/目标文本/g # 全局替换,将原文本全部替换为目标文本
yum -y install vim
yum -y install tar
yum -y install telnet
yum -y install make
系统语言切-中文
yum -y install langpacks-zh_CN
yum -y install glibc-langpack-zh.x86_64
locale -a
#查看localectl是否存在
type localectl
vi /etc/locale.conf
#######vvv
LANG="zh_CN.UTF-8"
#######
# 配置生效,重启或重新加载配置
# reboot 或 source /etc/locale.conf
. /etc/locale.conf
locale # 已经生效
用户或组管理
# 创建z-ssh用户组
groupadd -g 220520 z-ssh
# 组列表
cat /etc/group
# 创建用户并分配组 adduser 或 useradd
adduser -g z-ssh z-user
# 用户列表
cat /etc/passwd
# 设置密码
passwd z-user
# 用户切换
su z-user
su root #需密码
# 不登录用户:
groupadd -g 4444 no-login
#-s为默认shell,默认给予shell,但是不给登录shell
useradd -g no-login nacos -s /sbin/nologin
useradd -g no-login redis -s /sbin/nologin
useradd -g no-login mysql -s /sbin/nologin
部署jdk、nacos
参考另一篇博客
Linux-centos上安装nacos并延迟自启
# 从华为镜像网站下载java
wget https://repo.huaweicloud.com/java/jdk/8u201-b09/jdk-8u201-linux-x64.rpm
# wget https://repo.huaweicloud.com/java/jdk/8u201-b09/jdk-8u201-linux-x64.tar.gz
# 搜索openjdk,当前服务器没有jdk,故jdk的优先级问题不用考虑
yum search openjdk
# 安装jdk8
rpm -ivh jdk-8u201-linux-x64.rpm
java -version
# 搜索java
find / -name java
# /usr/java/jdk1.8.0_201-amd64/bin/java
# /usr/java/jdk1.8.0_201-amd64/jre/bin/java
vim /etc/profile
#######vvv
# java
export JAVA_HOME=/usr/java/jdk1.8.0_201-amd64
export JRE_HOME=/usr/java/jdk1.8.0_201-amd64/jre
export CLASS_PATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar:$JRE_HOME/lib
export PATH=$JAVA_HOME/bin:$JRE_HOME/bin:$PATH
#######
# 配置生效
source /etc/profile
# 查看变量
echo $JAVA_HOME
nacos
wget https://github.com/alibaba/nacos/releases/download/2.1.0/nacos-server-2.1.0.tar.gz
tar -zxvf nacos-server-2.1.0.tar.gz
mv nacos /usr/local/
java -version
# 单机模式启动
sh /usr/local/nacos/bin/startup.sh -m standalone
ps -ef |grep nacos
netstat -lnpt|grep 8848
# 默认密码 nacos nacos
vim /etc/nginx/conf.d/default.conf
#######vvv
location /nacos/ {
proxy_pass http://127.0.0.1:8848/nacos/;
}
#######
systemctl restart nginx
# 延迟启动脚本
vim /usr/local/nacos/bin/nacos_self_start.sh
#######vvv
#!/bin/bash
echo "nacos delayed 60s start"
sleep 60
sh /usr/local/nacos/bin/startup.sh -m standalone
echo "nacos start end"
#######
chmod +x /usr/local/nacos/bin/nacos_self_start.sh
# 开机自启
vim /etc/rc.d/rc.local
#######vvv
soure /etc/profile
# start nacos
nohup /usr/local/nacos/bin/nacos_self_start.sh &
#开机切换到t-user用户执行
#su t-user -c "nohup /usr/local/nacos/bin/nacos_self_start.sh &"
#######
chmod +x /etc/rc.d/rc.local
sh /usr/local/nacos/bin/shutdown.sh
systemctl enable rc-local # 启用
systemctl start rc-local # 启动
systemctl status rc-local #获取状态
vim /usr/local/nacos/conf/application.properties
#######vvv
nacos.logs.path=./logs/nacos
#######
安装nginx
# 下载nginx 的rpm包
wget http://nginx.org/packages/centos/8/x86_64/RPMS/nginx-1.22.0-1.el8.ngx.x86_64.rpm
# 安装
rpm -ivh nginx-1.22.0-1.el8.ngx.x86_64.rpm
# rpm 安装方式nginx 默认安装位置在 /etc/nginx/ 目录下
ll /etc/nginx/
# 启动nginx
systemctl start nginx
# 开机自启
systemctl enable nginx
ps -ef|grep nginx
# 主配置 /etc/nginx/nginx.conf
# 日志 /var/log/nginx/access.log
# 配置 /etc/nginx/conf.d/*.conf
# 静态页面 /usr/share/nginx/html
# /usr/sbin/nginx -c /etc/nginx/nginx.conf
# 测试配置 /usr/sbin/nginx -t -c /etc/nginx/nginx.conf
# 重启 /usr/sbin/nginx -s reload -c /etc/nginx/nginx.conf
systemctl restart nginx
# 查看端口
netstat -lnpt|grep 80
安装redis
wget http://download.redis.io/releases/redis-4.0.9.tar.gz
tar -zxvf redis-4.0.9.tar.gz
cd redis-4.0.9
make
# 编译成功后,执行安装
make install PREFIX=/usr/local/redis
cp redis.conf /usr/local/redis/bin/
mkdir /logs/redis
vim /logs/redis/notice.log
vim /usr/local/redis/bin/redis.conf
#######vvv
daemonize yes # 后台运行
port 6379 # 监听端口
requirepass password # 客户端连接密码
bind 127.0.0.1 #只允许本地进行访问,不允许远程连接
logfile "/logs/redis/notice.log"
#######
/usr/local/redis/bin/redis-server /usr/local/redis/bin/redis.conf
netstat -lntp|grep 6379
ps -ef |grep redis
./redis-cli -h 127.0.0.1 -p 6379 -a password
####vvv
127.0.0.1:6379> ping
PONG
127.0.0.1:6379> info
# Server
redis_version:4.0.9
...
####
vim /etc/systemd/system/redis.service
#######vvv
[Unit]
Description=redis-server
After=network.target
[Service]
Type=forking
ExecStart=/usr/local/redis/bin/redis-server /usr/local/redis/bin/redis.conf
PrivateTmp=true
[Install]
WantedBy=multi-user.target
#######
systemctl daemon-reload # 新增的systemctl的service 生效
systemctl enable redis.service #设置开机自启动
systemctl start redis.service #启动redis服务
systemctl stop redis.service #停止redis服务
systemctl restart redis.service #重新启动服务
systemctl status redis.service #查看服务当前状态
systemctl disable redis.service #停止开机自启动
安装mysql
# mysql5.7版本好像不支持centos8
# wget https://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-5.7.26-1.el7.x86_64.rpm-bundle.tar
# 下载mysql8.0.29
wget https://dev.mysql.com/get/Downloads/MySQL-8.0/mysql-8.0.29-1.el8.x86_64.rpm-bundle.tar
# 解压
tar -xvf mysql-8.0.29-1.el8.x86_64.rpm-bundle.tar
# 各rpm包是有依赖关系的,所以需要按照一定顺序进行安装
rpm -ivh mysql-community-common-8.0.29-1.el8.x86_64.rpm
rpm -ivh mysql-community-client-plugins-8.0.29-1.el8.x86_64.rpm
rpm -ivh mysql-community-libs-8.0.29-1.el8.x86_64.rpm
rpm -ivh mysql-community-client-8.0.29-1.el8.x86_64.rpm
rpm -ivh mysql-community-icu-data-files-8.0.29-1.el8.x86_64.rpm
yum -y install libaio
rpm -ivh mysql-community-server-8.0.29-1.el8.x86_64.rpm
#简单的方式,可以自动处理各个包之间的依赖关系并自动下载缺少的依赖
#yum install mysql-community-{server,client,common,libs}-*
systemctl status mysqld
systemctl enable mysqld.service
systemctl start mysqld.service
ps -ef |grep mysql
netstat -lntp|grep mysql
#第一次启动会创建超级管理员账号[email protected],初始密码存储在日志文件中
grep 'temporary password' /var/log/mysqld.log
# [email protected]: password
mysql -uroot -p
#######vvv
#修改默认密码
ALTER USER 'root'@'localhost' IDENTIFIED BY 'password';
#编码
SHOW VARIABLES LIKE 'character%';
#创建用户
create user 'test_user'@'%' IDENTIFIED BY 'password';
#创建数据库
create database test_db;
#用户授权
grant all on test_db.* to 'test_user'@'%';
#######
systemctl daemon-reload
防火墙配置
systemctl enable firewalld
systemctl start firewalld
systemctl status firewalld
# 启用端口
firewall-cmd --permanent --add-port=80/tcp
firewall-cmd --permanent --add-port=443/tcp
firewall-cmd --permanent --add-port=22/tcp
firewall-cmd --permanent --add-port=3306/tcp
firewall-cmd --permanent --add-port=6379/tcp
firewall-cmd --permanent --add-port=8848/tcp
firewall-cmd --reload
firewall-cmd --list-ports
# ssh 开放端口22、禁用root远程、授权指定用户远程
vi /etc/ssh/sshd_config
######vvv
Port 22
#允许任意ip访问呢
ListenAddress ::
AllowUsers z-user user2
#禁用root用户登陆
PermitRootLogin no
######
# ssh服务状态
systemctl status sshd.service
# ssh重启
systemctl restart sshd.service
问题-Access denied
# 执行systemctl命令报错
Failed to enable unit: Access denied
###
# 解决方式
kill -TERM 1
边栏推荐
- SQL Server 2016 detailed installation tutorial (with registration code and resources)
- 给女朋友看的消息中间件
- 免费、好用、强大的开源笔记软件综合评测
- Cloud assisted privacy collection intersection (server assisted psi) protocol introduction: Learning
- Is it reliable to invest in exchange traded ETF funds? Is it safe to invest in exchange traded ETF funds
- 去哪儿网(Qunar) DevOps 实践分享
- Efficient supplier management in supply chain
- 美团动态线程池实践思路已开源
- 想开户买股票,在网上办理股票开户安全吗?
- 模块化开发
猜你喜欢

如何在您的Shopify商店中添加实时聊天功能?

Proe/creo product structure design - continuous research

Proe/Creo产品结构设计-钻研不断

N methods of data De duplication using SQL

向excel中导入mysql中的数据表

Form forms and form elements (input, select, textarea, etc.)

面试官问:JS的继承

去哪儿网(Qunar) DevOps 实践分享

What are the requirements for customizing the slip ring for UAV

Message Oriented Middleware for girlfriends
随机推荐
电商转化率这么抽象,到底是个啥?
力扣今日题-522. 最长特殊序列
796 div.2 C. managing history thinking
有监督、无监督与半监督学习
How to add live chat in your Shopify store?
Latest MySQL advanced SQL statement Encyclopedia
LATEX 表格内容居左,中,右
LabVIEW continuous sampling and limited sampling mode
Import the data table in MySQL into Excel
Official announcement! Apache Doris graduated from the Apache incubator and officially became the top project of Apache!
Is it safe to open an account online now? Novice is just on the road, ask for the answer
独立站卖家都在用的五大电子邮件营销技巧,你知道吗?
什么是数字化?什么是数字化转型?为什么企业选择数字化转型?
Golang monkeys eat peaches and ask for the number of peaches on the first day
[open source] open source system sorting - Examination Questionnaire, etc
如何阅读一篇论文
单晶炉导电滑环的应用范围和作用是什么
Taro---day1---搭建项目
Acwing game 57 [unfinished]
Deep parsing of kubernetes controller runtime