Centos 7 Environment construction

Centos 7 common server environment construction: JDk1.8, MySQL5.7, RabbitMQ, Redis, nginx and other software, and word to PDF environment construction

Disk mount

Reference: baijiahao.baidu.com/s?id=164628…

1. Check the disk status

#View the current disk mount information
df -h

#Check how many disks the system has
fdisk -l

Copy the code

2. Partition the disk

#Partition the newly added disk (/dev/vdb indicates the id of the newly added disk)
fdisk /dev/vdb
Copy the code

3. Run the fdisk -l command to query the disk

4. Format the disk: run the mkfs.ext4 /dev/vdb1 command to format the partition disk.

5. Mount the disk to the corresponding directory

#Create a new directory under the root directory
mkdir /data

#Mount partition command
mount /dev/vdb1 /data


Copy the code

6. Automatically mount disks upon startup

Run the df -h command to check whether the mount is successful

Use the blkid command to view the UUID and format of the disk

It is recommended that you just use blkid /dev/vdb1 (the name of the blkid device) to be more precise and to minimize debugging errors.

blkid /dev/vdb1
Copy the code

Copy the UUID and format

/dev/vdb1: UUID=”7560b089-f5ac-4f5a-b0b4-e096e922c1c8″ TYPE=”ext4″

Revised:

UUID=7560b089-f5ac-4f5a-b0b4-e096e922c1c8 /data ext4 defaults 0 0

Writes disk information to the boot file

 vi /etc/fstab
Copy the code

7. Restart and check whether the mount is successful

#restart
reboot

#Restart the vm and check whether the vm is successfully mounted
df -h

Copy the code

JDK installation:

Reference: blog.csdn.net/hui_2016/ar…

Uninstall the previous version

The RPM – qa | grep Java or RPM – qa | grep JDK

RPM -e –nodeps Specifies the JDK name

Verify uninstall: RPM – qa | grep Java or RPM – qa | grep JDK

Note: View the JDK installation path

  • echo $JAVA_HOME
  • which java

Installing a new JDK

Preparing the JDK installation package: Download the Linux installation package from the official website

Decompress the installation package

tar -zxvf jdk-8u271-linux-x64.tar.gz
Copy the code

Editing environment variables

vim /etc/profile

#Add JDK environment variables at the bottom
#java environmentExport JAVA_HOME = / APP/soft/jdk1.8.0 _271 export CLASSPATH=.:${JAVA_HOME}/jre/lib/rt.jar:${JAVA_HOME}/lib/dt.jar:${JAVA_HOME}/lib/tools.jar export PATH=$PATH:${JAVA_HOME}/binCopy the code

Environmental variables take effect

source /etc/profile
Copy the code

Install NACOS

Prepare the installation file nacos-server-1.1.0.tar.gz

Unzip the files

The tar - ZXVF nacos - server - 1.1.0. Tar. GzCopy the code

Run standalone version

sh startup.sh -m standalone
Copy the code

Install MySQL5.7

Uninstall the previous version

Find mysql installation

rpm -qa|grep -i mysql
Copy the code

uninstall

The RPM - ev mysql - community - common - 5.7.23-1. El7. X86_64Copy the code

Find the installation directory command for older versions of mysql

find / -name mysql
Copy the code

Install MySQL5.7

Reference: blog.csdn.net/xiaolinlang…

Prepare the installation file: mysql-5.7.32-linux-glibc2.12-x86_64.tar.gz

Unzip to the current directory

The tar ZXVF mysql - 5.7.32 - Linux - glibc2.12 - x86_64. Tar. GzCopy the code

Mysql home directory processing

Mv mysql-5.7.32-linux-glibc2.12-x86_64 /APP/soft/mysql CD /data/soft/mysql mkdir dataCopy the code

Home directory permission processing

#To view
cat /etc/group | grep mysql
cat /etc/passwd |grep mysql

#If the user exists, run the userdel -r mysql command to delete the mysql user
userdel -r mysql

#In view will find no, that you have deleted.
cat /etc/group | grep mysql
cat /etc/passwd |grep mysql
Copy the code

Create mysql group and mysql user

groupadd mysql
useradd -r -g mysql mysql
chown -R mysql:mysql /data/soft/mysql
Copy the code

