How should I configure the server after spending 288 for three years

preface

The ECS that Alibaba cloud bought for 95 yuan is about to expire. It needs more than 1000 to renew. I thought there was nothing important on the server, so I took advantage of Tencent cloud discount and spent 288 to buy a three-year CVM. CVM is a cloud virtual machine. Let's call it a server for the time being.

1 core 2G, it seems that nothing can be done. But as a test environment, it can actually do a lot of things. Before buying, people around me advised me to install virtual machines, but I really didn't want to drive VMware every day, and I didn't want to toss my computer, so 288 didn't lose money!

Since it is a new server, the necessary development environment still needs to be done, so this article mainly records the operation. By the way, the operating system is CentOS 7.

Host operation

Building mutual trust

Every time you log in to ECS via ssh on your laptop, you have to enter your password, which is very annoying. Therefore, it is necessary to establish mutual trust and realize password free login.

I use MacBook, code A here, server code B, and put / ID in ssh directory_ rsa. The content in pub (i.e. public key) is copied to / Authorized in ssh directory_ In the keys file, you can establish mutual trust and realize ssh secret free login.

The. ssh directory structure is as follows:

If there is no public key, you can use the following command to generate it.

ssh-keygen -t rsa -f ~/.ssh/id_dsa -P ""

If I don't want to paste and copy the public key to host B, I can use the following command to append the public key content to authorized_keys.

ssh-copy-id root@172.27.xxx.xxx

The above two methods can achieve mutual trust.

Modify hostname

Both Tencent cloud and Alibaba cloud will generate hostname by default.

The hostname can be modified to what you want through the following two methods.

# 1. Method 1
vi /etc/hostname
# Write codeonthe Road,: wq save exit
hostname -F /etc/hostname

# 2. Method 2
hostname -b CodeOnTheRoad

Select one of the above operations, then exit and log in again, and the modification takes effect:

Set security group

Delete the original security group, configure new security rules, and only open some commonly used ports.

If you want to do it once and for all, you can open all ports.

development environment

Java

Download the JDK of linux system from the official website.

# Put the downloaded jdk in / usr/local and unzip it
tar zxvf jdk1.8.0_131.tar.gz 
vi /etc/profile
# Add the following two lines at the end of the file
export JAVA_HOME=/usr/local/jdk1.8.0_131
export PATH=$PATH:$JAVA_HOME/bin
# Refresh profile
source /etc/profile

You can edit ~ / bash_profile only configures the java environment of the current user.

Test for successful installation:

Python

# When making install, install what is missing according to the prompt
yum -y intall zlib zlib-devel libffi-devel tk-devel
# download
wget https://www.python.org/ftp/python/3.9.4/Python-3.9.4.tar.xz
tar xvf Python-3.9.4.tar.xz 
cd Python-3.9.4
# Generate Makefile, compile and install
./configure --prefix=/usr/local/python3.9 --enable-optimizations
make & make install

Enter the / usr/local/bin directory and set the global command through soft connection.

ln -s /usr/local/python3.9/bin/python3 python3
ln -s /usr/local/python3.9/bin/pip3 pip3

Enter python3 to test whether the installation is successful:

~/pip/pip. The download image has been configured in conf, ECS is alicloud image and CVM is Tencent cloud image, so we don't need to configure it ourselves.

docker

# install
yum -y install docker
# start-up
systemctl start docker.service
# Power on self start
systemctl enable docker.service
# verification
docker info

git

Here I configure gitee code cloud.

yum -y install git

Log in to gitee, enter settings, and set the linux ID_ rsa. Add the public key in pub to the SSH public key.

Test with ssh command:

ssh -T git@gitee.com

The test results are as follows: the configuration is successful:

Application software

mysql

# install
yum -y install mysql-community-server
# start-up
systemctl start mysqld

Enter mysql and set the password:

set password for 'root'@'%' = password('1qaz@WSX');

Every time you log in, you need to specify the password through - p. it's troublesome to say, so here you need to configure database password free login: create it in the user directory my.cnf file, add the following.

[client]
  host=localhost
  user='root'
  password='your password'

Pre and post security free test:

redis

 wget https://download.redis.io/releases/redis-6.2.2.tar.gz
 tar zxvf redis-6.2.2.tar.gz 
 cd redis-6.2.2
 make

After compiling, enter the src directory, and you will find that there are many commands beginning with redis. Create a new subdirectory of redis and bin, and create a new subdirectory of redis and conf.

redis. Put conf into conf. At this point, you can delete the previous source file directory.

Enter the bin and start the redis single node for testing without modifying any configuration.

./redis-server ../conf/redis.conf  &
./redis-cli 
# test
127.0.0.1:6379> set test 1
OK
127.0.0.1:6379> get test
"1"

nginx

# download
wget http://nginx.org/download/nginx-1.20.0.tar.gz
tar zxvf nginx-1.20.0.tar.gz
# Generate Makefile
cd nginx-1.20.0
./configure --prefix=/usr/local/nginx
# Compile and install
make & make install

When generating the Makefile of nginx, if HTTP is prompted_ rewrite_ Module module failed due to lack of pcre dependency. There are two solutions:

Method 1: disable the module

./configure --prefix=/usr/local/nginx --without-http_rewrite_module

Method 2: install pcre

# Download pcre
wget https://ftp.pcre.org/pub/pcre/pcre-8.44.tar.bz2
tar xvf pcre-8.44.tar.bz2 
# Specify pcre when generating Makefile
./configure --prefix=/usr/local/nginx --with-pcre=../pcre-8.44

Through the above two methods, the problem of pcre dependency can be solved, and the Makefile can be generated successfully to complete the compilation

tomcat

Download and unzip it, and then configure and start it as needed.

wget https://mirrors.bfsu.edu.cn/apache/tomcat/tomcat-8/v8.5.65/bin/apache-tomcat-8.5.65.tar.gz
tar zxvf apache-tomcat-8.5.65.tar.gz

conclusion

The above are some commonly used development environments and application software. I wrote an article before configuring nginx load balancing based on docker. If you are interested in installing redis cluster based on docker, you will write a separate article later.

At one o'clock in the night, the lights are still dim outside the window. The stars are shining and say good night. May you sleep in spring all night and have a good dream, looking forward to the next meeting.


Post-95 young programmers write about personal practice in daily work. From the perspective of beginners, they write from 0 to 1, detailed and serious. The article will start with the official account, and expect your attention.

Keywords: Linux MySQL server Cloud Server

Added by dch27 on Sun, 20 Feb 2022 19:06:18 +0200