離線Linux伺服器環境搭建

Wenenenenen發表於2024-08-07

檔案上傳到伺服器先

image-20230822143232457

一般傳到伺服器目錄

mkdir /usr/local/install_package

資料庫

版本:Postgresql 9.5.20

檢查依賴環境 gcc-c++環境,有日誌列印就是有安裝,新伺服器一般都只有gcc沒有g++

gcc -v 
g++ -v
rpm -qa | grep gcc-c++
rpm -qa | grep gcc

安裝,到gcc安裝目錄下

cd /usr/local/install_package/gcc
rpm -Uvh *.rpm --nodeps --force

然後使用檢查命令驗證

安裝Postgresql

解壓

cd /usr/local/install_package
tar -zxvf postgresql-9.5.20.tar.gz
cd postgresql-9.5.20

編譯帶上uuid,需要提前裝好uuid,注意:

cd /usr/local/install_package
tar -zxvf uuid-1.6.2.tar.gz
cd uuid-1.6.2
./configure
make && make install
rpm -ivh uuid-1.6.2-26.el7.x86_64.rpm
rpm -ivh uuid-devel-1.6.2-26.el7.x86_64.rpm
rpm -ivh libuuid-devel-2.23.2-65.el7_9.1.x86_64.rpm
# 如果不安裝以上的一個包,編譯postgresql就會報以下的錯誤:
# configure: error: library 'ossp-uuid' or 'uuid' is required for OSSP-UUID"
cd /usr/local/install_package/postgresql-9.5.20/contrib/uuid-ossp
# 這是編譯的 contrib/uuid-ossp
make && make install
#上邊如果不編譯uuid-ossp,就會出現下面的錯誤:
#postgres=# create extension "uuid-ossp";
#ERROR:  could not open extension control file "/usr/local/postgresql/share/extension/uuid-ossp.control": No such file or directory
#./configure --prefix=/bigdata/work/postgresql 指定安裝路徑 預設/usr/local/pgsql
# 編譯時候把uuid帶上,!!!!!!!,這個害我重灌了三次
./configure --with-uuid=ossp
#然後再繼續postgresql的make和make install
make
make install

./configure編譯要是有報錯缺少包,就檢查是否有,檢查也有的話就是缺少名稱-devel的包,去下載,安裝

映象下載站:http://mirrors.aliyun.com/centos/7/os/x86_64/Packages/

[root@iZul501d9puehvyajdpb92Z postgresql-9.5.20]# ./configure
.......
checking for library containing readline... no
configure: error: readline library not found
If you have readline already installed, see config.log for details on the
failure.  It is possible the compiler isn't looking in the proper directory.
Use --without-readline to disable readline support.
[root@iZul501d9puehvyajdpb92Z postgresql-9.5.20]# rpm -qa | grep readline
readline-6.2-11.el7.x86_64
[root@iZul501d9puehvyajdpb92Z gcc]# rpm -ivh ncurses-devel-5.9-14.20130511.el7_4.x86_64.rpm 
Preparing...                          ################################# [100%]
Updating / installing...
   1:ncurses-devel-5.9-14.20130511.el7################################# [100%]
[root@iZul501d9puehvyajdpb92Z gcc]# rpm -ivh readline-devel-6.2-11.el7.x86_64.rpm 
Preparing...                          ################################# [100%]
Updating / installing...
   1:readline-devel-6.2-11.el7        ################################# [100%]

readline依賴於ncurses,單個安裝需要注意依賴順序安裝,

再重新回去執行編譯命令 ./configure

這個結尾./configure成功

