CentOS 7 安装 Tomcat

rpm -qa | grep java
rpm -e --nodeps java-1.8.0-openjdk-1.8.0.141-1.b16.el7_3.x86_64
rpm -e --nodeps java-1.8.0-openjdk-headless-1.8.0.141-1.b16.el7_3.x86_64
rpm -e --nodeps java-1.7.0-openjdk-1.7.0.141-2.6.10.1.el7_3.x86_64
rpm -e --nodeps java-1.7.0-openjdk-headless-1.7.0.141-2.6.10.1.el7_3.x86_64

http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html

wget http://download.oracle.com/otn-pub/java/jdk/8u144-b01/090f390dda5b47b9b721c7dfaa008135/jdk-8u144-linux-x64.rpm
rpm -ivh jdk-8u144-linux-x64.rpm

vim /etc/profile
export JAVA_HOME=/usr/java/jdk1.8.0_144
export JRE_HOME=${JAVA_HOME}/jre
export CLASSPATH=.:${JAVA_HOME}/lib:${JRE_HOME}/lib
export PATH=${JAVA_HOME}/bin:${PATH}

source /etc/profile

java -version




http://tomcat.apache.org/download-80.cgi
wget http://mirrors.tuna.tsinghua.edu.cn/apache/tomcat/tomcat-8/v8.5.20/bin/apache-tomcat-8.5.20.tar.gz
tar -xvzf apache-tomcat-8.5.20.tar.gz
mv apache-tomcat-8.5.20 /usr/local/

启动Tomcat:
/usr/local/apache-tomcat-8.5.20/bin/startup.sh
关闭Tomcat:
/usr/local/apache-tomcat-8.5.20/bin/shutdown.sh

为Tomcat添加服务:
在Tomcat的安装目录下的bin目录下增加setenv.sh文件:
vi /usr/local/apache-tomcat-8.5.20/bin/setenv.sh
#set JAVA_HOME and JRE_HOME and CATALINA_HOME and CATALINA_BASE
export JAVA_HOME=/usr/java/jdk1.8.0_144
export JRE_HOME=/usr/java/jdk1.8.0_144/jre
export CATALINA_HOME=/usr/local/apache-tomcat-8.5.20
export CATALINA_BASE=/usr/local/apache-tomcat-8.5.20
#set JAVA_HOME and JRE_HOME and CATALINA_HOME and CATALINA_BASE

#add tomcat pid
CATALINA_PID="$CATALINA_BASE/tomcat.pid"
#add Java opts
JAVA_OPTS="-server -XX:PermSize=256M -XX:MaxPermSize=1024m -Xms512M -Xmx1024M -XX:MaxNewSize=256m"


创建tomcat.service文件:
vi /usr/lib/systemd/system/tomcat.service
[Unit]
Description=Apache Tomcat 8.5.20
After=syslog.target network.target remote-fs.target nss-lookup.target

[Service]
Type=forking
PIDFile=/usr/local/apache-tomcat-8.5.20/tomcat.pid
ExecStart=/usr/local/apache-tomcat-8.5.20/bin/startup.sh
ExecReload=/bin/kill -s HUP $MAINPID
ExecStop=/bin/kill -s QUIT $MAINPID
PrivateTmp=true

[Install]
WantedBy=multi-user.target


然后可以执行如下命令来检验是否配置正确:
systemctl enable tomcat.service
systemctl disable tomcat.service
systemctl start tomcat.service
systemctl stop tomcat.service
systemctl restart tomcat.service

出现403 Access Denied
By default the Host Manager is only accessible from a browser running on the same machine as Tomcat
vi /usr/local/apache-tomcat-8.5.20/webapps/manager/META-INF/context.xml


vi /usr/local/apache-tomcat-8.5.20/conf/tomcat-users.xml




systemctl restart tomcat

管理页面:
http://127.0.0.1:8080

代码部署:
1.利用Tomcat自动部署
将WebSitexxx目录拷贝到$CATALINA_HOME/webapps下
/usr/local/apache-tomcat-8.5.20/webapps/WebSitexxx/
访问地址如下:http://localhost:8080/WebSitexxx/

2.修改Server.xml文件部署
更改$CATALINA_HOME/conf/server.xml文件,
vi /usr/local/apache-tomcat-8.5.20/conf/server.xml
编辑Host节点:


CentOS 7 安装 ElasticSearch

wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-5.6.0.rpm
rpm --install elasticsearch-5.6.0.rpm
systemctl enable elasticsearch
systemctl start elasticsearch

报错:
Java HotSpot(TM) 64-Bit Server VM warning: INFO: os::commit_memory(0x000000008a660000, 1973026816, 0) failed; error='Cannot allocate memory' (errno=12)
#
# There is insufficient memory for the Java Runtime Environment to continue.
# Native memory allocation (mmap) failed to map 1973026816 bytes for committing reserved memory.
# An error report file with more information is saved as:
# /root/elasticsearch-5.6.0/hs_err_pid19703.log
vi /etc/elasticsearch/jvm.options
或
vi config/jvm.options
-Xms2g
-Xmx2g
修改为:
-Xms256m
-Xmx256m

./bin/elasticsearch

curl --proxy "" http://localhost:9200/?pretty

修改Elasticsearch的配置,使其支持外网访问:
vi config/elasticsearch.yml
network.host: 0.0.0.0

报错:
Exception in thread "main" java.lang.RuntimeException: don't run elasticsearch as root
添加专门的用户
useradd elastic
passwd elastic
chown -R elastic:elastic elasticsearch-5.6.0/

报错:
max virtual memory areas vm.max_map_count [65530] is too low, increase to at least [262144]
修改/etc/sysctl.conf配置文件
cat /etc/sysctl.conf | grep vm.max_map_count
vm.max_map_count=262144
如果不存在则添加
echo "vm.max_map_count=262144" >>/etc/sysctl.conf
sysctl -p