1. 网络配置
service network restart 命令冲突解决方法:
service NetworkManager stop
chkconfig NetworkManager off
service network restart
2. 基本命令
-
创建多级目录
mkdir -p a/b/c -
安装mariadb
[root@localhost src]# yum install mariadb-server 安装mariadb数据库
[root@localhost src]# yum clean all 清空已安装文件 如果下载失败之后执行的.
- 数据库命令
- 启动命令 [root@localhost src]# systemctl start mariadb
- 重启命令 [root@localhost src]# systemctl restart mariadb
- 关闭命令 [root@localhost src]# systemctl stop mariadb
- 设定开机自起 [root@localhost src]# systemctl enable mariadb
- 关闭开机自起 [root@localhost src]# systemctl disable mariadb
-
数据库初始化
mysql_secure_installation -
开放数据库权限
use mysql;
update user set host=“%” where host=“localhost”;
flush privileges;
3. 防火墙
- 关闭防火墙
查看防火墙状态
firewall-cmd --state
- 禁用启用防火墙
systemctl disable firewalld.service
systemctl enable firewalld.service
- 关闭开启防火墙
systemctl stop firewalld.service
systemctl start firewalld.service
- 手动开放防火墙端口
1). 检查防火墙开放的端口
firewall-cmd --list-ports
2).检查端口是否开放
firewall-cmd --query-port 80/tcp
3). 开启防火墙
firewall-cmd --zone=public --add-port=80/tcp --permanent
4).移除端口
firewall-cmd --zone=public --remove-port=9090/tcp --permanent
5).关于防火墙操作的解释
–zone #作用域
–add-port=80/tcp #添加端口,格式为:端口/通讯协议
–remove-port=80/tcp #移除端口,格式为:端口/通讯协议
–permanent #永久生效,没有此参数重启后失效
6).重启防火墙
firewall-cmd --reload
4. 部署后端
-
后端项目打包
-
运行项目
基础命令: java -jar 8091.jar -
后台运行
nohup java -jar 8091.jar => 8091.log &
java -jar jt-8091.jar 2>&1 >/dev/null
- 查看java 进程
jps - 关闭进程
kill -15 PID号
kill -9 PID号
日志查看
cat 输出文件所有的内容
more 输出文档所有的内容,分页输出,空格浏览下一屏,q退出
less 用法和more相同,只是通过PgUp、PgDo键来控制
tail 用于显示文件后几号,使用频繁
tail -10 nginx.conf 查看nginx.conf的最后10行
tail –f nginx.conf 动态查看日志,方便查看日志新增的信息
ctrl+c 结束查看
5. Linux 安装 Nginx
官网地址
http://nginx.org/en/download.html
软件下载地址
http://nginx.org/download/nginx-1.21.3.tar.gz
命令
1. 启动nginx start nginx
2. 重启nginx nginx -s reload
3. 关闭nginx nginx -s stop
5.1 service 支持 nginx
编辑 /etc/init.d/nginx
chmod 755 /etc/init.d/nginx
#!/bin/bash
#Startup script for the nginx Web Server
#chkconfig: 2345 85 15
nginx=/usr/local/nginx/sbin/nginx
conf=/usr/local/nginx/conf/nginx.conf
case $1 in
start)
echo -n "Starting Nginx"
$nginx -c $conf
echo " done."
;;
stop)
echo -n "Stopping Nginx"
pkill nginx
echo " done."
;;
test)
$nginx -t -c $conf
echo "Success."
;;
reload)
echo -n "Reloading Nginx"
ps auxww | grep nginx | grep master | awk '{print $2}' | xargs kill -HUP
echo " done."
;;
restart)
$nginx -s reload
echo "reload done."
;;
*)
echo "Usage: $0 {start|restart|reload|stop|test|show}"
;;
esac
5.2 systemctl 支持 nginx
编辑 /usr/lib/systemd/system/nginx.service
[Unit]
Description=nginx - high performance web server
After=network.target remote-fs.target nss-lookup.target
[Service]
Type=forking
PIDFile=/usr/local/nginx/logs/nginx.pid
ExecStartPre=/usr/local/nginx/sbin/nginx -t -c /usr/local/nginx/conf/nginx.conf
ExecStart=/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
ExecReload=/usr/local/nginx/sbin/nginx -s reload
ExecStop=/usr/local/nginx/sbin/nginx -s stop
ExecQuit=/usr/local/nginx/sbin/nginx -s quit
PrivateTmp=true
[Install]
WantedBy=multi-user.target
5.3 编辑nginx配置文件
vim /usr/local/nginx/conf/nginx.conf
#配置图片代理 image.jt.com
server {
listen 80;
server_name image.jt.com;
location / {
root /opt/web/images;
}
}
#配置前端代理 www.jt.com
server {
listen 80;
server_name www.jt.com;
location / {
root /opt/web/jt;
index index.html;
}
}
#配置后台服务器集群
upstream tomcats{
server 192.168.70.129:8091;
server 192.168.70.129:8092;
server 192.168.70.129:8093;
}
#配置后端代理 manage.jt.com
server {
listen 80;
server_name manage.jt.com;
location / {
proxy_pass http://tomcats;
}
}