分类
未分类

Java webservice详解

Archie_java于 2022-02-22 22:43:37 发布1736 收藏 5

分类专栏:WebService文章标签:javaxml开发语言

版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。

本文链接:https://blog.csdn.net/qq_43842093/article/details/123079151

版权

WebService 专栏收录该内容

5 篇文章2 订阅

订阅专栏

文章目录

1 webservice概述

webservice 即 web 服务,因互联网而产生,通过 webservice 这种 web 服务,我们可以实现互联网应用之间的资源共享,比如我们想知道 手机号码归属地,列车时刻表,天气预报,省市区邮政编码等信息,由于我们自己的数据库中并没有这些信息,那么我们可以调用第三方提供的 webservice服务,获取这些信息;

webservice 是一种系统之间进行调用的技术,系统之间调用的技术有:httpClient、hessian、dubbo、webservice 等;WebService 是一种跨越编程语言,跨越操作系统,跨越终端的远程调用技术,比如一个系统是 Java 语言开发的,另一个系统是 PHP 语言开发的,他们之间要实现信息交互,则可以使用 webservice 进行数据交互;

??所以 webservice 实现了异构系统之间的通信,不管是采用什么语言编写的,不管部署在什么操作系统平台上,使用 webservice 都可以实现信息的交换;

2 webservice核心要素

2.1 SOAP

SOAP 英文全称为:Simple Object Access Protocol,即简单对象访问协议,它是基于 xml 格式的消息交换协议;

OAP 定义了信息交换的格式,它包含一个重要的信封 envelope,使用信封envelope 来包装要传递的信息,使用命名空间 namespace 来区分传递的信息;简单来说,在 WebService 中传递的信息就是一封信,SOAP 就是信的通用格式,它定义了一封信应该有信封,信封里装着信的内容;

信封(envlope)的格式是固定的,而信的内容(要传递的数据)可以自己定义;SOAP 协议传输的数据采用 xml 格式进行封装,采用 http 协议进行传输,即soap=xml+http;

2.2 WSDL

WSDL 英文全称为 Web Service Description Language,即 Web Service 描述语言;它使用 xml 对 Web Service 进行描述,比如提供服务的方法、参数、返回值、数据类型等信息进行描述;简单来说,wsdl 就是 webservice 服务的使用说明书;

3 webservice的使用场景

1、应用系统集成
多个应用系统集成在一起,则需要信息交换或通信,那么可以采用 webservice进行通信;

2、异构系统之间通信
异构系统,主要是指编程语言不同的系统;不同系统之间,特别是开发语言不同的系统之间,可以通过 webservice 进行信息交换;

3、软件复用
webservice 可以作为一个公共的服务,供客户端调用,避免软件重复开发工作;

4 webservice的结构

服务端:提供服务,供客户端调用;
客户端:调用服务,获得服务的数据;

在这里插入图片描述

5 Java中的webservice

各种编程语言下都有 webservice 技术,比如 php、c#、Java 等;由于 webservice 定义交互的格式,所以不同编程语言之间可以实现相互调用,数据交换和通信;
Java 中的 webservice,即 Java API for XML-Based Webservices,简称JAX-WS 规范;

JAX-WS 是 sun 公司随 Java 5 发布的一项 webservice 规范,在此之前是JAX-RPC,JAX-RPC 不是很完善;由于 JAX-RPC 并不是很完善,所以在 Java 5 发布后,随即发布了 JAX-RPC2.0,该版本已经比较成熟和完善,后来为了和之前的规范进行区分,又将其改名为JAX-WS 2.0;

Java 5 对应 JAX-WS 2.0 版本;
Java 6 对应 JAX-WS 2.1 版本;
Java 7 对应 JAX-WS 2.2 版本;
目前 JAX-WS 是 2.2.9

5.1 webservice服务端

1、定义一个服务接口及实现,并将实现类注解为@WebService,标注了该注解的类的方法就变为 webservice 方法;

public interface UserService {

    public String sayHi (String name);

    public String work (String work);

    public User getUser (User user);

}
/**
 * 标注了该@WebService注解的类的方法就变为webservice方法
 */
