Linux Environment Configuration

Environment Configuration

Linux

0 .vimrc

#Create a new file in your own directory (~). vimrc
vim ~/.vimrc
#Add a text configuration (as follows...
#Indicates how many spaces a tab shows by default 8
set tabstop=2 
#Represents the length of the indentation that falls back when the backspace key is pressed in edit mode
set softtabstop=2 
#Represents the length of each level of indentation, typically set to be the same as softtabstop
set shiftwidth=2 
#Indicates that a tab represents an indent
set noexpandtab 
#set nu
set nu  
#Represents automatic indentation
set autoindent 
#Represents automatic indentation for C
set cindent
source ~/.vimrc
#... Enter a file (cd ~/.vimrc) and see the changes

1 JavaSE Development Kit

1-1 Download Folder (/opt)

mkdir java	#Create a Java folder
cd java
#... (Upload zipped package to Java folder)
tar -zxvf jdk-8u321-linux-x64.tar.gz	#Unzip tar.gz compression package
mv jdk-8u321-linux-x64 JDK8	 #Rename the folder'JDK8'(at your discretion)

Common decompression/compression commands

#.tar
tar -xvf FileName.tar	#Unpack
tar -cvf FileName.tar DirName #Packaging (separate from the concept of'compression')
#.tar.gz and. tgz
tar -zxvf FileName.tar.gz #decompression
tar zcvf FileName.tar.gz DirName #compress

1-2 software folder (/usr/local/software)

mkdir java
mv /opt/java/JDK8 ./java/

1-3 Profile Modification Environment Variables (/etc/profile)

vim /etc/profile

#... (enter configuration file)
#Press shitf g to enter the end of the file
#Add environment variables at the end of the file

export JAVA_HOME=/usr/local/software/java/JDK8 #Set JAVA_HOME environment variable
export PATH=$PATH:$JAVA_HOME/bin #Add JAVA_HOME into PATH

#Esc exits edit mode, enter':wq'to save edits and exit

source /etc/profile	#Reload the configuration file for the changes to take effect

1-4 View Java environment variables

java -version
javac -version #Successful display of the JDK version indicates that the environment variable is valid

2 Mysql

2-1 Uninstall MariaDB

rpm -qa | grep mariadb #Query whether'mariadb'is installed
rpm -e mariadb-libs-5.5.60-1.el7_5.x86_64 --nodeps #Delete related packages: This name is the related packages queried above. Package deletion requires some dependencies,'nodeps'means compulsory deletion regardless of dependencies
rm -rf /etc/my.cnf #Delete profile:'mariadb'also has a profile with the same name as mysql installation and needs to be deleted
rm -rf /var/lib/mysql/ #Delete data catalog: Delete on reference network, no mysql data catalog under my own lib

Installation of 2-2 MySQL

Decompression and Moving of 2-2-1 Compressed Packets
#Create a MySQL directory in the download folder, upload and unzip MySQL's official zip packages, and rename the unzipped folder
cd /opt #Enter/opt
mkdir mysql
#... (Upload Compressed Packet)
#Tips: MySQL officially has three compression packages, one is. tar.gz, one is -test-***. tar. Sum of GZ and containing both. tar compressed package. If it is downloaded. tar package, you need to uncompress this to get it first. tar.gz package, and decompress this
tar -zxvf mysql-5.7.37-linux-glibc2.12-x86_64.tar.gz
mv mysql-5.7.37-linux-glibc2.12-x86_64 mysql-5.7

#Create a MySQL directory in the software folder, create a data directory in the directory, and move the unzipped folder to the MySQL directory in the software folder
cd /usr/local/software
mkdir mysql
cd mysql
mkdir data
mv /opt/mysql/mysql-5.7 ./
2-2-2 Create user groups and users and modify permissions
groupadd mysql #Create User Groups
useradd -r -g mysql mysql #Create user mysql into user group mysql
chown mysql:mysql -R /usr/local/software/mysql #Give user MySQL permission to the MySQL directory
#Tips: You can view the owner of a file through the'll'command after modifying permissions
2-2-3 MySQL profile modification
vim /etc/my.cnf	#Configure my.cnf
# The configuration file is as follows:
# Where basedir datadir log-error pid-file is modified based on the package you defined earlier

[mysqld]
bind-address=0.0.0.0
port=3306
user=mysql
basedir=/usr/local/software/mysql/mysql-5.7
datadir=/usr/local/software/mysql/data
socket=/tmp/mysql.sock
log-error=/usr/local/software/mysql/data/mysql.err
pid-file=/usr/local/software/mysql/data/mysql.pid
#character config
character_set_server=utf8mb4
symbolic-links=0
explicit_defaults_for_timestamp=true
Initialization of 2-2-4 MySQL
#Enter the bin directory of MySQL
cd /usr/local/software/mysql/mysql-5.7/bin
#Initialize MySQL (recommended to edit in Notepad++ before pasting into XShell)
./mysqld --defaults-file=/etc/my.cnf --basedir=/usr/local/software/mysql/mysql-5.7/ --datadir=/usr/local/software/mysql/data/ --user=mysql --initialize
2-2-5 MySQL Startup and root Password Modification
  • MySQL Service Registration and Startup