checking thread safety of required library functions... yes
checking whether gcc supports -Wl,--as-needed... yes
configure: using compiler=gcc (GCC) 4.8.5 20150623 (Red Hat 4.8.5-44)
configure: using CFLAGS=-Wall -Wmissing-prototypes -Wpointer-arith -Wdeclaration-after-statement -Wendif-labels -Wmissing-format-attribute -Wformat-security -fno-strict-alia
sing -fwrapv -fexcess-precision=standard -O2
configure: using CPPFLAGS= -D_GNU_SOURCE 
configure: using LDFLAGS=  -Wl,--as-needed
configure: creating ./config.status
config.status: creating GNUmakefile
config.status: creating src/Makefile.global
config.status: creating src/include/pg_config.h
config.status: creating src/include/pg_config_ext.h
config.status: creating src/interfaces/ecpg/include/ecpg_config.h
config.status: linking src/backend/port/tas/dummy.s to src/backend/port/tas.s
config.status: linking src/backend/port/dynloader/linux.c to src/backend/port/dynloader.c
config.status: linking src/backend/port/sysv_sema.c to src/backend/port/pg_sema.c
config.status: linking src/backend/port/sysv_shmem.c to src/backend/port/pg_shmem.c
config.status: linking src/backend/port/unix_latch.c to src/backend/port/pg_latch.c
config.status: linking src/backend/port/dynloader/linux.h to src/include/dynloader.h
config.status: linking src/include/port/linux.h to src/include/pg_config_os.h
config.status: linking src/makefiles/Makefile.linux to src/Makefile.port

make成功

cp ../../../contrib/spi/refint.so refint.so
cp ../../../contrib/spi/autoinc.so autoinc.so
make[2]: Leaving directory `/usr/local/install_package/postgresql-9.5.20/src/test/regress'
make -C test/perl all
make[2]: Entering directory `/usr/local/install_package/postgresql-9.5.20/src/test/perl'
make[2]: Nothing to be done for `all'.
make[2]: Leaving directory `/usr/local/install_package/postgresql-9.5.20/src/test/perl'
make[1]: Leaving directory `/usr/local/install_package/postgresql-9.5.20/src'
make -C config all
make[1]: Entering directory `/usr/local/install_package/postgresql-9.5.20/config'
make[1]: Nothing to be done for `all'.
make[1]: Leaving directory `/usr/local/install_package/postgresql-9.5.20/config'
All of PostgreSQL successfully made. Ready to install.

make install 成功

