1.防火墙端口设置
firewall-cmd --zone=public --add-port=8080/tcp --permanent # 开放8080端口
firewall-cmd --zone=public --remove-port=8080/tcp --permanent #关闭8080端口
firewall-cmd --reload #配置立即生效
firewall-cmd --zone=public --list-ports #查看防火墙所有开放的端口
firewall-cmd --state #查看防火墙状态
systemctl stop firewalld.service #关闭防火墙
systemctl start firewalld.service #开启防火墙
systemctl restart firewalld.service #重启防火墙
netstat -lnpt #查看监听的端口
2.MySQL部署
1)centos下卸载自带MariaDB,避免于MySQL冲突
rpm -qa | grep mariadb #查看是否安装mariadb
rpm -e mariadb-libs-5.5.60-1.el7_5.x86_64 --nodeps #卸载mariadb【mariadb-libs-5.5.60-1.el7_5.x86_64为本机安装的mariadb】
2)关闭selinux
setenforce 0 #临时关闭
vi /etc/selinux/config #修改selinux配置,永久关闭
SELINUX=disabled #设置后退出保存# 可选择放开3306端口,如不暴露外部访问,则无需放开
firewall-cmd --zone=public --add-port=3306/tcp --permanent
firewall-cmd --reload # 重启防火墙
3)修改用户最大可创建文件数据
ulimit -SHn 65536 #临时修改
#永久修改
vi /etc/security/limits.conf
* soft nofile 65535
* hard nofile 65535
4)下载安装包 https://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-5.7.40-el7-x86_64.tar.gz,上传至服务器【home】目录下
tar xvf mysql-5.7.40-el7-x86_64.tar.gz #解压
mv mysql-5.7.44-el7-x86_64 /usr/local/mysql #将解压文件移至【/usr/local/mysql】位置# 创建MySQL用户组和用户
groupadd mysql
useradd -r -g mysql -s /bin/false mysql#创建MySQL所需文件夹,并设置权限
mkdir -p /home/mysql/{data,tmp}
touch /home/mysql/{mysql.sock,mysqld.log,mysqld.pid}
chown -R mysql:mysql /home/mysql
5)配置 my.cnf 配置文件
vi /etc/my.cnf
# my.cnf配置内容如下
[client]
socket=/home/mysql/mysql.sock[mysqld]
innodb_buffer_pool_size = 2g#服务id
server-id=1
#日志目录
#log_bin=/home/mysql/binlog/mysql-bin
#binlog_format=ROWjoin_buffer_size = 4M
sort_buffer_size = 4M
read_rnd_buffer_size = 4M
datadir=/home/mysql/data
socket=/home/mysql/mysql.sock
tmpdir= /home/mysql/tmp
log-error=/home/mysql/mysqld.log
pid-file=/home/mysql/mysqld.pid# 禁用软链接
symbolic-links=0
#数据行更新时,timestamp类型字段不更新为当前时间
explicit_defaults_for_timestamp=truemax_connections=1200
wait_timeout=28800
interactive_timeout=28800
max_allowed_packet = 64M
table_open_cache = 2048
tmp_table_size = 128M
ft_min_word_len = 4
skip-external-lockingsql_mode=STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION
6)初始化数据目录
/usr/local/mysql/bin/mysqld --defaults-file=/etc/my.cnf --initialize
chown -R mysql:mysql /home/mysql# 复制启动脚本到/etc/init.d目录
cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysql.server#添加mysql 环境变量
vi /etc/profile.d/mysql.sh
export PATH=$PATH:/usr/local/mysql/binsource /etc/profile #重载环境变量/etc/init.d/mysql.server start #安全启动MySQL服务
/etc/init.d/mysql.server stop #关闭MySQL服务
7)修改MySQL登录密码
grep 'temporary password' /home/mysql/mysqld.log #查看初始化密码mysql -uroot -p
ALTER USER 'root'@'localhost' IDENTIFIED BY '123456'; #修改密码
flush privileges; #刷新权限
3.nginx配置
# 安装依赖
yum install pcre pcre-devel openssl openssl-devel -y
rpm -ivh zlib*# 下载nginx,并解压
wget https://nginx.org/download/nginx-1.22.1.tar.gz
tar xvf nginx-1.22.1.tar.gz# 编译安装nginx
cd nginx-1.22.1
./configure \
--prefix=/usr/local/nginx \
--with-http_gzip_static_module \
--with-http_ssl_module
make && make install# 修改配置
# 临时修改
ulimit -SHn 65536
# 永久修改
vi /etc/security/limits.conf
#用户 soft/hard nofile 65535
#当前shell该用户能打开的最大文件数
* soft nofile 65535
* hard nofile 65535# 关闭selinux,放开端口配置操作如以上MySQL设置一致,如已关闭selinux,则无需配置useradd -M -s /sbin/nologin nginx # 添加nginx用户
ln -s /usr/local/nginx/sbin/nginx /usr/bin/# 修改nginx配置,根据自身项目配置
vi /usr/local/nginx/conf/nginx.conf/usr/local/nginx/sbin/nginx # 启动nginx
/usr/local/nginx/sbin/nginx -s stop #关闭nginx
4.redis配置
# 下载解压redis
wget https://download.redis.io/releases/redis-6.2.7.tar.gz
tar xf redis-6.2.7.tar.gz
cd redis-6.2.7/# 编译安装
yum -y install cpp binutils glibc glibc-kernheaders glibc-common glibc-devel gcc make gcc-c++ libstdc++-devel tcl
make MALLOC=libc PREFIX=/usr/local/redis install# 配置redis
mkdir /usr/local/redis/conf
cp redis.conf /usr/local/redis/conf/vi /usr/local/redis/conf/redis.conf
#修改以下配置项
#bind 0.0.0.0
daemonize yes
requirepass 123456# 配置启动服务
vi /lib/systemd/system/redis.service
[Unit]
Description=Redis
After=network.target[Service]
Type=forking
PIDFile=/var/run/redis_6379.pid
ExecStart=/usr/local/redis/bin/redis-server /usr/local/redis/conf/redis.conf
ExecReload=/bin/kill -s HUP $MAINPID
ExecStop=/bin/kill -s QUIT $MAINPID
PrivateTmp=true[Install]
WantedBy=multi-user.target
vi /lib/systemd/system/redis.service
[Unit]
Description=Redis
After=network.target[Service]
Type=forking
PIDFile=/var/run/redis_6379.pid
ExecStart=/usr/local/redis/bin/redis-server /usr/local/redis/conf/redis.conf
ExecReload=/bin/kill -s HUP $MAINPID
ExecStop=/bin/kill -s QUIT $MAINPID
PrivateTmp=true[Install]
WantedBy=multi-user.targetsystemctl daemon-reload # 重载服务
systemctl start redis # 启动redis
systemctl enable redis # 测试redis登录校验
ln -s /usr/local/redis/bin/redis-cli /usr/bin/redis-cli
redis-cli -h 127.0.0.1 -p 6379 -a 123456
5.其他命令
# 查看服务进程
ps -ef | grep 【服务关键字】,比如:ps -ef | grep java
# 安全关闭进程
kill -15 【进程ID】
# 强制关闭进程
kill -9 【进程ID】
其他命令后续持续补充,有好的建议可以提出