@WebService
public class UserServiceImpl implements UserService {

    @Override
    public String sayHi(String name) {
        return "Hi, " + name;
    }

    @Override
    public String work (String work) {
        return "He is working " + work;
    }

    @Override
    public User getUser (User user) {
        user.setName(user.getName() + "-service");
        return user;
    }
}
12345678910111213141516171819202122
public class User {

    private int id;

    private String name;

    private Date birthday;

    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public Date getBirthday() {
        return birthday;
    }

    public void setBirthday(Date birthday) {
        this.birthday = birthday;
    }
}
1234567891011121314151617181920212223242526272829303132

2、通过 Endpoint 的 publish 方法,将上一步定义的服务发布出去;

public class Server {

    public static void main(String[] args) {
        //发布webservice
        String wsAddress = "http://localhost:6868/01-ws-java-server/ws";
        Endpoint endpoint = Endpoint.publish(wsAddress, new UserServiceImpl());
        System.out.println("webservice发布成功:" + endpoint.isPublished());
    }
}

3、运行 main 方法;

4、 在 浏 览 器 里 输入 http://localhost:6868/01-ws-java-server/ws?wsdl 将 会 看 到webservice 的 wsdl 信息;有了服务端的 webservice 描述文件 wsdl,就可以根据这个描述文件开发客户端调用程序
在这里插入图片描述

5.2 webservice客户端

1、根据服务端的 wsdl 文件生成客户端调用代码:
在命令行输入命令(需要配置了 Java 环境变量):
wsimport -encoding [编码] -keep -p [包名] [发布的服务地址?wsdl]
比如:

wsimport -encoding utf8 -keep -p com.ws.stub -Xnocompile http://localhost:6868/01-ws-java-server/ws?wsdl

其中:
wsimport 命令
-encoding 指定生成代码的编码格式
-keep 保存生成的代码
-p 指定包名
-Xnocompile 表示生成的代码不编译

在这里插入图片描述
在这里插入图片描述
2、使用生成的代码调用服务端提供的服务;

public class Client {

    public static void main(String[] args) {

        //1.创建一个webservice的客户端
        UserServiceImplService userServiceImplService = new UserServiceImplService();

        //2.获取远程服务接口对象
        UserServiceImpl userService = userServiceImplService.getUserServiceImplPort();

        //3.直接调用远程服务接口对象的方法
        String hi= userService.sayHi("张三丰");
        System.out.println(hi);

        String work = userService.work("Java");
        System.out.println(work);

        User user = new User();
        user.setId(100);
        user.setName("张无忌");
        user.setBirthday(DateUtils.dateToXmlDate(new Date()));
        User userServer = userService.getUser(user);
        System.out.println(userServer.getId() + "--" + userServer.getName() + "--" + userServer.getBirthday());
    }
}
12345678910111213141516171819202122232425

注意Date类型要使用工具类特殊处理

public class DateUtils {

    /**
     * 将Date类转换为XMLGregorianCalendar
     *
     * @param date
     * @return
     */
    public static XMLGregorianCalendar dateToXmlDate(Date date){
        Calendar cal = Calendar.getInstance();
        cal.setTime(date);
        DatatypeFactory dtf = null;
        try {
            dtf = DatatypeFactory.newInstance();
            XMLGregorianCalendar dateType = dtf.newXMLGregorianCalendar();
            dateType.setYear(cal.get(Calendar.YEAR));
            //由于Calendar.MONTH取值范围为0~11,需要加1
            dateType.setMonth(cal.get(Calendar.MONTH)+1);
            dateType.setDay(cal.get(Calendar.DAY_OF_MONTH));
            dateType.setHour(cal.get(Calendar.HOUR_OF_DAY));
            dateType.setMinute(cal.get(Calendar.MINUTE));
            dateType.setSecond(cal.get(Calendar.SECOND));

            return dateType;
        } catch (DatatypeConfigurationException e) {
            e.printStackTrace();
        }
        return null;
    }