make[1]: Leaving directory `/usr/local/install_package/postgresql-9.5.20/src'
make -C config install
make[1]: Entering directory `/usr/local/install_package/postgresql-9.5.20/config'
/usr/bin/mkdir -p '/usr/local/pgsql/lib/pgxs/config'
/usr/bin/install -c -m 755 ./install-sh '/usr/local/pgsql/lib/pgxs/config/install-sh'
/usr/bin/install -c -m 755 ./missing '/usr/local/pgsql/lib/pgxs/config/missing'
make[1]: Leaving directory `/usr/local/install_package/postgresql-9.5.20/config'
PostgreSQL installation complete.

建立使用者,不能用root啟動

[root@iZul501d9puehvyajdpb92Z pgsql]# useradd postgres
[root@iZul501d9puehvyajdpb92Z pgsql]# passwd postgres
Changing password for user postgres.
New password: 
BAD PASSWORD: The password contains the user name in some form
Retype new password: 
passwd: all authentication tokens updated successfully.

授權

mkdir /usr/local/pgsql/data
mkdir /usr/local/pgsql/log
chown -R postgres:postgres /usr/local/pgsql

環境變數,vim /etc/profile, 結尾加上下面的,source /etc/profile,結果生效

export PGDATA=/usr/local/pgsql/data
export PGHOME=/usr/local/pgsql
export LD_LBRARY_PATH=/usr/local/pgsql/lib:$LD_LIBRARY_PATH
export PATH=$PGHOME/bin:$PATH

初始化資料庫

切換postgres使用者,到pgsql/bin下,執行initdb

WARNING: enabling "trust" authentication for local connections
You can change this by editing pg_hba.conf or using the option -A, or
--auth-local and --auth-host, the next time you run initdb.

Success. You can now start the database server using:

    bin/pg_ctl -D /usr/local/pgsql/data -l logfile start

配置資料庫

/usr/local/pgsql/data目錄下

vim pg_hba.conf

image-20230818145502452

vim postgresql.conf

image-20230818145552593

配置成服務

切回root使用者

複製啟動檔案

cp contrib/start-scripts/linux /etc/init.d/postgresql
vim /etc/init.d/postgresql

image-20230818150114524

授權+開機自啟

chmod +x /etc/init.d/postgresql
chkconfig --add postgresql

啟動,檢視

service postgresql start
service postgresql stop
service postgresql status
ps -ef|grep postgres

psql連線,\password 設定資料庫使用者密碼

image-20230818150659480

可以本地使用Navicat測試連線

安裝PostGIS

先安裝proj,geos,gdal.依賴項,下載地址:http://download.osgeo.org

[root@iZul501d9puehvyajdpb92Z install_package]# tar xf proj-4.8.0.tar.gz
[root@iZul501d9puehvyajdpb92Z proj-4.9.3]# cd proj-4.9.3
[root@iZul501d9puehvyajdpb92Z proj-4.9.3]# ./configure --prefix=/usr/local/pgsql/plugin/proj
[root@iZul501d9puehvyajdpb92Z proj-4.9.3]# make && make install
[root@iZul501d9puehvyajdpb92Z proj-4.9.3]# vim /etc/ld.so.conf.d/proj-4.9.3.conf 
#寫入一句:
/usr/local/pgsql/plugin/proj/lib
[root@iZul501d9puehvyajdpb92Z proj-4.9.3]# ldconfig

安裝geos,先安裝bzip2解壓器,

[root@iZul501d9puehvyajdpb92Z install_package]# tar -zxvf bzip2-1.0.6.tar.gz 
[root@iZul501d9puehvyajdpb92Z install_package]# cd bzip2-1.0.6
[root@iZul501d9puehvyajdpb92Z bzip2-1.0.6]# make && make install
[root@iZul501d9puehvyajdpb92Z bzip2-1.0.6]# cd ..
[root@iZul501d9puehvyajdpb92Z install_package]# bzip2 -d geos-3.8.0.tar.bz2
[root@iZul501d9puehvyajdpb92Z install_package]# tar xf geos-3.8.0.tar
[root@iZul501d9puehvyajdpb92Z install_package]# cd geos-3.8.0
[root@iZul501d9puehvyajdpb92Z geos-3.8.0]# ./configure --prefix=/usr/local/pgsql/plugin/geos
[root@iZul501d9puehvyajdpb92Z geos-3.8.0]# make && make install
[root@iZul501d9puehvyajdpb92Z geos-3.8.0]# vim /etc/ld.so.conf.d/geos-3.8.0.conf
#寫入一句:
/usr/local/pgsql/plugin/geos/lib
[root@iZul501d9puehvyajdpb92Z geos-3.8.0]# ldconfig

gdal

[root@iZul501d9puehvyajdpb92Z install_package]# tar xf gdal-1.11.4.tar.gz 
[root@iZul501d9puehvyajdpb92Z install_package]# cd gdal-1.11.4
[root@iZul501d9puehvyajdpb92Z gdal-1.11.4]# ./configure --prefix=/usr/local/pgsql/plugin/gdal
[root@iZul501d9puehvyajdpb92Z gdal-1.11.4]# make && make install
[root@iZul501d9puehvyajdpb92Z gdal-1.11.4]# vim /etc/ld.so.conf.d/gdal-1.11.4.conf
#寫入一句:
/usr/local/pgsql/plugin/gdal/lib
[root@iZul501d9puehvyajdpb92Z gdal-1.11.4]# ldconfig

PostGis

[root@iZul501d9puehvyajdpb92Z install_package]# tar xf postgis-2.3.7.tar.gz
[root@iZul501d9puehvyajdpb92Z postgis-2.3.7]# cd postgis-2.3.7
[root@iZul501d9puehvyajdpb92Z postgis-2.3.7]# ./configure --prefix=/usr/local/pgsql/plugin/postgis \
--with-pgconfig=/usr/local/pgsql/bin/pg_config \
--with-geosconfig=/usr/local/pgsql/plugin/geos/bin/geos-config \
--with-gdalconfig=/usr/local/pgsql/plugin/gdal/bin/gdal-config \
--with-projdir=/usr/local/pgsql/plugin/proj

編譯報錯還是少元件,下載安裝,重新執行編譯

configure: error: could not find xml2-config from libxml2 within the current path. You may need to try re-running configure with a --with-xml2config parameter.

## 依賴順序 xz-libs --> xz-devel --> libxml2-devel 
## 特別注意版本,試錯了很多次,因為本機有xz-libs和libxml2,所以要依據本機的版本下載
[root@iZul501d9puehvyajdpb92Z install_package]# rpm -ivh xz-devel-5.2.2-2.el7_9.x86_64.rpm
[root@iZul501d9puehvyajdpb92Z install_package]# rpm -ivh libxml2-devel-2.9.1-6.el7_9.6.x86_64.rpm

又一直報錯,找不到GDAL

configure: error: could not find GDAL

解決:把pgsql/lib也配置到ldconfig裡
[root@iZul501d9puehvyajdpb92Z postgis-2.3.7]# vim /etc/ld.so.conf.d/pgsql-9.5.20.conf
#寫入一句:
/usr/local/pgsql/lib
[root@iZul501d9puehvyajdpb92Z postgis-2.3.7]# ldconfig

安裝

make && make install

檢測

[root@iZul501d9puehvyajdpb92Z postgis-2.3.7]# su postgres
[postgres@iZul501d9puehvyajdpb92Z postgis-2.3.7]$ psql
psql (9.5.20)
Type "help" for help.

postgres=# select * from pg_available_extensions;
          name          | default_version | installed_version |                               comment                               
------------------------+-----------------+-------------------+---------------------------------------------------------------------
 plpgsql                | 1.0             | 1.0               | PL/pgSQL procedural language
 postgis_topology       | 2.3.7           |                   | PostGIS topology spatial types and functions
 postgis_tiger_geocoder | 2.3.7           |                   | PostGIS tiger geocoder and reverse geocoder
 postgis                | 2.3.7           |                   | PostGIS geometry, geography, and raster spatial types and functions
(4 rows)

postgres=# create extension postgis;
CREATE EXTENSION
postgres=# create extension postgis_topology;
CREATE EXTENSION

JDK

mkdir /usr/local/java/
cd /usr/local/install_package
tar -zxvf jdk-8u381-linux-x64.tar.gz -C /usr/local/java/
vim /etc/profile
#新增環境變數
export JAVA_HOME=/usr/local/java/jdk1.8.0_381/
export JRE_HOME=${JAVA_HOME}/jre
export CLASSPATH=.:${JAVA_HOME}/lib:${JRE_HOME}/lib
export PATH=${JAVA_HOME}/bin:$PATH
source /etc/profile
#建立軟連線
ln -s /usr/local/java/jdk1.8.0_381/bin/java /usr/bin/java
#驗證
java -version

Redis

cd /usr/local/install_package
tar -zxvf redis-6.2.13.tar.gz
 cd redis-6.2.13
 #編譯
 make
 #安裝 預設到/usr/local/bin  ->指定路徑 make install PREFIX=/tools/redis
 make install
 
 #啟動
 redis-server /usr/local/install_package/redis-6.2.13/redis.conf
 #關閉
 redis-cli shutdown
 #修改配置
 vim /usr/local/install_package/redis-6.2.13/redis.conf
 改動:
 	#設定後臺啟動,如果不是後臺啟動,每次推出redis就關閉了
    daemonize yes
    #開啟密碼保護,註釋則不需要密碼
    requirepass qwer1234
    #允許訪問的ip,改為0.0.0.0就是所有ip均可
    #bind 127.0.0.1 -::1
    bind 0.0.0.0
#新增到服務 設定開機自啟
vim /usr/lib/systemd/system/reids.service
寫入:
	[Unit]
    Description=redis-server
    After=network.target

    [Service]
    Type=forking

    ExecStart=/usr/local/bin/redis-server/usr/local/install_package/redis-6.2.13/redis.conf
    PrivateTmp=true

    [Install]
    WantedBy=multi-user.target
#過載系統服務
systemctl daemon-reload
#設定開機自啟
systemctl enable redis.service
#取消開機自啟
systemctl disable redis.service
#啟動服務
systemctl start redis.service
#停止服務
systemctl stop redis.service
#檢視服務狀態
systemctl status redis.service

Tomcat

cd /usr/local/install_package
tar -zxvf apache-tomcat-9.0.34.tar.gz -C /usr/local/tomcat
cd /usr/local/tomcat/apache-tomcat-9.0.34
vim /conf/server.xml
改埠:
	<Connector port="8080" protocol="HTTP/1.1"
               connectionTimeout="20000"
               redirectPort="8443" />
#啟動
bin/start.sh
#停止
bin/shutdown.sh

Application

找臺能連上資料庫的Windows,用Navicat執行sql,建立資料庫。

war包放到tomcat的webapps目錄下,啟動tomcat

修改配置檔案

webapps/imageserver/WEB-INF/classes/application-dev.yml

修改資料庫連線,redis連線,資料目錄

server:
  port: 8081

spring:
  datasource:
    url: jdbc:postgresql://127.0.0.1:5432/intoview
    username: intoview
    password: intoview
    # 使用druid資料來源
    type: com.alibaba.druid.pool.DruidDataSource
    driver-class-name: org.postgresql.Driver
    filters: stat
    maxActive: 2
    initialSize: 1
    maxWait: 600000
    minIdle: 1
    timeBetweenEvictionRunsMillis: 60000
    minEvictableIdleTimeMillis: 300000
    validationQuery: select now()
    testWhileIdle: true
    testOnBorrow: false
    testOnReturn: false
    poolPreparedStatements: true
    maxOpenPreparedStatements: 20
  redis:
    host: localhost
    port: 6379
    password: qwer1234

imageserver:
  #point-data-path: /opt/module/data/imagedata
#  point-data-path: E:/opt/imagedata
 # point-data-path: E:/Desktop/Work/imageServer/testData #E:/Desktop/Work/imageServer/testData
  point-data-path:/data
  closest-distance-tolerance: 5

修改tomcat埠和yml的埠最好一致

這裡修改application-dev.yml為8080

量測版和非量測版切換:

static/asset/js/index.js

634和639行,realimage是非量測,realimage是量測

if ($(".is-publisher").length > 0) {
            $.each(data, function (index, props) {
                resources[props.id] = props;
                html += '<tr>' + '<td>' + (index + 1) + '</td>' + '<td><img src="open/public/getImage/' + props.name + '/' + props.firstPicName + '" class="item-img">' + '</td>' + '<td>' + props.label + '</td><td>'+props.name+'</td>' + '<td>' + props.createDate + '</td>' + '<td>' + props.collectDate + '</td>' + '<td>' + (props.picCount || 0) + '</td>' + '<td>' + (props.mileage == null ? 0 : props.mileage.toFixed(2)) + '公里</td>' + '<td>' + '<a title="預覽" href=' + 'realimage?serviceName=' + props.name + ' target=_blank><i class="fa fa-eye"></i></a>' + '<a title="授權" class="authorization  fa fa-unlock"  data-id=' + props.id + ' data-name=' + props.name + ' data-label=' + props.label + '></a>' + '<a title="刪除" class="delete fa fa-times" data-serviceName=' + props.name + ' data-id=' + props.id + '></a>' + '<a title="設定" class="setting fa fa-eyedropper" data-id=' + props.id + '></a>' + '</td>' + '</tr>';
            });
        } else {
            $.each(data, function (index, props) {
                resources[props.id] = props;
                html += '<tr>' + '<td>' + (index + 1) + '</td>' + '<td><img src="open/public/getImage/' + props.name + '/' + props.firstPicName + '" class="item-img">' + '</td>' + '<td>' + props.label + '</td><td>'+props.name+'</td>' + '<td>' + props.createDate + '</td>' + '<td>' + props.collectDate + '</td>' + '<td>' + (props.picCount || 0) + '</td>' + '<td>' + (props.mileage == null ? 0 : props.mileage.toFixed(2)) + '公里</td>' + '<td>' + '<a title="預覽" href=' + 'realimage?serviceName=' + props.name + ' target=_blank><i class="fa fa-eye"></i></a>' + '</td>' + '</tr>';
            });
        }

相關文章