Creating a Configuration File

vim /etc/my.cnf
Copy the code
[client]
#password	= your_password
port = 3310
socket		= /tmp/mysql.sock

[mysqld]
binlog_cache_size = 32K
thread_stack = 256K
join_buffer_size = 256K
query_cache_type = 0
max_heap_table_size = 128M
port = 3310
socket		= /tmp/mysql.sock
datadir = /APP/soft/mysql/data
pid-file = /tmp/mysqld/mysqld.pid
log-error=/var/log/mysqld.log

character-set-server = utf8
default_storage_engine = InnoDB
performance_schema_max_table_instances = 400
table_definition_cache = 400
skip-external-locking
key_buffer_size = 1024M
max_allowed_packet = 100G
table_open_cache = 1024
sort_buffer_size = 4096K
net_buffer_length = 4K
read_buffer_size = 4096K
read_rnd_buffer_size = 256K
myisam_sort_buffer_size = 64M
thread_cache_size = 256
query_cache_size = 0M
tmp_table_size = 128M
sql-mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES

explicit_defaults_for_timestamp = true
#skip-name-resolve
max_connections = 1000
max_connect_errors = 100
open_files_limit = 65535

log-bin=mysql-bin
binlog_format=mixed
server-id = 1
expire_logs_days = 10
slow_query_log=1
slow-query-log-file=/APP/soft/mysql/data/mysql-slow.log
long_query_time=3
#log_queries_not_using_indexes=on
early-plugin-load = ""


innodb_data_home_dir = /APP/soft/mysql/data
innodb_data_file_path = ibdata1:10M:autoextend
innodb_log_group_home_dir = /APP/soft/mysql/data
innodb_buffer_pool_size = 1024M
innodb_log_file_size = 512M
innodb_log_buffer_size = 128M
innodb_flush_log_at_trx_commit = 1
innodb_lock_wait_timeout = 50
innodb_max_dirty_pages_pct = 90
innodb_read_io_threads = 4
innodb_write_io_threads = 4

[mysqldump]
quick
max_allowed_packet = 500M

[mysql]
no-auto-rehash

[myisamchk]
key_buffer_size = 256M
sort_buffer_size = 4M
read_buffer = 2M
write_buffer = 2M

[mysqlhotcopy]
interactive-timeout

Copy the code

Create file/TMP /mysql.sock

cd /tmp

touch mysql.sock

chown mysql:mysql mysql.sock

chmod 755 mysql.sock
Copy the code

Create file/TMP /mysqld/mysqld.pid

mkdir mysqld

cd mysqld

touch mysqld.pid

cd ..

chown -R mysql:mysql mysqld

cd mysqld

chmod 755 mysqld.pid
Copy the code

Create the file /var/log/mysqld.log

touch /var/log/mysqld.log

chown -R mysql:mysql /var/log

cd /var/log

chmod 755 mysqld.log
Copy the code

Initializing the database

cd /APP/soft/mysql/bin/

./mysqld --initialize --user=mysql --basedir=/APP/soft/mysql --datadir=/APP/soft/mysql/data


Copy the code

Error:

Resolve errors:

yum -y install numactl
Copy the code

/mysqld –initialize –user=mysql –basedir=/APP/soft/mysql –datadir=/APP/soft/mysql/data

Safe start:

./mysqld_safe --user=mysql &
Copy the code
#View the initial password
cat /var/log/mysqld.log
Copy the code

Log on to the MySQL

./mysql -u root -p
Copy the code
show databases;
Copy the code

Change the password

mysql> set password=password("xh2018");
Copy the code

Set the remote access permission

mysql>grant all privileges on *.* to 'root'@The '%' identified by 'xh2018';
Copy the code

Create a user:

CREATE USER 'pig'@'%' IDENTIFIED BY '123456';
Copy the code

Authorization:

Command:

GRANT privileges ON databasename.tablename TO 'username'@'host'
Copy the code

Description:

  • Privileges: Operation privileges of the user, such asSELECT.INSERT.UPDATE, if you want to grant all permissionsALL
  • Databasename: indicates the databasename
  • Tablename: The name of the table, which can be used if you want to grant the user permissions to operate on all databases and tables*Said, such as*. *