    /**
     * 将XMLGregorianCalendar转换为Date
     *
     * @param cal
     * @return
     */
    public static Date xmlDate2Date(XMLGregorianCalendar cal){
        return cal.toGregorianCalendar().getTime();
    }
}
12345678910111213141516171819202122232425262728293031323334353637383940

6 WDSL文件说明

service

  • 整个 webservice 的服务信息,比如服务名,包括所有的服务;

binding

  • 定义每个服务接口的消息格式和协议细节;

portType

  • 描述整个 webservice 可以被执行的操作及相关信息;

message

  • 定义操作的一个或多个数据参数;

types

  • 定义 webservice 使用的全部数据类型;

7 webservice 请求与响应监控

webservice 的请求和响应是 soap 格式的 xml,可以采用一个端口监听工具 TCPMon,通过这个工具,我们可以非常方便地监听目标端口请求与响应的数据;

TCPMon 相当于一个“ 拦截器”,所有我们向目标服务器发送的数据包和服务器返回的数据包都要经过这个拦截器(也可以叫作代理服务器),进而拦截到请求和响应的数据包;
在这里插入图片描述
如上图,如果不使用监控工具,我们是通过 http://xxx.xxx.xxx:8080 访问服务端的服务;如果使用监控工具,则通过访问监控工具,由监控工具请求服务端的,服务,然后再把结果返回给我们,则访问请求变为:http://xxx.xxx.xxx:9000
需要访问9000重新生成WDSL,并替换掉之前的WDSL,然后重新发起请求。

8 webservice 在Tomcat中发布

1、添加相关依赖

<?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.ws</groupId>
    <artifactId>03-ws-web-server</artifactId>
    <version>1.0.0</version>

    <dependencies>
        <dependency>
            <groupId>com.sun.xml.ws</groupId>
            <artifactId>jaxws-rt</artifactId>
            <version>2.2.10</version>
        </dependency>

        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>javax.servlet-api</artifactId>
            <version>3.1.0</version>
        </dependency>

    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <configuration>
                    <source>1.8</source>
                    <target>1.8</target>
                </configuration>
            </plugin>
        </plugins>
    </build>

</project>
123456789101112131415161718192021222324252627282930313233343536373839

2、编写服务接口

public interface UserService {

    public String sayHi(String name);

    public String work(String work);

    public User getUser(User user);

}

3、添加服务实现类,并标注@webservice注解

/**
 * 标注了该@WebService注解的类的方法就变为webservice方法
 */
@WebService
public class UserServiceImpl implements UserService {

    @Override
    public String sayHi(String name) {
        return "Hi, " + name;
    }

    @Override
    public String work (String work) {
        return "He is working " + work;
    }

    @Override
    public User getUser (User user) {
        user.setName(user.getName() + "-service");
        return user;
    }
}
12345678910111213141516171819202122

4、在WEB-INF文件夹下创建webservice配置文件

<?xml version="1.0" encoding="UTF-8"?>
<endpoints xmlns="http://java.sun.com/xml/ns/jax-ws/ri/runtime" version="2.0">

    <!-- 服务路径http://网站路径/ws/userService -->
    <endpoint name="userService"
              implementation="com.ws.service.impl.UserServiceImpl"
              url-pattern="/ws/userService" />

</endpoints>

5、在web,xml中添加WSServlet,servlet3.0也可以不添加如下配置

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xmlns="http://java.sun.com/xml/ns/javaee"
         xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
         id="WebApp_ID" version="3.0">

    <!-- Servlet 3.0或者以上不需要配置 -->
    <servlet>
        <servlet-name>jaxws</servlet-name>
        <servlet-class>com.sun.xml.ws.transport.http.servlet.WSServlet</servlet-class>
        <load-on-startup>1</load-on-startup>
    </servlet>
    <servlet-mapping>
        <servlet-name>jaxws</servlet-name>
        <url-pattern>/ws/*</url-pattern>
    </servlet-mapping>

</web-app>
123456789101112131415161718

调用和之前一样

9 在Spring中使用webservice

1、导入依赖

<?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.ws</groupId>
    <artifactId>05-ws-spring-web-server</artifactId>
    <version>1.0.0</version>

    <dependencies>

        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-web</artifactId>
            <version>4.3.13.RELEASE</version>
        </dependency>

        <dependency>
            <groupId>org.jvnet.jax-ws-commons.spring</groupId>
            <artifactId>jaxws-spring</artifactId>
            <version>1.9</version>
        </dependency>

    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <configuration>
                    <source>1.8</source>
                    <target>1.8</target>
                </configuration>
            </plugin>
        </plugins>
    </build>

</project>
12345678910111213141516171819202122232425262728293031323334353637383940

2、编写服务接口
3、编写接口的实现类,并添加@webservice注解,需要让spring将该类加载为一个bean,所以需要加上@servcice或者@Component注解

/**
 * 标注了该@WebService注解的类的方法就变为webservice方法
 */