#View passwords (password information is recorded in the error log in the data directory)
cat /usr/local/software/mysql/data/mysql.err
#Will mysql.server placed in/etc/init.d/mysql,'mysql'is followed by the name of the MySQL service
cp /usr/local/software/mysql/mysql-5.7/support-files/mysql.server /etc/init.d/mysql
#Start MySQL Service
service mysql start
#... (Here are some tips for successful service startup, some are SUCCESS and some are [OK])
#Unsure whether to start successfully ps operation can be used to view the process
ps -ef|grep mysql
  • root User Password Modification
#Login to MySQL interface
cd /usr/local/software/mysql/mysql-5.7/bin #Enter the bin directory of MySQL
./mysql -u root -p   #bin directory
#After logging in, perform password changes under mysql> (MySQL control interface)
SET PASSWORD = PASSWORD('123456');
ALTER USER 'root'@'localhost' PASSWORD EXPIRE NEVER;
FLUSH PRIVILEGES; 
exit #Leave MySQL Control Interface
2-2-6 Access Permission Settings
  • The database of the remote connection server is not accessible at this time and additional settings are required in MySQL
#Login to MySQL interface
cd /usr/local/software/mysql/mysql-5.7/bin #Enter the bin directory of MySQL
./mysql -u root -p   #bin directory
#... (Enter password)

use mysql                                            #Access mysql Library
update user set host = '%' where user = 'root';      #Enable root access to any more host s
FLUSH PRIVILEGES;                                    #Refresh

3 Redis

3-1 gcc Compile Environment Installation

  • The installation of redis requires compiling the source code for redis, so prepare the compilation environment ahead of time
#1. Make sure root logs in 2. Make sure Linux is connected to the external network
yum -y install gcc automake autoconf libtool make

3-2 Redis Compressed Pack Download and Unzip

mkdir /opt/redis #Create redis folder in download directory/opt
cd /opt/redis #Enter the redis folder
wget http://download.redis.io/releases/redis-4.0.1.tar.gz #Download redis compressed package
tar -zxvf redis-4.0.1.tar.gz #Decompression package

mkdir /usr/local/software/redis
mv redis-4.0.1 /usr/local/software/redis/

3-3 Redis source file compilation and Redis installation

cd /usr/local/software/redis/redis-4.0.1

#Compile Source File
make
#... Compilation success will show: Hint:It's a good idea to run'make test'; The wording of
#... If compilation fails, all redis source files (that is, redis-4.0.1) need to be removed and recompressed

#Install redis in the redis directory (note that it is not redis-4.0.1)
make PREFIX=/usr/local/software/redis install
#... If there is an additional bin directory in the installation path, the installation succeeds, and if the installation fails, the source files are removed and recompressed

Executable file functions under /usr/local/redis/bin:

Executable Program NameRelated Explanations
redis-benchmarkPerformance Test Tool
redis-check-aofAOF File Repair Tool
redis-check-dumpRDB file checking tool (snapshot persistent file)
redis-cli (commonly used)Command Line Client
redis-server (commonly used)redis server start command

3-4 Redis Profile Modification

#Copy the configuration file from the redis source file (redis-4.0.1) into the redis home directory for easy management
cp /usr/local/software/redis/redis-4.0.1/redis.conf /usr/local/software/redis
#Modify profile name (6666 is redis start port number)
mv redis.conf 6666.conf	
#Modify Profile
vim /usr/local/software/redis/6666.conf
#Configuration file contents: (find the corresponding location in the configuration file)

#In this case, bind means that only the specified segment can remotely access this redis, and when commented out, there is no such restriction
#bind 127.0.0.1
#The default is set to yes, which prevents remote access at redis3. After version 2.3
protected-mode no
#Set up background running
daemonize yes
#Set Port
port 6666
#Set up database totals
databases 32
#Set Password(The default password is empty),This line was found in the configuration file # requirepass foobared
requirepass 123456
#Set Log File
logfile ./redislog.log
#Set Data File Storage Directory
dir ./

Startup and Use of 3-5 Redis

cd /usr/local/software/redis/bin #Enter the bin folder of redis
./redis-server ../6666.conf  #Specify profile startup, or follow redis default file if no profile is selected
#... (redis has been started successfully at this point), you can view the redis process through the ps command
ps -ef | grep redis
#... (The redis process with port:6666 indicates successful startup)
./redis-cli -p 6666 -a 123456 #Connect redis(-p for port, -a for password to connect redis)
#... (The following is the redis client operation)
>ping #Detect if redis is connected successfully (PONG is displayed if the connection is successful)
>shutdown #Stop redis

3-6 Redis Registration Start-Up Self-Service

