Ubuntu 20.04LTS开发环境/node14.17/Ruby2.7.3/Python3.8.5/OpenJDK11/Tomcat10/Solr8.8.2

最近把自己本地的VM重新安装配置了一下,主要是Ubuntu升级到20.04LTS, Node.js 14.17, Ruby 2.7.3, Python 3.8.5, OpenJDK 11, Tomcat 10, Solr 8.8.2。下面记录一下:

image
Source: Pixabay

基本环境

安装好VM后注意在VirtualBox配置Port forwarding.

运行:

sudo apt-get install -y build-essential libssl-dev libreadline-dev zlib1g-dev

zsh

sudo apt-get install zsh
sudo usermod -s /bin/zsh $(whoami)

重新登录后选择2)配置好zsh,然后安装oh-my-zsh:

sh -c "$(wget https://raw.githubusercontent.com/robbyrussell/oh-my-zsh/master/tools/install.sh -O -)"

Node.js 14.17.0

curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.38.0/install.sh | zsh
source .zshrc
nvm list-remote
nvm install v14.17.0

Ruby 2.7.3

rbenv

  git clone git://github.com/sstephenson/rbenv.git .rbenv
echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.zshrc
echo 'eval "$(rbenv init -)"' >> ~/.zshrc
git clone git://github.com/sstephenson/ruby-build.git ~/.rbenv/plugins/ruby-build
echo 'export PATH="$HOME/.rbenv/plugins/ruby-build/bin:$PATH"' >> ~/.zshrc
source .zshrc

Ruby

rbenv install -v 2.7.3
rbenv global 2.7.3

Python 3.8.5

sudo apt install python3-pip
sudo apt-get install python3-venv
python3 -m venv myenv

将如下语句添加到.zshrc:

source myenv/bin/activate

Java

OpenJDK 11

sudo apt install default-jdk 
sudo nano /etc/environment

Add:

JAVA_HOME="/usr/lib/jvm/java-11-openjdk-amd64"

Tomcat 10

Run:

sudo groupadd tomcat
sudo useradd -s /bin/false -g tomcat -d /opt/tomcat tomcat
cd /tmp
curl -O https://mirrors.ukfast.co.uk/sites/ftp.apache.org/tomcat/tomcat-10/v10.0.6/bin/apache-tomcat-10.0.6.tar.gz
sudo mkdir /opt/tomcat
sudo tar xzvf apache-tomcat-10.0.6.tar.gz -C /opt/tomcat --strip-components=1
cd /opt/tomcat
sudo chgrp -R tomcat /opt/tomcat
sudo chmod -R g+r conf
sudo chmod g+x conf
sudo chown -R tomcat webapps/ work/ temp/ logs/

添加tomcat服务:

sudo nano /etc/systemd/system/tomcat.service

添加如下内容:

[Unit]
Description=Apache Tomcat Web Application Container
After=network.target

[Service]
Type=forking

Environment=JAVA_HOME=/usr/lib/jvm/java-11-openjdk-amd64
Environment=CATALINA_PID=/opt/tomcat/temp/tomcat.pid
Environment=CATALINA_HOME=/opt/tomcat
Environment=CATALINA_BASE=/opt/tomcat
Environment='CATALINA_OPTS=-Xms512M -Xmx1024M -server -XX:+UseParallelGC'
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

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

[Install]
WantedBy=multi-user.target

Reload system daemon:

sudo systemctl daemon-reload

Start Tomcat:

sudo systemctl start tomcat

Test if you can access Tomcat via port 8080, then enable this service:

sudo systemctl enable tomcat

Configure Tomcat web admin UI:

sudo nano /opt/tomcat/conf/tomcat-users.xml

内容如下:

<?xml version="1.0" encoding="UTF-8"?>
<tomcat-users xmlns="http://tomcat.apache.org/xml"
              xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
              xsi:schemaLocation="http://tomcat.apache.org/xml tomcat-users.xsd"
              version="1.0">
  <role rolename="manager-gui"/>
  <user username="tomcat" password="PASSWORD" roles="manager-gui"/>

  <role rolename="admin-gui"/>
  <user username="admin" password="PASSWORD" roles="admin-gui"/>
</tomcat-users>   

默认方式下,tomcat针对admin页面添加了IP限制。可以通过以下文件将其注释掉:

sudo nano /opt/tomcat/webapps/manager/META-INF/context.xml

Solr8.8.2

cd /tmp
wget https://mirrors.ukfast.co.uk/sites/ftp.apache.org/lucene/solr/8.8.2/solr-8.8.2.tgz
tar xvf solr-8.8.2.tgz
cd solr-8.8.2/bin
sudo ./install_solr_service.sh ../../solr-8.8.2.tgz

创建一个core:

sudo su - solr -c "/opt/solr/bin/solr create -c your_core -n data_driven_schema_configs"

测试Solr:

sudo service solr status

安装并使用zsh

最近开始使用zsh,感觉比Linux系统默认的bash要好用太多了,尤其对于经常使用git的各位程序猿来说,提供了很多额外的提示,比如,当前的branch,是否有未提交更改,以及各种快捷命令等等。强烈推荐!下面把安装步骤介绍一下:

zsh

阅读更多

最近遇到的一个Cron job的坑

Cron job

最近写了一个Python程序,将其添加到了cronjob中,希望让其定期自动运行,但一直不能正常工作。其实在这之前一直在使用cronjob,也从没遇到过什么问题,因此感觉肯定是一个很初级的错误导致的。 下面把这次排错的经历记录一下。

阅读更多