@Component
@WebService
public class UserServiceImpl implements UserService {

    @Override
    public String sayHi(String name) {
        return "Hi, " + name;
    }

    @Override
    public String work (String work) {
        return "He is working " + work;
    }

    @Override
    public User getUser (User user) {
        user.setName(user.getName() + "-service");
        return user;
    }
}
1234567891011121314151617181920212223

4、添加spring配置文件

<?xml version="1.0" encoding="UTF-8"?>
<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">

    <import resource="applicationContext-jaxws.xml"/>

</beans>

5、配置spring的jax-ws配置文件

<?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:ws="http://jax-ws.dev.java.net/spring/core"
       xmlns:wss="http://jax-ws.dev.java.net/spring/servlet"
       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://jax-ws.dev.java.net/spring/core http://jax-ws.dev.java.net/spring/core.xsd
        http://jax-ws.dev.java.net/spring/servlet http://jax-ws.dev.java.net/spring/servlet.xsd">

    <context:component-scan base-package="com.ws.service.impl" />

    <!-- 绑定webservice地址,需要与web.xml的地址对应 -->
     <!-- 访问:http://localhost:8080/webservice-server-spring-web//ws/userService"?wsdl -->
    <!--alt + enter-->
    <wss:binding url="/ws/userService">
        <wss:service>
            <ws:service bean="#userServiceImpl" />
        </wss:service>
    </wss:binding>

</beans>
1234567891011121314151617181920212223