Example:

GRANT SELECT, INSERT ON test.user TO 'pig'@'%';
GRANT ALL ON *.* TO 'pig'@'%';
GRANT ALL ON maindataplus.* TO 'pig'@'%';
Copy the code

Note:

The user authorized by the preceding command cannot authorize another user. To enable the user to authorize another user, run the following command:

GRANT privileges ON databasename.tablename TO 'username'@'host' WITH GRANT OPTION;
Copy the code

Effective immediately:

mysql> flush privileges;
Copy the code

Install RabbitMQ

Install Erlang

Prepare the installation package erlang-22.3.4.12-1.el7.x86_64. RPM

Run the setup command:

The RPM - the ivh Erlang 22.3.4.12-1. El7. X86_64. RPMCopy the code

Note: If the execution encounters any of the following problems, do so

Download: openssl – libs – 1.0.2 k – 19. El7. X86_64. RPM

The RPM - the ivh openssl - libs - 1.0.2 k - 19. El7. X86_64. RPM -- forceCopy the code

Install the rabbitmq

Prepare the rabbitmq-server-generic-UNIX-3.8.7.tar installation package

Extract:

The tar XVF - the rabbitmq server - generic - Unix - 3.8.7. TarCopy the code

Configuring environment Variables

Echo 'export PATH=$PATH:/APP/soft/rabbitmq_server-3.8.7/sbin' >> /etc/profileCopy the code

Refreshing environment variables

source /etc/profile
Copy the code

On | off | view commands

#Start the command
rabbitmq-server -detached

#Stop command
rabbitmqctl stop

#Check the status
rabbitmqctl status

Copy the code

Enable the Web plug-in: Default account Password: guest Guest (This account can only be accessed on the local computer)

rabbitmq-plugins enable rabbitmq_management
Copy the code

Viewing All Users

rabbitmqctl list_users
Copy the code

Add a new user

rabbitmqctl add_user zhaobl 123456
Copy the code

Configure permissions

rabbitmqctl set_permissions -p "/" zhaobl ".*" ".*" ".*"
Copy the code

Viewing User Rights

rabbitmqctl list_user_permissions zhaobl
Copy the code

Set the tag

rabbitmqctl set_user_tags zhaobl administrator
Copy the code

Five, Redis installation

Prepare the file: I copied it from the previous Linux

#Upload foldersSCP - r test [email protected]: / var/WWW /
#Upload a file
scp /path/local_filename username@servername:/path

Copy the code

Start command:

 ./src/redis-server redis.conf &
Copy the code

Verify that Redis is started

./redis-cli
Copy the code

Install nginx

Prepare the installation package: nginx-1.18.0.tar.gz

Extract:

The tar - ZXVF nginx - 1.18.0. Tar. GzCopy the code

Compile:

CD nginx - 1.18.0#compile
./configure
#An error
Copy the code

Solution:

yum -y install pcre-devel openssl openssl-devel
Copy the code

Install nginx again

./configure
make
make install
Copy the code

Installation address: /usr/local/nginx/

#Start command:
./nginx
#Restart command:
./nginx -s reload
Copy the code

Seven, LibreOffice installation

7.1 Environment Preparations

1. Prepare the installation package

Linux version: Libreoffice_7.1.5_linux_x86-64_rpm.tar.gz

Windows version: libreoffice_7.1.5_win_x64.msi

7.2 unzip

Windows version double-click default install

Linux version installation: reference blog.csdn.net/weiguang102…

Extract:

Tar - ZXVF LibreOffice_7. 1.5 _Linux_x86-64 _rpm. Tar. GzCopy the code

7.3 installation *. The RPM

#Go to the decompressed folderCD libreoffice_7.1.5.2_linux_x86-64_rpm /RPMS yum -y localinstall *Copy the code

7.4 install libreoffice – headless

yum install -y libreoffice-headless
Copy the code

7.5 Checking whether the installation is complete

Libreoffice7.1 - versionCopy the code

7.6 Convert Word to PDF and Install LibreOffice-Writer

libreoffice --headless --convert-to pdf 1.doc
Copy the code

Error: missing loaded source file

