常用工具
一、SecureCRT
- 设置秘钥对登录 使用阿里云的公用ip
- 需要在阿里安全规则组设置ssh端口
二、winSCP
root登录不了:
(1)vim /etc/ssh/sshd_config
(2)PasswordAuthentication yes
PermitRootLogin yes
(3)systemctl restart sshd进行重启
Centos 常用命令以及安装一些库
- yum -y install lrzsz
- yum install libaio-devel.x86_64
- yum install glibc.i686
- rm -rf 强制删除
- rm -f 删除文件
- tar -xzvf xx.tar.gz 解压tar.gz
- xz -d 转化xz为tar
- tar -xvf xx.tar 解压tar
- rz 上传文件
- sz 下载文件
- mv 修改文件名
- touch 文件名 创建文件
- mkdir 文件夹名 创建文件夹
服务器配置流程
一、安装jdk
通过java -version查看系统是否默认安装,如果已安装通过下面命令移除:
yum -y remove java-1.7.0-openjdk*
yum -y remove java-1.8.0-openjdk*
- 在甲骨文官网下载相对应的tar.gz文件,上传到服务器解压
- vim /etc/profile
- i插入
- export JAVA_HOME=/opt/jdk/jdk8
- export CLASSPATH=.:JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar
- PATH=JAVA_HOME/bin
- esc后输入wq保存
- source /etc/profile:配置文件生效
- java -version 查看
二、安装tomcat
- 在tomcat下载对应的tar.gz文件,上传到服务器解压
- vim /etc/profile
- i插入
- export TOMCAT_HOME=/opt/tomcat/tomcat9
- PATH=JAVA_HOME/bin:$TOMCAT_HOME/bin
- esc后输入wq保存
- source /etc/profile:配置文件生效
tomcat配置
- 在阿里服务器规则配置中增加8080/8080端口
- yum install rng-tools(启动熵服务,解决tomcat启动慢问题)
- systemctl start rngd-启动熵服务
- systemctl daemon-reload、systemctl restart rngd-重新载入服务
- 设置Tomcat开机自启动:
- 在tomca/bin 目录下面,增加 setenv.sh 配置,catalina.sh启动的时候会调用,同时配置Java内存参数:
CATALINA_PID="$CATALINA_BASE/tomcat.pid"
JAVA_OPTS="-server -XX:PermSize=256M -XX:MaxPermSize=1024m -Xms512M -Xmx1024M -XX:MaxNewSize=256m"
- 在/usr/lib/systemd/system目录下增加tomcat.service(根据实际路径设置):
[Unit]
Description=Tomcat
After=syslog.target network.target remote-fs.target nss-lookup.target
[Service]
Type=forking
Environment="JAVA_HOME=/usr/local/java"
PIDFile=/usr/local/tomcat/tomcat.pid
ExecStart=/usr/local/tomcat/bin/startup.sh
ExecReload=/bin/kill -s HUP $MAINPID
ExecStop=/bin/kill -s QUIT $MAINPID
PrivateTmp=true
[Install]
WantedBy=multi-user.target
-
使用tomcat.service命令:
开机启动
systemctl enable tomcat.service
启动tomcat
systemctl start tomcat.service
停止tomcat
systemctl stop tomcat.service
重启tomcat
systemctl restart tomcat.service
- http://ip:8080/ 验证是否成功
三、mysql安装以及配置
在MySQL官网中下载yum源rpm安装包
yum localinstall xxx.rpm:使用安装源
yum install mysql-community-server:安装mysql
-
mysqld --initialize --user=mysql --console
- 初始化mysql
- 在/var/lib/mysql/会生成一个mysql.sock,需要设置在my.cnf上
- 会生成一个临时密码,用来作为临时登录
-
配置my.cnf文件
[client]
socket=/var/lib/mysql/mysql.sock
default-character-set=utf8[mysql]
default-character-set=utf8
socket=/var/lib/mysql/mysql.sock[mysqld]
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock 通过mysql -uroot -p 以及临时密码进入mysql
alter user 'root'@'localhost'IDENTIFIED BY 'newpassword';
flush privileges;
Navicat连接阿里云mysql
解决Navicat 报错:1130-host is not allowed MySQL不允许从远程访问的方法:
mysql>usemysql;
mysql>update user set host = '%' where user ='root';
mysql>select host, user from user;解决Client does not support authentication protocol requested by server; consider upgrading MySQL client:
ALTER USER 'root'@'%' IDENTIFIED WITH mysql_native_password BY '你的密码';
ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY '你的密码';
SELECT plugin FROM mysql.user WHERE User = 'root';mysql相关命令:
启动mysql
systemctl start mysqld
停止
systemctl stop mysqld
开机启动
systemctl enable mysqld
systemctl daemon-reload
四、nginx安装以及配置
- yum install gcc-c++
- yum install -y pcre pcre-devel
- yum install -y zlib zlib-devel
- yum install -y openssl openssl-devel
- 到nginx下载安装包
- tar -zxvf nginx-1.10.1.tar.gz
- cd nginx-1.10.1
- ./configure
- make
- make install
- whereis nginx:查找安装路径
- nginx设置:
-
vi /lib/systemd/system/nginx.service (下面文件路径不用重新设)
[Unit]
Description=nginx
After=network.target[Service]
Type=forking
ExecStart=/usr/local/nginx/sbin/nginx
ExecReload=/usr/local/nginx/sbin/nginx -s reload
ExecStop=/usr/local/nginx/sbin/nginx -s quit
PrivateTmp=true[Install]
WantedBy=multi-user.target -
相关命令
启动nginx服务
systemctl start nginx.service
设置开机自启动
systemctl enable nginx.service
停止开机自启动
systemctl disable nginx.service
查看服务当前状态
systemctl status nginx.service
重新启动服务
systemctl restart nginx.service
查看所有已启动的服务
systemctl list-units --type=service
-
五、服务器放置Vue项目
通过npm run build 打包出vue的dist,复制到服务器特定文件夹中
-
vim /usr/local/nginx/conf/nginx.conf配置路径 :
server { listen 8089;//指定端口 server_name localhost; root /opt/project/vue-appmanager/dist/;//存放项目目录 index index.html; location / { try_files $uri $uri/ /index.html; } }
六、服务器放置SpringBoot项目
Maven->Lifecycle->clean->Install,然后在target文件夹中会出现.jar文件
-
vim /usr/local/nginx/conf/nginx.conf配置路径 :
server { listen 80; server_name localhost; location /appmanagerapi{//跟springboot项目设置的 context-path一致 proxy_pass http://127.0.0.1:8088/appmanagerapi; } error_page 500 502 503 504 /50x.html; location = /50x.html { root html; } }
把springboot的jar设置为开机自启动
-
进入/lib/systemd/system 创建xxxx.service(名字随便定)
[Unit]
Description=abcd service
After=syslog.target[Service]
Type=simple
ExecStart= /opt/jdk1.8.0_211/bin/java -jar /opt/project/springboot/xxxx.jar[Install]
WantedBy=multi-user.target -
相关命令:
刷新服务配置文件
systemctl daemon-reload
服务设置为开机启动
systemctl enable xxx.service
启动服务
systemctl start xx.service
停止服务
systemctl stop xx.service
查看服务状态
systemctl status xx.service
七、阿里配置配置对应端口
- http:80
- https:443
- vue:8089