centos安装redis

官网下载的安装包 redis-4.0.2.tar.gz

1.解压文件tar -zxvf redis-4.0.2.tar.gz
2.make   #如果错误则使用下面的命令
make MALLOC=libc

a001

3.安装完毕后就配置文件

3.1 设置redis可以一直在后台运行,以守护进程方式运行,即关闭SSH工具程序也在运行。
daemonize no 改成 daemonize yes

3.2 默认的话redis-server启动时会在当前目录生成或读取dump.rdb,可以指定生成的路径
dir ./ 改成 dir /usr/local/redis/

3.3 指定是否在每次更新操作后进行日志记录
appendonly no 改成 appendonly yes

因为 redis本身同步数据文件是按上面save条件来同步的,所以有的数据会在一段时间内只存在于内存中。默认为no

3.4 默认redis是只能内网127.0.0.0访问,如果想外网访问需要修改绑定的地址
bind 127.0.0.1 改成 bind 0.0.0.0
改成任何IP都能访问的,当然这里也可以绑定单独的IP;改成外网访问需要设置密码,否则会报错;

3.5 修改保护模式,不修改保护模式也是只能内网访问的
protected-mode yes 改成 protected-mode no

3.6 设置密码
将”# requirepass foobared“ 改成 requirepass 123
4.启动redis服务

./redis-server redis.conf
*注:必需指定redis.conf文件,如果不指定,会加载默认的配置,那修改过的配置也不会生效。

5.验证服务是否启动:

ps aux|grep redis

a003

redis-cli测试内网
cd /www/server/redis.4.0.2/src
./redis-cli #我的是没有设置密码,所以直接回车
./redis-cli -a 123
备注:redis-cli -h 实例连接地址 -a 密码

a002

 

yum -y install gcc gcc-c++ gcc-g77 make libtool autoconf patch unzip automake libxml2 libxml2-devel ncurses ncurses-devel libtool-ltdl-devel libtool-ltdl libmcrypt libmcrypt-devel libpng libpng-devel libjpeg-devel openssl openssl-devel curl curl-devel libxml2 libxml2-devel ncurses ncurses-devel libtool-ltdl-devel libtool-ltdl autoconf automake libaio*

Nginx支持socket转发

有个接口是通过socket通信,对端服务器访问存在IP限制,只好通过跳板机,因为它具备访问对端服务器的权限。nginx1.9开始支持tcp层的转发,通过stream实现的,而socket也是基于tcp通信。

一.实现过程:

1.安装nginx,stream模块默认不安装的,需要手动添加参数:–with-stream,官方下载地址:download,根据自己系统版本选择nginx1.9或以上版本。

2.nginx.conf 配置,参考说明:ngx_stream_core_module

nginx.conf

user nginx;
worker_processes 1;
error_log /var/log/nginx/error.log warn;
pid /var/run/nginx.pid;
events {
worker_connections 1024;
}
http {
……………..
}

# tcp层转发的配置文件夹