3-6-1 Copy and modify the redis service script
#Copy the redis service script (utils/redis_init_script) to/etc/init.d directory
cp /usr/local/software/redis/redis-4.0.1/utils/redis_init_script /etc/init.d/
#Enter init.d directory and rename the script redis for ease of administration
cd /etc/init.d
mv ./redis_init_script redis
#Modify service script
vim ./redis
#The modifications are as follows:
REDISPORT=6666
#Executable files in the bin directory generated during installation
EXEC=/usr/local/software/redis/bin/redis-server 	#Location of the server
CLIEXEC=/usr/local/software/redis/bin/redis-cli 	#Client Location
PIDFILE=/var/run/redis_${REDISPORT}.pid 			#PID file location for Redis
#Specify the redis-launched profile, and the previous profile name 6666.conf correspondence
CONF="/usr/local/software/redis/${REDISPORT}.conf"

#Add a password variable to stop the redis service ($2 for the second parameter)
PASSWORD=$2
#Modify'$CLIEXEC-p $REDISPORT shutdown'in stop block
$CLIEXEC -a $PASSWORD -p $REDISPORT shutdown
#... Save Exit After Modification
#Increase script file execution permissions
chmod +x ./redis
3-6-2 Add script to startup entry
#Add script to boot entry
chkconfig --add redis
#View Startup Self-Start Items
chkconfig --list
#... If the redis name is visible, the registration of the boot-up self-start service is successful
* BUG record:'service redis does not support chkconfig'prompt appears
  • The following two lines of comments need to be released at the top of the configuration file specified by the redis script (I don't have either at all)
vim /usr/local/software/redis/6666.conf

#Comments to be added to the profile:
# chkconfig: 2345 90 10
# description: Redis is a persistent key-value database

#... Rejoining the open startup item at this time will not cause an error
3-6-3 Service Active Start and Stop
service redis start 
#If the password is entered incorrectly, the service will continuously attempt to connect to the redis client and report an exception. Press to exit and stop again
service redis stop 123456

If you suspend a task using ctrl+Z, the connection service will not quit but will be suspended

#Solution
jobs -l  #Query pending processes to see their pid
kill -9 Suspended process pid

4 Nginx

4-1 Environment Dependency Package

  • If the dependency is already installed, the installation will not continue
yum -y install gcc zlib zlib-devel pcre-devel openssl openssl-devel

4-2 Upload and unzip the installation package

mkdir /opt/nginx
cd /opt/nginx
#.... (Upload file)
tar -zxvf nginx-1.20.2.tar.gz
mkdir /usr/local/software/nginx
mv nginx-1.20.2 /usr/local/software/nginx

4-3 Nginx Compilation and Installation

  • Enter the compiled file directory (nginx-1.20.2)
cd /usr/local/software/nginx/nginx-1.20.2
  • Create a makeFile file using the configure command
  • It is recommended to edit in notepad before pasting into XShell. Pay special attention to the prefix value, which indicates the path to nginx installation
./configure \
--prefix=/usr/local/software/nginx \
--pid-path=/var/run/nginx/nginx.pid \
--lock-path=/var/lock/nginx.lock \
--error-log-path=/var/log/nginx/error.log \
--http-log-path=/var/log/nginx/access.log \
--with-http_gzip_static_module \
--http-client-body-temp-path=/var/temp/nginx/client \
--http-proxy-temp-path=/var/temp/nginx/proxy \
--http-fastcgi-temp-path=/var/temp/nginx/fastcgi \
--http-uwsgi-temp-path=/var/temp/nginx/uwsgi \
--http-scgi-temp-path=/var/temp/nginx/scgi \
--with-http_stub_status_module \
--with-http_ssl_module \
--with-file-aio \
--with-http_realip_module
  • Compile and install (or in the same directory (nginx-1.20.2))
make
make install

4-4 Nginx Startup and Port Settings

  • Nginx Port Settings
vim /usr/local/software/nginx/conf/nginx.conf
#Change 80 to 8089 at the listening port (roughly around 36 lines of file, positioned by'36+GG')
  • Nginx Start
cd /usr/local/software/nginx/sbin
./nginx

Overview of Nginx commands

./nginx	#open
./nginx -s stop	#Close
./nginx -s reload	#restart

4-5 Port Open

  • Server needs to set rules configuration for security group (omitted)
  • Firewall started to open port

Common firewalld commands

#Firewall service related commands
systemctl start firewalld.service		#Open Firewall
systemctl stop firewalld.service		#Close Firewall
systemctl enable firewalld.service		#Start-Up Self-Enabling
systemctl disable firewalld.service 	#Turn on disable self-start
systemctl is-enabled firewalld.service	#Check to see if the service starts automatically

#Firewall Port Related Commands
firewall-cmd --zone=public --add-port=80/tcp --permanent	#Open tcp 80 port permanently
firewall-cmd --zone=public --remove-port=80/tcp --permanent #Permanently delete tcp 80 port
firewall-cmd --zone=public --add-service=https --permanent	#Open https service permanently
firewall-cmd --zone=public --list-ports                     #View all open ports
firewall-cmd --reload     #Update firewall rules, after modifying firewall rules, need to reload

Keywords: Linux Operation & Maintenance

Added by Christian B. on Thu, 10 Mar 2022 20:06:04 +0200