Mostrando postagens com marcador Linux. Mostrar todas as postagens
Mostrando postagens com marcador Linux. Mostrar todas as postagens

sexta-feira, 8 de junho de 2018

Como excluir arquivos mais antigos do que X dias no Linux


Muitas vezes precisamos executar rotinas de limpeza em nossos computadores, de forma a excluir arquivos que não são mais utilizados para liberar espaço para novos arquivos. E, em alguns casos, priorizamos excluir os arquivos mais antigos.
Para excluir os documentos mais antigos do que um determinado número de dias no Linux, use o comando a seguir:
?
1
find /path/to/files* -mtime +X -exec rm {} \;
Em que:
  • /path/to/files é o diretório onde você pretende procurar e excluir os arquivos;
  • é o tempo de modificação dos arquivos. Significa que estamos procurando todos documentos cuja última modificação foi feita há mais de X dias.
Caso quiséssemos excluir todos arquivos dentro do diretório /home/drall cuja última modificação foi feita há 90 dias, usaríamos o seguinte comando:
?
1
find /home/drall -mtime +90 -exec rm {} \;

terça-feira, 20 de março de 2018

How to install Tomcat 8.5 on Debian 9 / Ubuntu 16.04 / Linux Mint 18

Requirement

First, switch to the root user.
su -
OR
sudo su -
Tomcat requires Java JDK to be installed on the machine. You can either install Oracle JDK or OpenJDK.
For this demo, I am going with OpenJDK.
apt-get -y install openjdk-8-jdk
Once Java is installed, you can verify the Java version by using the following command.
java -version
Output:
openjdk version "1.8.0_141"
OpenJDK Runtime Environment (build 1.8.0_141-8u141-b15-1~deb9u1-b15)
OpenJDK 64-Bit Server VM (build 25.141-b15, mixed mode

For best practice, Tomcat should never be run as privileged user (root). So, create a low-privilege user for running the Tomcat service.
groupadd tomcat
mkdir /opt/tomcat
useradd -g tomcat -d /opt/tomcat -s /bin/nologin tomcat
or
useradd -s /bin/false -g tomcat -d /opt/tomcat tomcat

Download & Configure Apache Tomcat

You can download the latest version of the Apache Tomcat from the official website.
wget http://www-us.apache.org/dist/tomcat/tomcat-8/v8.5.27/bin/apache-tomcat-8.5.27.tar.gz
Extract the tomcat on to your desired (/opt/tomcat) directory.
tar -zxvf apache-tomcat-*.tar.gz
mv apache-tomcat-8.5.27/* /opt/tomcat/
Change the ownership of the extracted directory so that tomcat user can write files to it.
chown -R tomcat:tomcat /opt/tomcat/

chmod +x /opt/tomcat/bin/*.sh 

Change the add in /etc/bash.bashrc  and /etc/profile  and /etc/environment
# Variaveis Java
JAVA_HOME=/usr/lib/jvm/java-8-oracle
CATALINA_HOME=/opt/tomcat
export JAVA_HOME
JRE_HOME=$JAVA_HOME/jre
export JRE_HOME
#PATH=$PATH:$JAVA_HOME/bin:$JRE_HOME/bin:
#export PATH
export CATALINA_HOME


Controlling Apache Tomcat

Manual

You can start and stop the Tomcat using the script which comes along with the package.
To start Tomcat service, go to the Tomcat directory and run:
cd /opt/tomcat/bin/
sh startup.sh
Output:
Using CATALINA_BASE:   /opt/tomcat
Using CATALINA_HOME:   /opt/tomcat
Using CATALINA_TMPDIR: /opt/tomcat/temp
Using JRE_HOME:        /usr
Using CLASSPATH:       /opt/tomcat/bin/bootstrap.jar:/opt/tomcat/bin/tomcat-juli.jar
Tomcat started.
To stop Tomcat service, run:
sh shutdown.sh

Change the ownership of the extracted directory so that tomcat user can write files to it.


chown -R tomcat:tomcat /opt/tomcat/

Systemd

We can also configure systemd to start the Tomcat service. Skip the below step in case you do not want to use systemd for managing Tomcat service.
Create a tomcat systemd service file. Green ones depend on the environmentso change them accordingly.
nano /etc/systemd/system/tomcat.service
Add the below information to Tomcat systemd service file.
[Unit]
Description=Apache Tomcat 8.x Web Application Container
Wants=network.target
After=network.target

[Service]
Type=forking

Environment=JRE_HOME=/usr/lib/jvm/java-8-oracle/jre
Environment=CATALINA_PID=/opt/tomcat/temp/tomcat.pid
Environment=CATALINA_HOME=/opt/tomcat
Environment='CATALINA_OPTS=-Xms512M -Xmx1G -Djava.net.preferIPv4Stack=true'
Environment='JAVA_OPTS=-Djava.awt.headless=true -Djava.security.egd=file:/dev/./urandom'

ExecStart=/opt/tomcat/bin/startup.sh
ExecStop=/opt/tomcat/bin/shutdown.sh
SuccessExitStatus=143

User=tomcat
Group=tomcat
UMask=0007
RestartSec=10
Restart=always

[Install]
WantedBy=multi-user.target
Reload systemd daemon.
systemctl daemon-reload
To start the Tomcat service; run:
systemctl start tomcat
Check the status of Tomcat, run:
systemctl status tomcat
Enable the auto start of Tomcat service on system boot:
systemctl enable tomcat

Verify Apache Tomcat
By default, Tomcat runs on port 8080. Use can use the netstat command to check the port status.
netstat -antup | grep 8080
or
netstat -plntu | grep 8080
Output:
tcp        0      0 0.0.0.0:8080            0.0.0.0:*               LISTEN      12224/java


Firewall

You may need to allow Tomcat server requests in the firewall so that we can access the application from the external network.
ufw allow 8080

Configure Apache Tomcat Web UI

Tomcat comes with the web-manager and Host Manager for managing Tomcat. Both Host Manager and Web Manager are password protected, and it requires a username and password to access.
Only the user with the manager-gui and admin-gui role is allowed to access web manager and host-manager respectively. Those two roles are defined in tomcat-users.xml file.
nano /opt/tomcat/conf/tomcat-users.xml
Place the following two lines (role and user definition) just above the last line.
manager-gui,admin-gui"/>
tomcat" password="admin" roles="manager-gui,admin-gui"/>

For security reason, Web Manager and Host Manager is accessible only from the localhost, ie, from the server itself.
If you want to access managers from the remote system then you need to add your source network in allow list. To do that, edit the below two files.
nano /opt/tomcat/webapps/manager/META-INF/context.xml

nano /opt/tomcat/webapps/host-manager/META-INF/context.xml
Update the below line on both files with source IP from which your accessing the Web and Host Manager. .* will allow everyone to have access to managers.
allow="127\.\d+\.\d+\.\d+|::1|0:0:0:0:0:0:0:1|.*" />
OR
You can allow only part of your network. For example, to allow only 192.168.0.0/24 network, you can use the below values.
allow="127\.\d+\.\d+\.\d+|::1|0:0:0:0:0:0:0:1|192.168.*" />
Restart the Tomcat service.
systemctl restart tomcat


netstat Command not found on Debian 9 / Ubuntu / Linux Mint – Quick Fix


netstat is a command line tool to view the network connection statistics to/from the machine. With netstat, you can see network connections, routing tables, interface statistics, masquerade connections, and multicast memberships.
Are you facing netstat command not found issue after the installation Debian 9 / Ubuntu / Linux Mint.
-bash: netstat: command not found
Here is the small guide to install the necessary package for getting netstat command. Let us see which package provides us netstat command.
apt-file search --regexp '/netstat$'
Output:
net-tools: /bin/netstat
From the above command, you can see that net-tools package provides you netstat command. So, install the net-toolspackage using the apt-get command.
apt-get install -y net-tools
Output:
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following NEW packages will be installed:
 net-tools
0 upgraded, 1 newly installed, 0 to remove and 98 not upgraded.
Need to get 248 kB of archives.
After this operation, 963 kB of additional disk space will be used.
Get:1 http://deb.debian.org/debian stretch/main amd64 net-tools amd64 1.60+git20161116.90da8a0-1 [248 kB]
Fetched 248 kB in 0s (422 kB/s)
Selecting previously unselected package net-tools.
(Reading database ... 131147 files and directories currently installed.)
Preparing to unpack .../net-tools_1.60+git20161116.90da8a0-1_amd64.deb ...
Unpacking net-tools (1.60+git20161116.90da8a0-1) ...
Processing triggers for man-db (2.7.6.1-2) ...
Setting up net-tools (1.60+git20161116.90da8a0-1) ...
Once the installation is complete. Run netstat to see whether it is available or not.
netstat
Output:
Active Internet connections (w/o servers)
Proto Recv-Q Send-Q Local Address           Foreign Address         State
tcp        0      0 mydebian:ssh            192.168.1.5:55051       ESTABLISHED
tcp        0      0 mydebian:ssh            192.168.1.6:55368       ESTABLISHED
tcp        0     64 mydebian:ssh            192.168.1.6:55660       ESTABLISHED
Active UNIX domain sockets (w/o servers)
Proto RefCnt Flags       Type       State         I-Node   Path
unix  2      [ ]         DGRAM                    16007    /run/user/119/systemd/notify
unix  2      [ ]         DGRAM                    9360     /run/systemd/journal/syslog
unix  2      [ ]         DGRAM                    17319    /run/user/1000/systemd/notify
unix  3      [ ]         DGRAM                    9176     /run/systemd/notify
unix  2      [ ]         DGRAM                    9178     /run/systemd/cgroups-agent
unix  28     [ ]         DGRAM                    9190     /run/systemd/journal/dev-log
unix  8      [ ]         DGRAM                    9208     /run/systemd/journal/socket
unix  3      [ ]         STREAM     CONNECTED     23927    /run/user/1000/bus
unix  3      [ ]         STREAM     CONNECTED     22423    /run/systemd/journal/stdout
unix  3      [ ]         STREAM     CONNECTED     26620    /run/user/1000/bus
unix  3      [ ]         STREAM     CONNECTED     25601
unix  3      [ ]         STREAM     CONNECTED     23390    /run/systemd/journal/stdout
unix  3      [ ]         STREAM     CONNECTED     23284    /run/user/1000/bus
unix  3      [ ]         STREAM     CONNECTED     23270
unix  3      [ ]         STREAM     CONNECTED     23043
unix  3      [ ]         STREAM     CONNECTED     24356    /var/run/dbus/system_bus_socket
unix  3      [ ]         STREAM     CONNECTED     131096   /var/run/dbus/system_bus_socket
unix  3      [ ]         STREAM     CONNECTED     23046    /run/user/1000/bus
netstat Command not found on Debian - netstat command output
netstat Command not found on Debian – netstat command output
That’s All. You now have netstat command on your machine.

segunda-feira, 19 de março de 2018

Cor Color Bash Prompt Debian


Green Prompt for your user


Edit ”~/.bashrc” and change:
#force_color_prompt=yes
to:
force_color_prompt=yes
To change it for all new users make the same in ”/etc/skel/.bashrc”.

Red Prompt for root


Edit ”/root/.bashrc” and change ”force_color_prompt=yes” like for your user.
Now change the color to red. Search this line:
PS1='${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\$ '
and change it to:
PS1='${debian_chroot:+($debian_chroot)}\[\033[01;31m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\$ '
Note: For this change to take effect, you must log out then log in again.

Debian (older versions)

Green Prompt for your user

Open ”~/.bashrc” and append:
PS1='${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\$ '

Red Prompt for root

Edit ”/root/.bashrc” and append:
PS1='${debian_chroot:+($debian_chroot)}\[\033[01;31m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]$ '

Other colors

Color Code
Black 30
Red 31
Green 32
Brown 33
Blue 34
Purple 35
Cyan 36
Light Gray 37 

Here are the rest of the colour equivalences:

Black       0;30     Dark Gray     1;30
Blue        0;34     Light Blue    1;34
Green       0;32     Light Green   1;32
Cyan        0;36     Light Cyan    1;36
Red         0;31     Light Red     1;31
Purple      0;35     Light Purple  1;35
Brown       0;33     Yellow        1;33
Light Gray  0;37     White         1;37

sábado, 10 de fevereiro de 2018

Lentidao Lerdeza performance do RDP no windows server 2008 R2 e 2012 R2 em VM maquina virtuais Vmware e Proxmox


Slow RDP performance on Windows 2008 R2 and 2012 R2 servers running on VMware and Proxmox

We were running several Windows 2012 R2 servers on a VMware ESX environment. And still, we experience a sluggish performance on the Windows 2012R2 server when connection them with any RDP-client. We tried different connections (wifi, 4G, LAN, etc.) and different clients (Windows 10 RDP, RoyalTS, Mac-RDP, etc.). The hardware could’t be a factor in the issue. So we searched to some finetune-settings in GPO and registry.

The hardware wasn’t an issue.

the servers did’t have a high overall load
there was no high CPU load
there was enough RAM
we used 15k HP SAS enterprise disks
there was no high IO
we had Teamed the NICs in VMware


This is what we did to solve the issue and get very fast RDP-performance.


Finetune “Remote Desktop Services” in Group Policy


Just wanted to post this for anyone else experiencing this issue. Seems the issue does not effect Windows Server 2012 R2, and turns out it might be related to the UDP packets getting fragmenting when creating a RDP session. Here’s the fix:


open prompt DOS:  gpedit.msc 





Computer Config > Windows Settings  > Administrative Templates > Windows  Components  > Remote Desktop Services > Remote Desktop Session Host >  Connections >  Select RDP transport protocol = Use only TCP











You can also set this on the client side by specifying:

Computer Config > Windows Settings > Admin Templates > Windows Components > Remote Desktop Services > Remote Desktop Connection Client > Turn off UDP on Client = Enabled











Disabling TCP Offloading in Windows Server 2012
We also add below registry setting to improve performance. A little explanation of TCP Offloading:

“TCP offload engine is a function used in network interface cards (NIC) to offload processing of the entire TCP/IP stack to the network controller. By moving some or all of the processing to dedicated hardware, a TCP offload engine frees the system’s main CPU for other tasks. However, TCP offloading has been known to cause some issues, and disabling it can help avoid these issues.”


----------  2º second option -----------


This is what you must do in the Registry (regedit)




1. Open RegEdit on the Windows Server machine.

2. Navigate to this registry key in the tree on the left:

3. HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters

4. Right-click on the right side, and add a new DWORD (32-bit) Value

5. Set the value name to DisableTaskOffload and the value data to 1

6. Reconnect to the Server via RDP (to a new session) and your performance should be normal.










*-------------------------------------------------------------------------------------------------*


On the Windows Server 2012 machine, disable the Large Send Offload via the following steps:

a. Open Network Connections.

b. Right-click the icon of the NIC which is responsible for the connection to terminal clients and select Properties.

c. In Networking tab, click Configure… button.

d. In the next window, switch to Advanced tab.

e. Click the Large Send Offload Version 2 (IPv4) and change the value to Disabled.