include /etc/nginx/tcp.d/*.conf;
请注意,stream配置不能放到http内,即不能放到/etc/nginx/conf.d/,因为stream是通过tcp层转发,而不是http转发。

如配置在http内,启动nginx会报如下错误:

nginx: [emerg] “server” directive is not allowed here
3.在tcp.d下新建个bss_num_30001.conf文件,内容如下:

Spring框架简介

1. Spring框架的作用

轻量:Spring是轻量级的,基本的版本大小为2MB
控制反转:Spring通过控制反转实现了松散耦合,对象们给出它们的依赖,而不是创建或查找依赖的对象们。
面向切面的编程AOP:Spring支持面向切面的编程,并且把应用业务逻辑和系统服务分开。
容器:Spring包含并管理应用中对象的生命周期和配置
MVC框架: Spring-MVC
事务管理:Spring提供一个持续的事务管理接口,可以扩展到上至本地事务下至全局事务JTA
异常处理:Spring提供方便的API把具体技术相关的异常

tx:annotation-driven注解方式EnableTransactionManagement

替换方法是用@EnableTransactionManagement

以下是官方文档:

org.springframework.transaction.annotation
Annotation Type EnableTransactionManagement


@Target(value=TYPE)
@Retention(value=RUNTIME)
@Documented
@Import(value=TransactionManagementConfigurationSelector.class)
public @interface EnableTransactionManagement

Enables Spring’s annotation-driven transaction management capability, similar to the support found in Spring’s <tx:*> XML namespace. To be used on @Configuration classes as follows:

 @Configuration
 @EnableTransactionManagement
 public class AppConfig {
     @Bean
     public FooRepository fooRepository() {
         // configure and return a class having @Transactional methods
         return new JdbcFooRepository(dataSource());
     }

     @Bean
     public DataSource dataSource() {
         // configure and return the necessary JDBC DataSource
     }

     @Bean
     public PlatformTransactionManager txManager() {
         return new DataSourceTransactionManager(dataSource());
     }
 }

For reference, the example above can be compared to the following Spring XML configuration:

 <beans>
     <tx:annotation-driven/>
     <bean id="fooRepository" class="com.foo.JdbcFooRepository">
         <constructor-arg ref="dataSource"/>
     </bean>
     <bean id="dataSource" class="com.vendor.VendorDataSource"/>
     <bean id="transactionManager" class="org.sfwk...DataSourceTransactionManager">
         <constructor-arg ref="dataSource"/>
     </bean>
 </beans>
 

In both of the scenarios above, @EnableTransactionManagement and <tx:annotation-driven/> are responsible for registering the necessary Spring components that power annotation-driven transaction management, such as the TransactionInterceptor and the proxy- or AspectJ-based advice that weave the interceptor into the call stack when JdbcFooRepository‘s @Transactional methods are invoked.

A minor difference between the two examples lies in the naming of the PlatformTransactionManager bean: In the @Bean case, the name is “txManager” (per the name of the method); in the XML case, the name is“transactionManager”. The <tx:annotation-driven/> is hard-wired to look for a bean named “transactionManager” by default, however @EnableTransactionManagement is more flexible; it will fall back to a by-type lookup for anyPlatformTransactionManager bean in the container. Thus the name can be “txManager”, “transactionManager”, or “tm”: it simply does not matter.

For those that wish to establish a more direct relationship between @EnableTransactionManagement and the exact transaction manager bean to be used, the TransactionManagementConfigurer callback interface may be implemented – notice the implements clause and the @Override-annotated method below:

 @Configuration
 @EnableTransactionManagement
 public class AppConfig implements TransactionManagementConfigurer {
     @Bean
     public FooRepository fooRepository() {
         // configure and return a class having @Transactional methods
         return new JdbcFooRepository(dataSource());
     }

     @Bean
     public DataSource dataSource() {
         // configure and return the necessary JDBC DataSource
     }

     @Bean
     public PlatformTransactionManager txManager() {
         return new DataSourceTransactionManager(dataSource());
     }

     @Override
     public PlatformTransactionManager annotationDrivenTransactionManager() {
         return txManager();
     }
 }

This approach may be desirable simply because it is more explicit, or it may be necessary in order to distinguish between two PlatformTransactionManager beans present in the same container. As the name suggests, theannotationDrivenTransactionManager() will be the one used for processing @Transactional methods. See TransactionManagementConfigurer Javadoc for further details.

The mode() attribute controls how advice is applied; if the mode is AdviceMode.PROXY (the default), then the other attributes control the behavior of the proxying.

If the mode() is set to AdviceMode.ASPECTJ, then the proxyTargetClass() attribute is obsolete. Note also that in this case the spring-aspects module JAR must be present on the classpath.

Since:
3.1
Author:
Chris Beams
See Also:
TransactionManagementConfigurer, TransactionManagementConfigurationSelector, ProxyTransactionManagementConfiguration, AspectJTransactionManagementConfiguration

Optional Element Summary
 AdviceMode mode
Indicate how transactional advice should be applied.
 int order
Indicate the ordering of the execution of the transaction advisor when multiple advices are applied at a specific joinpoint.
 boolean proxyTargetClass
Indicate whether subclass-based (CGLIB) proxies are to be created (true) as opposed to standard Java interface-based proxies (false).

 

proxyTargetClass

public abstract boolean proxyTargetClass
Indicate whether subclass-based (CGLIB) proxies are to be created (true) as opposed to standard Java interface-based proxies (false). The default is false. Applicable only if mode() is set to AdviceMode.PROXY.Note that setting this attribute to true will affect all Spring-managed beans requiring proxying, not just those marked with @Transactional. For example, other beans marked with Spring’s @Async annotation will be upgraded to subclass proxying at the same time. This approach has no negative impact in practice unless one is explicitly expecting one type of proxy vs another, e.g. in tests.

Default:
false

mode

public abstract AdviceMode mode
Indicate how transactional advice should be applied. The default is AdviceMode.PROXY.
See Also:
AdviceMode
Default:
org.springframework.context.annotation.AdviceMode.PROXY

order

public abstract int order
Indicate the ordering of the execution of the transaction advisor when multiple advices are applied at a specific joinpoint. The default is Ordered.LOWEST_PRECEDENCE.
Default:
2147483647

 

https://docs.spring.io/spring/docs/4.0.x/javadoc-api/org/springframework/transaction/annotation/EnableTransactionManagement.html

更多文档:

https://docs.spring.io/spring/docs/4.0.x/javadoc-api/overview-summary.html

Nginx使用upstream模块实现tomcat负载均衡

UPSTREAM负载均衡模块

负载均衡模块用于从”upstream”指令定义的后端主机列表中选取一台主机。nginx先使用负载均衡模块找到一台主机,再使用upstream模块实现与这台主机的交互。为了方便介绍负载均衡模块,做到言之有物,以下选取nginx内置的ip hash模块作为实际例子进行分析。

配置

要了解负载均衡模块的开发方法,首先需要了解负载均衡模块的使用方法。因为负载均衡模块与之前书中提到的模块差别比较大,所以我们从配置入手比较容易理解。

在配置文件中,我们如果需要使用ip hash的负载均衡算法。我们需要写一个类似下面的配置:

14041424344114
 
Copyright © 2008-2021 lanxinbase.com Rights Reserved. | 粤ICP备14086738号-3 |