[root@bogon Public]# libreoffice --headless --convert-to pdf 123.docx 
Error: source file could not be loaded
[root@bogon Public]# 

Copy the code

You need to install

yum install libreoffice-writer
Copy the code

7.7 Installing Win10 fonts into centos

Windows Fonts are set in “C:\Windows\Fonts”.

Centos font set in /usr/share/fonts

Create a window font folder in centos

mkdir /usr/share/fonts/windows
Copy the code

2. Copy or download the font file (*.ttf) you want to install from C:\Windows\Fonts on your PC to /usr/share/fonts/ Windows

3. Modify the font file permissions so that users other than root can use it

cd /usr/share/fonts/windows

chmod 755 *.ttf
Copy the code

4. Set up font cache

#(If prompted mkfontScale:commandNot found, you need to install it yourself# yum install mkfontscale)
mkfontscale 

mkfontdir

#Fc-cache:commandIf not found, you need to install it# yum install fontconfig)
fc-cache -fv 
Copy the code

5. Restart the computer

reboot
Copy the code

7.7 Conversion Format Description

Libreoffice –headless –convert-to PDF {document path} –outdir {export directory path}

7.8 Converting Documents using Java

Eight, VSFTP installation

8.1 Checking the Installation

rpm -qa |grep vsftpd

#Vsftpd-3.0.2-11.el7_2.x86_64 is installed
#If nothing is returned, it is not installed, right
Copy the code

8.2 Installing the VSFTP Service

yum install -y vsftpd
Copy the code

8.3 start VSFTP

systemctl start vsftpd
Copy the code

8.4 Verifying whether services are started

netstat -nltp|grep 21
Copy the code

8.5 Creating a User Group

#Create a group for storing FTP users
groupadd ftpgroups
Copy the code

8.6 Creating an FTP User

#Create an FTP user and add the user to the ftpgroups group
useradd -d /APP/workspace/web/daping/jiamusi/video -g ftpgroups video
Copy the code

Set the password

#Video User name and password created just now: videoftp
passwd video
Copy the code

Settings are not allowed for user login

usermod -s /sbin/nologin video
Copy the code

Restart the VSFTPD service

/bin/systemctl restart vsftpd.service
#Or systemctl restart VSFTPD
Copy the code

8.7 Setting and Configuration

vim /etc/vsftpd/vsftpd.conf
#Disabling Anonymous Users
anonymous_enable=NO 
#Do not switch the root directory to delete this line or do not#
# chroot_local_user=YES 
Copy the code

9. Add system users

9.1 Adding a User

#Create a user as user root
adduser video
#Set the password
passwd video
#Prompt for the password videoftp


#Create a group for storing FTP users
# groupadd ftpgroups
# adduser -g ftpgroups video
Copy the code

9.2 Setting a Specified Directory

#A directory is open to a user
chown -R  video:video  /APP/workspace/web/daping/jiamusi/video

#chown -R video:video /home/gsgd/gsgd-longjian/jiamusi/video
Copy the code

9.3 Deleting a User

userdel video
Copy the code

9.4 Viewing Users

id video
cat /etc/passwd
cat /etc/group
Copy the code

X. Convert Word template to PDF

10.1 requirements

The customer provides a Word template file and requires it to be downloaded as a PDF file based on the data in the system and the Word template

10.2 Solution

Use FreeMarker to fill the system data into a template file, then use LibreOffice software to convert the resulting file into a PDF, and finally into an application for PDF download

Step 10.3

1. Install LibreOffice

LibreOffice is open source software that supports Windows and Linux platforms. Note that the commands on Windows and Linux platforms may be inconsistent.

2. Prepare a FreeMarker template

In the template file provided by the customer, replace the output data with FreeMarker syntax fields.

3. Convert Word to XML: Use LibreOffice to convert Word to XML

#Window environment command
soffice --convert-to xml .\xunshijilu.doc
Copy the code

FreeMarker template: Copy the file to the project and change the suffix to HTML to become a FreeMarker template.

5. Fill in the data: Use FreeMarker to query the data, fill in the template, and export it to the specified path

6. Convert XML to PDF: Use the LibreOffice command in the program to convert XML to PDF