1. linux查看端口及一些基本命令
linux下查看所有开启的端口
netstat -ntulp
查看80端口以及占用的线程
netstat -ntulp |grep 80
linux自动获取ip
dhclient
查看cpu个数
cat /proc/cpuinfo| grep "physical id"| sort| uniq| wc -l
查看cpu核数
cat /proc/cpuinfo| grep "cpu cores"| uniq
2. springboot jar包部署到服务器上的一些操作
springboot项目后台运行并且输出日志
nohup java -jar nuode-shooping-1.0-SNAPSHOT.jar >>ndshooping.log 2>&1 &
不输出日志
nohup java -jar nuode-shooping-1.0-SNAPSHOT.jar >/dev/null &
3. centos7源码(tar包)安装nginx
3.1. 下载解压
使用tar命令解压
tar -zxvf nginx-1.10.0.tar.gz
3.2. 安装
1.进入解压后的nginx目录执行以下命令
./configure --prefix=usr/local/nginx-1.10.0
–prefix=PATH : 指定 nginx 的安装目录。默认 /usr/local/nginx
若出现以下错误
./configure: error: C compiler cc is not found
需安装gcc
yum install gcc-c++
继续执行./configure命令若出现以下错误
./configure: error: the HTTP rewrite module requires the PCRE library.
需安装pcre库
yum install pcre-devel -y
继续执行./configure命令若出现以下错误
./configure: error: the HTTP gzip module requires the zlib library.
需安装zlib库
yum install zlib-devel -y
2.继续执行./configure命令若没有错误,表示当前环境可以安装nginx,执行以下命令
make && make install
3.3. 把nginx添加到service服务里面
1.进入到nginx.service文件
vim /usr/lib/systemd/system/nginx.service
2.写入以下配置
#服务描述性的配置
[Unit]
Description=nginx - high performance web server
Documentation=http://nginx.org/en/docs/
After=network.target remote-fs.target nss-lookup.target
#服务关键配置
[Service]
Type=forking
#pid文件位置
#要与nginx配置文件中的pid配置路径一致,这个很重要,否则会服务启动失败
PIDFile=/var/run/nginx.pid
#启动前检测 nginx配置文件 是否正确
ExecStartPre=/usr/local/nginx-1.10.0/sbin/nginx -t -c /usr/local/nginx-1.10.0/conf/nginx.conf
#启动
ExecStart=/usr/local/nginx-1.10.0/sbin/nginx -c /usr/local/nginx-1.10.0/conf/nginx.conf
#重启
ExecReload=/usr/local/nginx-1.10.0/sbin/nginx -s reload
#关闭
ExecStop=/usr/local/nginx-1.10.0/sbin/nginx -s stop
PrivateTmp=true
[Install]
WantedBy=multi-user.target
然后执行(修改或新增文件需要执行以下语句才能生效)
systemctl daemon-reload
接下来就可以执行以下命令来开启/停止/重启nginx
service nginx start/stop/reload
3.4. nginx.conf文件的配置
user www www;
#user root;
worker_processes auto;
error_log /www/wwwlogs/nginx_error.log crit;
pid /www/server/nginx/logs/nginx.pid;
worker_rlimit_nofile 51200;
events
{
use epoll;
worker_connections 51200;
multi_accept on;
}
http
{
include mime.types;
#include luawaf.conf;
include proxy.conf;
default_type application/octet-stream;
server_names_hash_bucket_size 512;
client_header_buffer_size 32k;
large_client_header_buffers 4 32k;
client_max_body_size 50m;
sendfile on;
tcp_nopush on;
keepalive_timeout 60;
tcp_nodelay on;
fastcgi_connect_timeout 300;
fastcgi_send_timeout 300;
fastcgi_read_timeout 300;
fastcgi_buffer_size 64k;
fastcgi_buffers 4 64k;
fastcgi_busy_buffers_size 128k;
fastcgi_temp_file_write_size 256k;
fastcgi_intercept_errors on;
gzip on;
gzip_min_length 1k;
gzip_buffers 4 16k;
gzip_http_version 1.1;
gzip_comp_level 2;
gzip_types text/plain application/javascript application/x-javascript text/javascript text/css application/xml;
gzip_vary on;
gzip_proxied expired no-cache no-store private auth;
gzip_disable "MSIE [1-6]\.";
limit_conn_zone $binary_remote_addr zone=perip:10m;
limit_conn_zone $server_name zone=perserver:10m;
server_tokens off;
access_log off;
server
{
listen 80;
server_name www.nuodehealthy.com;
index index.html index.htm index.php;
root /www/server/phpmyadmin;
#error_page 404 /404.html;
include enable-php.conf;
charset utf-8;
location = /
{
proxy_pass http://172.16.245.44:8081/rosten-water-0.1;
proxy_connect_timeout 600;
proxy_read_timeout 600;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
location /rosten-water-0.1/
{
proxy_pass http://172.16.245.44:8081/rosten-water-0.1/;
proxy_connect_timeout 600;
proxy_read_timeout 600;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
#location ~.*(js|css|png|gif|jpg|mp3|ogg)$ {
#root的内容填写静态资源目录
# root /www/server/tomcat/webapps/rosten-water-0.1/;
#}
#location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
#{
# root /www/server/tomcat/webapps/rosten-water-0.1/;
# if (-f $request_filename) {
# expires 1d;
# break;
# }
#}
#location ~ .*\.(js|css)$
# {
# root /www/server/tomcat/webapps/rosten-water-0.1/;
# if (-f $request_filename) {
# expires 1d;
# break;
#}
#}
#location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
#{
# expires 30d;
#}
#location ~ .*\.(js|css)?$
#{
# expires 12h;
#}
#location ~ /\.
#{
# deny all;
#}
access_log /www/wwwlogs/access.log;
}
include /www/server/panel/vhost/nginx/*.conf;
}
4. centos7源码安装jdk
把源码包拉到/opt目录下,使用以下命令解压
tar -vxzf xxx.tar.gz
打开profile文件,并找到最后一行,添加环境变量
vim /etc/profile
JAVA_HOME=/opt/jdk1.8.0_144
JRE_HOME=$JAVA_HOME/jre
PATH=$PATH:$JAVA_HOME/bin
CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar
export JAVA_HOME
export JRE_HOME
export PATH
export CLASSPATH
刷新
source /etc/profile
为什么要建这个超链接,因为一些自己注册的linux服务(如springboot的jar注册的服务),默认情况下从/usr/bin/java路径使用java,yum安装的时候,这个超链接会自动创建,如果你自己下载包安装的话,这个超链接就需要你手动创建了。
ln -s /opt/jdk1.8.0_144/bin/java /usr/bin/java
5. centos7源码安装tomcat
把源码包拉到/opt目录下,解压即可。使用以下命令运行tomcat
/opt/tomcat/bin/startup.sh
6. centos7源码安装mysql
6.1. 先查看有没有安装过mysql
rpm -qa|grep mysql
有就卸载
rpm -e --nodeps xxx
6.2. 安装编译需要的包
yum -y install gcc-c++ cmake bison-devel ncurses-devel
6.3. 进入mysql目录编译并安装
cd mysql-5.6.14
cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DMYSQL_DATADIR=/usr/local/mysql/data -DSYSCONFDIR=/etc -DWITH_MYISAM_STORAGE_ENGINE=1 -DWITH_INNOBASE_STORAGE_ENGINE=1 -DWITH_MEMORY_STORAGE_ENGINE=1 -DWITH_READLINE=1 -DMYSQL_UNIX_ADDR=/var/lib/mysql/mysql.sock -DMYSQL_TCP_PORT=3306 -DENABLED_LOCAL_INFILE=1 -DWITH_PARTITION_STORAGE_ENGINE=1 -DEXTRA_CHARSETS=all -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci
make && make install
6.4. 配置mysql
设置权限
使用下面的命令查看是否有mysql用户及用户组
cat /etc/passwd 查看用户列表
cat /etc/group 查看用户组列表
如果没有就创建
groupadd mysql
useradd -g mysql mysql
修改/usr/local/mysql权限
chown -R mysql:mysql /usr/local/mysql
初始化配置,进入安装路径(在执行下面的指令),执行初始化配置脚本,创建系统自带的数据库和表
cd /usr/local/mysql
scripts/mysql_install_db --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data --user=mysql [这是一条指令]
注:在启动MySQL服务时,会按照一定次序搜索my.cnf,先在/etc目录下找,找不到则会搜索"$basedir/my.cnf",在本例中就是 /usr/local/mysql/my.cnf,这是新版MySQL的配置文件的默认位置!
如果执行上一条命令报以下错误
Can't locate Data/Dumper.pm in @INC (@INC contains: /usr/local/lib64/perl5 /usr/local/share/perl5 /usr/lib64/perl5/vendor_perl /usr/share/perl5/vendor_perl /usr/lib64/perl5 /usr/share/perl5 .) at scripts/mysql_install_db line 42.
BEGIN failed--compilation aborted at scripts/mysql_install_db line 42.
是缺少缺少perl插件,yum安装
yum -y install 'perl(Data::Dumper)'
继续执行上一条命令
注意:在CentOS 7版操作系统的最小安装完成后,在/etc目录下会存在一个my.cnf,需要将此文件更名为其他的名字,如:/etc/my.cnf.bak,否则,该文件会干扰源码安装的MySQL的正确配置,造成无法启动。
修改名称,防止干扰:
mv /etc/my.cnf /etc/my.cnf.bak
启动MySQL
添加服务,拷贝服务脚本到init.d目录,并设置开机启动
[注意在 /usr/local/mysql 下执行]
cp support-files/mysql.server /etc/init.d/mysql
chkconfig mysql on
service mysql start --启动MySQL
配置mysql密码
/usr/local/mysql/bin/mysql -uroot
set password=password('123456');
配置任何目录下都能使用mysql命令
vim /etc/profile
在PATH下添加mysql路径
PATH=/opt/jdk1.8.0_144/bin:/usr/local/mysql/bin:$PATH
刷新profile文件
source /etc/profile
7. 按时备份数据库
需求分析
1)每天凌晨 2:10 备份 数据库 atguiguDB 到 /data/backup/db
2)备份开始和备份结束能够给出相应的提示信息
3)备份后的文件要求以备份时间为文件名,并打包成 .tar.gz 的形式,比如:
2018-03-12_230201.tar.gz
在备份的同时,检查是否有 10 天前备份的数据库文件,如果有就将其删除。
vim backup.sh
#!/bin/bash
HOST=localhost
USER=root
PASSWORD=123456
DATABASE=test_h
DATETIME=$(date +%Y-%m-%d_%H%M%S)
BACKUP=/data/backup
#不存在备份目录就创建,存在就使用
[ ! -d $BACKUP ] && mkdir -p $BACKUP
echo "--------------------备份开始-------------------------"
echo "--------------------备份目录:$BACKUP-------------------------"
mysqldump -u$USER -p$PASSWORD --host=$HOST $DATABASE > $BACKUP/$DATETIME.sql
cd $BACKUP
tar -zcvf $DATETIME.tar.gz $DATETIME.sql
#删除临时文件
rm -rf $DATETIME.sql
#查找10天前的备份文件并删除
find $BACKUP -mtime +10 -name "*.tar.gz" -exec rm -rf {} \;
#查找10分钟前的备份文件并删除
find $BACKUP -mmin +10 -name "*.tar.gz" -exec rm -rf {} \;
#查找2小时内的备份文件并删除
find $BACKUP -mmin -120 -name "*.tar.gz" -exec rm -rf {} \;
echo "--------------------备份结束-------------------------"
创建调度任务
crontab -e
10 2 * * * /home/hkq/backup.sh
8. springboot环境配置
application.yml配置
server:
port: 8082
spring:
application:
name: nuode-shooping
datasource:
driver-class-name: com.mysql.jdbc.Driver
url: jdbc:mysql://192.168.0.137:3306/nd-shooping
username: root
password: password
hikari:
maximum-pool-size: 30
minimum-idle: 10
mybatis:
configuration:
map-underscore-to-camel-case: true
log-impl: org.apache.ibatis.logging.stdout.StdOutImpl
type-aliases-package: com.nuode.shopping.pojo
pom配置
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.nuode</groupId>
<artifactId>nuode-shooping</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>
<name>nuode-shooping Maven Webapp</name>
<!-- FIXME change it to the project's website -->
<url>http://www.example.com</url>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.17.RELEASE</version>
</parent>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.7</maven.compiler.source>
<maven.compiler.target>1.7</maven.compiler.target>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.16.20</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.32</version>
</dependency>
<dependency>
<groupId>tk.mybatis</groupId>
<artifactId>mapper-spring-boot-starter</artifactId>
<version>2.0.2</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.apache.shiro/shiro-spring -->
<dependency>
<groupId>org.apache.shiro</groupId>
<artifactId>shiro-spring</artifactId>
<version>1.4.2</version>
</dependency>
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>fastjson</artifactId>
<version>1.2.44</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
9. idea注释配置
9.1. 类注释
找到file and code templates ->file header
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-XTz0v8h0-1615340741515)(assets\1585205296(1)].png)
/**
* @description
* @author huangkaiqiang
* @date ${DATE} ${TIME}
* @version 1.0
*/
9.2. 方法注释
找到live templates ->新建模板
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-ROGz8krS-1615340741521)(assets\1585206065(1)].png)
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-HaF4m1K9-1615340741524)(assets\1585205854(1)].png)
/**
* @description $description$
* $VAR1$
$params$* @return $returns$
* @date $date$ $time$
*/
VAR1:
groovyScript(" def result=''; def params=\"${_1}\".replaceAll('[\\\\[|\\\\]|\\\\s]', '').split(',').toList(); for(i = 0; i < params.size(); i++) { if(i!=0)result+= ' * '; result+='@param ' + params[i] + ((i < (params.size() - 1)) ? '\\n' + '\\t' : ''); }; return result", methodParameters())
params:不写
returns:methodReturnType()
date:date()
time:time()
10. 防止idea创建maven工程加载过慢
使用maven骨架创建web项目 -->点击加号
添加
name:archetypeCatalog
value:internal
11. spring环境配置
11.1. 不使用AOP
导入pom依赖
<dependencies>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>4.3.20.RELEASE</version>
</dependency>
</dependencies>
编写bean.xml文件
<?xml version="1.0" encoding="UTF-8"?>
<!--xml文件使用的标签-->
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd">
<bean id="a" class="com.hkq.study01.test.A"></bean>
<bean id="b" class="com.hkq.study01.test.B">
<property name="a" ref="a"></property>
</bean>
</beans>
<!--注解使用的标签-->
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd">
<!--告知spring在创建容器时要扫描的包,配置所需要的标签不是在beans的约束中,而是一个名称为
context名称空间和约束中-->
<context:component-scan base-package="com.hkq.study01"></context:component-scan>
</beans>
11.2. 使用AOP
导入pom依赖
<dependencies>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>4.3.20.RELEASE</version>
</dependency>
<!--切入点表达式-->
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjweaver</artifactId>
<version>1.8.7</version>
</dependency>
</dependencies>
编写bean.xml文件
<?xml version="1.0" encoding="UTF-8"?>
<!--基于xml文件配置-->
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:aop="http://www.springframework.org/schema/aop"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop.xsd">
</beans>
<!--基于注解配置-->
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd">
<!-- 配置spring创建容器时要扫描的包-->
<context:component-scan base-package="com.itheima"></context:component-scan>
<!-- 配置spring开启注解AOP的支持 -->
<aop:aspectj-autoproxy></aop:aspectj-autoproxy>
</beans>
11.3. 使用spring声明式事务
导入pom依赖
<dependencies>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>4.3.20.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-tx</artifactId>
<version>4.3.20.RELEASE</version>
</dependency>
<!--切入点表达式-->
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjweaver</artifactId>
<version>1.8.7</version>
</dependency>
编写bean.xml文件
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop.xsd">
</beans>
12. SSM整合
-
使用maven骨架创建项目,导入pom依赖
<?xml version="1.0" encoding="UTF-8"?> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>hkq.com</groupId> <artifactId>ssm</artifactId> <version>1.0-SNAPSHOT</version> <packaging>war</packaging> <name>ssm Maven Webapp</name> <!-- FIXME change it to the project's website --> <url>http://www.example.com</url> <properties> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <maven.compiler.source>1.8</maven.compiler.source> <maven.compiler.target>1.8</maven.compiler.target> <spring.version>5.2.1.RELEASE</spring.version> <slf4j.version>1.6.6</slf4j.version> <log4j.version>1.2.12</log4j.version> <mysql.version>5.1.6</mysql.version> <mybatis.version>3.4.5</mybatis.version> </properties> <dependencies> <!-- spring --> <dependency> <groupId>org.aspectj</groupId> <artifactId>aspectjweaver</artifactId> <version>1.6.8</version> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-context</artifactId> <version>${spring.version}</version> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-web</artifactId> <version>${spring.version}</version> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-webmvc</artifactId> <version>${spring.version}</version> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-test</artifactId> <version>${spring.version}</version> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-tx</artifactId> <version>${spring.version}</version> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-jdbc</artifactId> <version>${spring.version}</version> </dependency> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>4.12</version> <scope>test</scope> </dependency> <dependency> <groupId>mysql</groupId> <artifactId>mysql-connector-java</artifactId> <version>${mysql.version}</version> </dependency> <dependency> <groupId>javax.servlet</groupId> <artifactId>servlet-api</artifactId> <version>2.5</version> <scope>provided</scope> </dependency> <!--<dependency> <groupId>javax.servlet.jsp</groupId> <artifactId>jsp-api</artifactId> <version>2.0</version> <scope>provided</scope> </dependency> <dependency> <groupId>jstl</groupId> <artifactId>jstl</artifactId> <version>1.2</version> </dependency>--> <!-- log start --> <dependency> <groupId>log4j</groupId> <artifactId>log4j</artifactId> <version>${log4j.version}</version> </dependency> <dependency> <groupId>org.slf4j</groupId> <artifactId>slf4j-api</artifactId> <version>${slf4j.version}</version> </dependency> <dependency> <groupId>org.slf4j</groupId> <artifactId>slf4j-log4j12</artifactId> <version>${slf4j.version}</version> </dependency> <!-- log end --> <dependency> <groupId>org.mybatis</groupId> <artifactId>mybatis</artifactId> <version>${mybatis.version}</version> </dependency> <dependency> <groupId>org.mybatis</groupId> <artifactId>mybatis-spring</artifactId> <version>1.3.0</version> </dependency> <dependency> <groupId>c3p0</groupId> <artifactId>c3p0</artifactId> <version>0.9.1.2</version> <type>jar</type> <scope>compile</scope> </dependency> </dependencies> <build> <finalName>ssm</finalName> <pluginManagement> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> <version>3.2</version> <configuration> <source>1.8</source> <target>1.8</target> <encoding>UTF-8</encoding> <showWarnings>true</showWarnings> </configuration> </plugin> </plugins> </pluginManagement> </build> </project>
-
配置web.xml文件
<!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN" "http://java.sun.com/dtd/web-app_2_3.dtd" > <web-app> <display-name>Archetype Created Web Application</display-name> <!-- 配置Spring的监听器 --> <listener> <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> </listener> <!-- 配置加载类路径的配置文件 --> <context-param> <param-name>contextConfigLocation</param-name> <param-value>classpath:applicationContext.xml</param-value> </context-param> <!-- 配置前端控制器:服务器启动必须加载,需要加载springmvc.xml配置文件 --> <servlet> <servlet-name>dispatcherServlet</servlet-name> <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> <!-- 配置初始化参数,创建完DispatcherServlet对象,加载springmvc.xml配置文件 --> <init-param> <param-name>contextConfigLocation</param-name> <param-value>classpath:springmvc.xml</param-value> </init-param> <!-- 服务器启动的时候,让DispatcherServlet对象创建 --> <load-on-startup>1</load-on-startup> </servlet> <servlet-mapping> <servlet-name>dispatcherServlet</servlet-name> <url-pattern>/</url-pattern> </servlet-mapping> <!-- 配置解决中文乱码的过滤器 --> <filter> <filter-name>characterEncodingFilter</filter-name> <filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class> <init-param> <param-name>encoding</param-name> <param-value>UTF-8</param-value> </init-param> </filter> <filter-mapping> <filter-name>characterEncodingFilter</filter-name> <url-pattern>/*</url-pattern> </filter-mapping> </web-app>
-
在resources下新建springmvc.xml文件并配置
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:mvc="http://www.springframework.org/schema/mvc" xmlns:context="http://www.springframework.org/schema/context" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation=" http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd"> <!-- 扫描controller的注解,别的不扫描 --> <context:component-scan base-package="com.hkq.ssm" use-default-filters="false"> <context:include-filter type="annotation" expression="org.springframework.stereotype.Controller"/> </context:component-scan> <!-- 配置视图解析器 --> <bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver"> <!-- JSP文件所在的目录 --> <property name="prefix" value="/WEB-INF/pages/" /> <!-- 文件的后缀名 --> <property name="suffix" value=".jsp" /> </bean> <!-- 设置静态资源不过滤 --> <mvc:resources location="/css/" mapping="/css/**" /> <mvc:resources location="/images/" mapping="/images/**" /> <mvc:resources location="/js/" mapping="/js/**" /> <!-- 开启对SpringMVC注解的支持 --> <mvc:annotation-driven /> </beans>
-
在resources下新建applicationContext.xml文件并配置
<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context" xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd"> <context:component-scan base-package="com.hkq.ssm"> <context:exclude-filter type="annotation" expression="org.springframework.stereotype.Controller"/> </context:component-scan> <!-- 配置数据库相关参数properties的属性:${url} --> <context:property-placeholder location="classpath:jdbc.properties" /> <!-- 配置C3P0的连接池对象 --> <bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource"> <property name="driverClassName" value="${jdbc.driver}" /> <property name="url" value="${jdbc.url}" /> <property name="username" value="${jdbc.username}" /> <property name="password" value="${jdbc.password}" /> </bean> <!-- 配置SqlSession的工厂 --> <bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean"> <!-- 注入数据库连接池 --> <property name="dataSource" ref="dataSource" /> <!-- 扫描pojo包 使用别名 --> <property name="typeAliasesPackage" value="com.hkq.ssm.pojo"/> <!-- 扫描sql配置文件:mapper需要的xml文件 --> <property name="mapperLocations" value="classpath:mapper/*.xml"/> </bean> <!-- 配置扫描dao的包 --> <bean id="mapperScanner" class="org.mybatis.spring.mapper.MapperScannerConfigurer"> <property name="basePackage" value="com.hkq.ssm.mapper"/> </bean> </beans>
-
在resources下新建jdbc.properties文件并配置
jdbc.driver=com.mysql.jdbc.Driver jdbc.url=jdbc:mysql://localhost:3306/leyou jdbc.username=root jdbc.password=123456
-
在resources下新建log4j.properties文件并配置
# Set root category priority to INFO and its only appender to CONSOLE. #log4j.rootCategory=INFO, CONSOLE debug info warn error fatal log4j.rootCategory=info, CONSOLE, LOGFILE # Set the enterprise logger category to FATAL and its only appender to CONSOLE. log4j.logger.org.apache.axis.enterprise=FATAL, CONSOLE # CONSOLE is set to be a ConsoleAppender using a PatternLayout. log4j.appender.CONSOLE=org.apache.log4j.ConsoleAppender log4j.appender.CONSOLE.layout=org.apache.log4j.PatternLayout log4j.appender.CONSOLE.layout.ConversionPattern=%d{ISO8601} %-6r [%15.15t] %-5p %30.30c %x - %m\n # LOGFILE is set to be a File appender using a PatternLayout. log4j.appender.LOGFILE=org.apache.log4j.FileAppender log4j.appender.LOGFILE.File=d:\axis.log log4j.appender.LOGFILE.Append=true log4j.appender.LOGFILE.layout=org.apache.log4j.PatternLayout log4j.appender.LOGFILE.layout.ConversionPattern=%d{ISO8601} %-6r [%15.15t] %-5p %30.30c %x - %m\n
-
创建mybatisConfig.xml文件(可选)
<?xml version="1.0" encoding="UTF-8" ?> <!DOCTYPE configuration PUBLIC "-//mybatis.org//DTD Config 3.0//EN" "http://mybatis.org/dtd/mybatis-3-config.dtd"> <configuration> <!-- 配置全局属性 --> <settings> <!-- 使用jdbc的getGeneratedKeys获取数据库自增主键值 --> <setting name="useGeneratedKeys" value="true" /> <!-- 使用列别名替换列名 默认:true --> <setting name="useColumnLabel" value="true" /> <!-- 开启驼峰命名转换:Table{create_time} -> Entity{createTime} --> <setting name="mapUnderscoreToCamelCase" value="true" /> </settings> </configuration>
-
创建mapper.xml文件
<?xml version="1.0" encoding="UTF-8" ?> <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> <mapper namespace="com.hkq.ssm.mapper.BrandMapper"> <select id="findAllBrand" resultType="Brand"> SELECT id,name,image,letter FROM tb_brand; </select> </mapper>
13. redis
13.1 redis安装
-
解压redis.tar.gz包
tar -zxvf redis-5.0.8.tar.gz
-
安装gcc
yum -y install gcc-c++
-
进入redis文件夹编译安装
make install
如果出现zmalloc.h:50:31: 致命错误:jemalloc/jemalloc.h:没有那个文件或目录,则执行
make MALLOC=libc
如果出现以下错误
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-zTiGjsq4-1615340741527)(D:\BaiduNetdiskDownload\软件开发的环境配置\assets\425CFE55-1733-4a6e-8CA1-3632F13DEC9A.png)]
则执行
gcc -v # 查看gcc版本 yum -y install centos-release-scl # 升级到9.1版本 yum -y install devtoolset-9-gcc devtoolset-9-gcc-c++ devtoolset-9-binutils scl enable devtoolset-9 bash 以上为临时启用,如果要长期使用gcc 9.1的话: echo "source /opt/rh/devtoolset-9/enable" >>/etc/profile
然后接着编译安装,成功后会出现Hint:It’s a good idea to run ‘make test’
执行make test测试一下,如果出现以下错误
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-XucAf8TN-1615340741528)(D:\BaiduNetdiskDownload\软件开发的环境配置\assets\88568F76-142F-43d3-A312-76E0E4DC520E.png)]
执行
yum install tcl make test
-
redis默认安装路径
/usr/local/bin
13.2 redis配置文件详解
打开redis.conf文件
-
redis后台启动
把no修改为yes daemonize yes
14. linux服务器添加中文字体
-
安装必要的服务
yum install mkfontscale # 安装mkfontscale,mkfontdir yum install fontconfig # 安装fc-cache
-
安装字体
2.1. 创建/usr/share/fonts/myfonts目录
2.2. 把从C:\Windows\Fonts中的simsun.ttc文件拷贝到/usr/share/fonts/myfonts中
2.3. 进入到myfonts文件夹中
(1)执行 mkfontscale,生成了fonts.scale文件 (2)执行 mkfontdir,生成了fonts.dir文件 (3)执行 fc-cache -fv
-
使用 fc-list :lang=zh 查看字体库,查看是否包含新加入的字体
-
如果有其他服务使用,只需要重启服务器即可,比如重启Tomcat/Apache等
15. 解决java图片增加文字水印变成了方框
-
进入jdk安装路径中的jre/lib/fonts文件夹
-
创建fallback文件夹
ntos-release-scl # 升级到9.1版本
yum -y install devtoolset-9-gcc devtoolset-9-gcc-c++ devtoolset-9-binutils
scl enable devtoolset-9 bash
以上为临时启用,如果要长期使用gcc 9.1的话:
echo “source /opt/rh/devtoolset-9/enable” >>/etc/profile然后接着编译安装,成功后会出现Hint:It's a good idea to run 'make test' 执行make test测试一下,如果出现以下错误 [外链图片转存中...(img-XucAf8TN-1615340741528)] 执行 ```shell yum install tcl make test
-
redis默认安装路径
/usr/local/bin
13.2 redis配置文件详解
打开redis.conf文件
-
redis后台启动
把no修改为yes daemonize yes
14. linux服务器添加中文字体
-
安装必要的服务
yum install mkfontscale # 安装mkfontscale,mkfontdir yum install fontconfig # 安装fc-cache
-
安装字体
2.1. 创建/usr/share/fonts/myfonts目录
2.2. 把从C:\Windows\Fonts中的simsun.ttc文件拷贝到/usr/share/fonts/myfonts中
2.3. 进入到myfonts文件夹中
(1)执行 mkfontscale,生成了fonts.scale文件 (2)执行 mkfontdir,生成了fonts.dir文件 (3)执行 fc-cache -fv
-
使用 fc-list :lang=zh 查看字体库,查看是否包含新加入的字体
-
如果有其他服务使用,只需要重启服务器即可,比如重启Tomcat/Apache等
15. 解决java图片增加文字水印变成了方框
- 进入jdk安装路径中的jre/lib/fonts文件夹
- 创建fallback文件夹
- 把windows中的simsun.ttc字体文件拷贝到fallback文件夹中