6、配置web.xml文件

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xmlns="http://java.sun.com/xml/ns/javaee"
         xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
         id="WebApp_ID" version="3.0">

    <!-- needed for ContextLoaderListener -->
    <context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>classpath:applicationContext.xml</param-value>
    </context-param>

    <!-- Bootstraps the root web application context before servlet initialization -->
    <listener>
        <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
    </listener>

    <!-- 用于配置地址栏请求路径 -->
    <servlet>
        <servlet-name>JaxWsServlet</servlet-name>
        <servlet-class>com.sun.xml.ws.transport.http.servlet.WSSpringServlet</servlet-class>
    </servlet>
    <servlet-mapping>
        <servlet-name>JaxWsServlet</servlet-name>
        <url-pattern>/ws/*</url-pattern>
    </servlet-mapping>

</web-app>
12345678910111213141516171819202122232425262728

调用和之前一样

转自https://blog.csdn.net/qq_43842093/article/details/123079151

分类
未分类

服务器意外断电MySQL/Mariadb无法启动日志解决办法

错误信息:2022-04-10 9:58:30 0 [ERROR] InnoDB: Missing FILE_CHECKPOINT at 80579362363 between the checkpoint 80579362363 and the end 80579362304

解决办法:

mv ib_logfile0 ib_logfile0.bak

摘自http://www.22vd.com/70779.html

分类
未分类

查看jdk(java开发工具包)安装路径的方法

查看jdk(java开发工具包)安装路径的方法
下面以操作系统是Windows10计算机为例介绍。

若已经安装好了jdk(java开发工具包),也配置了环境变量,事后却忘了安装路径在哪,如何查看jdk安装路径?

法一、

先执行java -version 指令查看是否已经配置过java了,

如果查到java版本则证明已经安装配置过了,再执行java -verbose指令,会返回很多信息,其中就包含了JDK的安装路径。

这种方法对按装多个jdk,仅能看到第一个,参见下图:

【如何清除命令行窗口内容
输入 cls 回车】

下面的方法可能更好:

法二、

右键此电脑,属性 -> 高级系统设置 -> 环境变量,在“用户变量”(对当前用户起作用)或“系统变量”(对此计算机上所有的用户起作用)找到path行点击选中,点击“编辑”找到带“Java”的部分就是,参见下图:

由图中显示可知,本例中安装了两个了版本的jdk。

顺便指出,用户环境变量优先级高于系统环境变量!系统会先检查用户变量,发现变量名有定义,则用之,而不会再去检查系统变量是否存在,且值为多少。如果用户变量没有定义,再去找系统变量。用户变量优先于系统变量。

延展阅读:用户变量和系统变量的区别 https://www.cnblogs.com/xinxianquan/p/10663756.html
————————————————
版权声明:本文为CSDN博主「软件开发技术爱好者」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/cnds123/article/details/101539053

分类
未分类

App365.club.TcpProxy 1.0.0.1

分类
未分类

Android SSH客户端ConnectBot

https://app365.club/wordpress/ConnectBot_201556.apk

分类
未分类

Linux cron.log设置,使用Linux Cron Job与Logrotate进行日志轮换管理

https://blog.csdn.net/weixin_36002881/article/details/116966945

分类
实用网址

SSCMS 内容管理系统

开源、跨平台、企业级

快速创建在Windows,Linux、Mac或者
Docker上运行的网站及微信公众号

https://sscms.com/

分类
实用网址

Apache ECharts

一个基于 JavaScript 的开源可视化图表库

https://echarts.apache.org/zh/index.html

分类
未分类

How to set up a clean UTF-8 environment in Linux

Many people have problems with handling non-ASCII characters in their programs, or even getting their IRC client or text editor to display them correctly.

To efficiently work with text data, your environment has to be set up properly – it is so much easier to debug a problem which has encoding issues if you can trust your terminal to correctly display correct UTF-8.

I will show you how to set up such a clean environment on Debian Lenny, but most things work independently of the distribution, and parts of it even work on other Unix-flavored operating systems like MacOS X.

Choosing an encoding

In the end the used character encoding doesn’t matter much, as long as it’s a Unicode encoding, i.e. one which can be used to encode all Unicode characters.

UTF-8 is usually a good choice because it efficiently encodes ASCII data too, and the character data I typically deal with still has a high percentage of ASCII chars. It is also used in many places, and thus one can often avoid conversions.

Whatever you do, chose one encoding and stick to it, for your whole system. On Linux that means text files, file names, locales and all text based applications (mutt, slrn, vim, irssi, …).

For the rest of this article I assume UTF-8, but it should work very similarly for other character encodings.

Locales: installing

Check that you have the locales package installed. On Debian you can do that with.

$ dpkg -l locales
Desired=Unknown/Install/Remove/Purge/Hold
| Status=Not/Inst/Cfg-files/Unpacked/Failed-cfg/Half-inst/trig-aWait/Trig-pend
|/ Err?=(none)/Hold/Reinst-required/X=both-problems (Status,Err: uppercase=bad)
||/ Name           Version        Description
+++-==============-==============-============================================
ii  locales        2.7-18         GNU C Library: National Language (locale) da

The last line is the important one: if it starts with ii, the package is installed, and everything is fine. If not, install it. As root, type

$ aptitude install locales

If you get a dialog asking for details, read on to the next section.

Locales: generation

make sure that on your system an UTF-8 locale is generated. As root, type

$ dpkg-reconfigure locales

You’ll see a long list of locales, and you can navigate that list with the up/down arrow keys. Pressing the space bar toggles the locale under the cursor. Make sure to select at least one UTF-8 locale, for example en_US-UTF-8 is usually supported very well. (The first part of the locale name stands for the language, the second for the country or dialect, and the third for the character encoding).

In the next step you have the option to make one of the previously selected locales the default. Picking a default UTF-8 locale as default is usually a good idea, though it might change how some programs work, and thus shouldn’t be done servers hosting sensitive applications.

Locales: configuration

If you chose a default locale in the previous step, log out completely and then log in again. In any case you can configure your per-user environment with environment variables.

The following variables can affect programs: LANG, LANGUAGE, LC_CTYPE, LC_NUMERIC, LC_TIME, LC_COLLATE, LC_MONETARY, LC_MESSAGES, LC_PAPER, LC_NAME, LC_ADDRESS, LC_TELEPHONE, LC_MEASUREMENT, LC_IDENTIFICATION.

Most of the time it works to set all of these to the same value. Instead of setting all LC_ variables separately, you can set the LC_ALL. If you use bash as your shell, you can put these lines in your ~/.bashrc and ~/.profile files:

export LC_ALL=en_US.UTF-8
export LANG=en_US.UTF-8
export LANGUAGE=en_US.UTF-8

To make these changes active in the current shell, source the .bashrc:

$ source ~/.bashrc

All newly started interactive bash processes will respect these settings.

You must restart long-running programs for these changes to take effect.

A Warning about Non-Interactive Processes

There are certain processes that don’t get those environment variables, typically because they are started by some sort of daemon in the background.

Those include processes started from cronat, init scripts, or indirectly spawned from init scripts, like through a web server.

You might need to take additional steps to ensure that those programs get the proper environment variables.

Locales: check

Run the locale program. The output should be similar to this:

LANG=en_US.UTF-8
LANGUAGE=en_US.UTF-8
LC_CTYPE="en_US.UTF-8"
LC_NUMERIC="en_US.UTF-8"
LC_TIME="en_US.UTF-8"
LC_COLLATE="en_US.UTF-8"
LC_MONETARY="en_US.UTF-8"
LC_MESSAGES="en_US.UTF-8"
LC_PAPER="en_US.UTF-8"
LC_NAME="en_US.UTF-8"
LC_ADDRESS="en_US.UTF-8"
LC_TELEPHONE="en_US.UTF-8"
LC_MEASUREMENT="en_US.UTF-8"
LC_IDENTIFICATION="en_US.UTF-8"
LC_ALL=en_US.UTF-8

If not you’ve made a mistake in one of the previous steps, and need to recheck what you did.

Setting up the terminal emulator

Setting up the terminal emulator for your terminal emulator strongly depends on what you actually use. If you use xterm, you can start it as xterm -en utf-8konsole and the Gnome Terminal can be configured in their respective configuration menus.

Testing the terminal emulator

To test if you terminal emulator works, copy and paste this line in your shell:

perl -Mcharnames=:full -CS -wle 'print "\N{EURO SIGN}"'

This should print a Euro sign  on the console. If it prints a single question mark instead, your fonts might not contain it. Try installing additional fonts. If multiple different (nonsensical) characters are shown, the wrong character encoding is configured. Keep trying :-).

SSH

If you use SSH to log in into another machine, repeat the previous steps, making sure that the locale is set correctly, and that you can view a non-ASCII character like the Euro sign.

Screen

The screen program can work with UTF-8 if you tell it to.

The easiest (and sometimes the only) way is to start it with the -U option:

$ screen -U

and also when detaching (screen -Urd or so).

Inside a running screen you can try Ctrl+a :utf8 on<return>. If that doesn’t work, exit your screen and start a new one with -U

Irssi

There’s a complete guide for setting up irssi to use UTF-8, which partially overlaps with this one. The gist is:

/set term_charset utf-8
/set recode_autodetect_utf8 ON
/set recode_fallback ISO-8859-15
/set recode ON

转自https://perlgeek.de/en/article/set-up-a-clean-utf8-environment

分类
未分类

查看crontab日志

CentOS: tail -f /var/log/cron

Ubuntu: tail -f /var/log/cron.log

注:Ubuntu 默认没有开启cron log.

在/etc/rsyslog.d/50-default.conf文件中取消#cron.* /var/log/cron.log注释符号#, 并重启rsyslog

sudo service rsyslog restart