鼎鼎知识库
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

2021.4.23局域网Ubuntu搭建环境.md 16KB

文件目录结构

/home/lenovo
	znzm
		tools
			mysql
			redis
			tdengine
		apps
			main
			open
			scheduler

开始创建

确定当前目录:pwd (当前目录为/home/lenovo)
创建智能照明目录:mkdir znzm
进入智能照明目录:cd znzm
创建工具目录用来放数据库的执行文件:mkdir tools
创建应用程序目录用来放应用程序发布文件:mkdir apps
创建MySQL目录:mkdir tools/mysql
创建Redis目录:mkdir tools/redis
创建TDEngine目录:mkdir tools/tdengine
创建智能照明主程序目录:mkdir apps/main
创建开放平台目录:mkdir apps/open
创建调度平台目录:mkdir apps/scheduler

测试服务器MySQL离线安装失败记录

以下没有成功,忽略。

确认当前目录:pwd (目前在root目录)
创建目录:mkdir downloads
进入目录:cd downloads
下载压缩文件:wget https://dev.mysql.com/get/Downloads/MySQL-5.6/mysql-5.6.36-linux-glibc2.5-x86_64.tar.gz
查看组:cat /etc/group
查看用户:cat /etc/passwd
创建mysql用户组:groupadd mysql
创建mysql用户:useradd -g mysql mysql
创建mysql安装目录:mkdir /usr/local/mysql
把压缩包解压到mysql安装目录tar -xzf /root/downloads/mysql-5.6.36-linux-glibc2.5-x86_64.tar.gz -C /usr/local/mysql  (mysql下包括mysql-5.6.36-linux-glibc2.5-x86_64目录)
把mysql下包括mysql-5.6.36-linux-glibc2.5-x86_64目录拷贝到上一级:sudo cp -R -t /usr/local/mysql /usr/local/mysql/mysql-5.6.36-linux-glibc2.5-x86_64/*
删除把mysql下包括mysql-5.6.36-linux-glibc2.5-x86_64目录:sudo rm -rf /usr/local/mysql/mysql-5.6.36-linux-glibc2.5-x86_64
创建配置文件:touch /etc/my.cnf
编辑my.cnf文件:nano /etc/my.cnf

[mysql]

# 设置mysql客户端默认字符集

default-character-set=utf8

socket=/var/lib/mysql/mysql.sock

[mysqld]

skip-name-resolve

# 设置端口

port=3306

socket=/var/lib/mysql/mysql.sock

# 设置mysql的安装目录

basedir=/usr/local/mysql

# 设置mysql数据库的存放目录

datadir=/usr/local/mysql/data/mysql

# 允许最大连接数

max_connections=200

# 服务端使用的字符集

character-set-server=utf8

# 创建表默认引擎

default-storage-engine=INNODB

lower_case_table_names=1

max_allowed_packet=16M

创建以上my.cnf文件中定义的目录:

mkdir /var/lib/mysql
mkdir /var/lib/mysql/mysql
chown -R mysql:mysql /var/lib/mysql
chown -R mysql:mysql /var/lib/mysql/mysql

修改/usr/local/mysql目录的拥有者:sudo chown -R mysql:mysql /usr/local/mysql
进入mysql目录:cd /usr/local/mysql

--以下忽略
安装数据库:

sudo /usr/local/mysql/scripts/mysql_install_db --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data

./scripts/mysql_install_db --user=mysql

报错Installing MySQL system tables..../bin/mysqld: error while loading shared libraries: libaio.so.1: cannot open shared object file: No such file or directory

sudo apt install libaio
--以上忽略

创建数据存储目录:mkdir data/mysql

公司局域网安装MySQL失败记录

以下没有成功。忽略。

确认当前所在目录:pwd (当前目录为:/home/lenovo/znzm)
进入MySQL所在目录:cd tools/mysql
确认Ubuntu内核:arch (x86_64=AMD64)
开始下载:wget https://dev.mysql.com/get/Downloads/MySQL-5.6/mysql-5.6.36-linux-glibc2.5-x86_64.tar.gz
确定解压文件所在目录: /home/lenovo/znzm/tools/mysql/mysql-5.6.36-linux-glibc2.5-x86_64.tar.gz

脚本文件

创建脚本文件:nano start.sh

#!/bin/bash

# 安装MySQL
SOURCE_GZ_FILE="/home/lenovo/znzm/tools/mysql/mysql-5.6.36-linux-glibc2.5-x86_64.tar.gz"
INSTALL_DIR="/usr/local/mysql"

# 判断MySQL是否安装
echo "检查MySQL是否安装"
mysql -version > /dev/null 2>&1

if [ $? -eq 127 ];then
	echo "暂未安装MySQL"
	# 如果INSTALL_DIR目录已经存在,则删除
	if [ -d ${INSTALL_DIR} ];then
		echo "安装目录已存在,正在删除${INSTALL_DIR}"
		sudo rm -rf ${INSTALL_DIR}
	fi
	echo "创建安装目录${INSTALL_DIR}"
	sudo mkdir ${INSTALL_DIR}
	
	echo "解压${SOURCE_GZ_FILE}到安装目录${INSTALL_DIR}..."
	sudo tar -xzf ${SOURCE_GZ_FILE} -C ${INSTALL_DIR}
	TEMP=`ls ${INSTALL_DIR}`
	sudo cp -R -t ${INSTALL_DIR} ${INSTALL_DIR}/${TEMP}/*
	sudo rm -f ${INSTALDIR}/{TEMP}
	echo "解压完毕"
	echo "添加MySQL用户组和用户"
	sudo groupadd mysql
	sudo useradd -g mysql mysql
	echo "开始安装"
	cd ${INSTALL_DIR} && pwd
	sudo mkdir data/mysql
	sudo chown -R mysql:mysql ${INSTALL_DIR}
	sudo ./scripts/mysql_install_db --user=mysql --basedir=${INSTALL_DIR} --datadir=${INSTALL_DIR}/data/mysql
	sudo cp support-files/mysql.server /etc/init.d/mysql
	sudo chmod 755 /etc/init.d/mysql
	sudo cp support-files/my-default.cnf /etc/my.cnf
	echo "请求修改/etc/init.d/mysql文件"
	echo "basedir=${INSTALL_DIR/}"
	echo "datadir=${INSTALL_DIR}/data/mysql"
	echo "按Enter确认"
	read -n 1
	sudo nano /etc/init.d/mysql
	echo "请修改/etc/profile文件,添加mysql环境变量"
	echo '文件末尾追加export PATH=${PATH}:'${INSTALL_DIR}/bin
	echo "按Enter确认"
	read -n 1
	sudo nano /etc/profile
	source /etc/profile
	sudo echo "安装成功!启动mysql服务"
	sudo systemctl enable mysql
	sudo service mysql start
	echo "请修改mysql -> root密码"
	echo "请输入密码:"
	read mysql_pwd
	sudo mysqladmin -u root password ${mysql_pwd}
else
	echo "MySQL已安装"
	mysql -version
fi

赋予权限:chmod +x start.sh

执行脚本文件:bash start.sh

TecheDdGo123


报错:Installing MySQL system tables.../usr/local/mysql/bin/mysqld: error while loading shared libraries: libaio.so.1: cannot open shared object file: No such file or directory
sudo /etc/init.d/apparmor stop
sudo /etc/init.d/apparmor teardown
sudo update-rc.d -f apparmor remove
sudo apt-get purge apparmor

创建脚本:nano pre.sh
#!/bin/bash

sudo /etc/init.d/apparmor stop
sudo /etc/init.d/apparmor teardown
sudo update-rc.d -f apparmor remove
sudo apt-get purge apparmor

赋予权限:chmod +x pre.sh
执行脚本:bash pre.sh
再次执行脚本:bash start.sh
输入密码:TechedDdGo123

报错:mysql.service is not a native service, redirecting to systemd-sysv-install.
Executing: /lib/systemd/systemd-sysv-install enable mysql
Job for mysql.service failed because the control process exited with error code.
See "systemctl status mysql.service" and "journalctl -xe" for details.

开始清除

确定需要删除的文件:

SOURCE_GZ_FILE="/home/lenovo/znzm/tools/mysql/mysql-5.6.36-linux-glibc2.5-x86_64.tar.gz"
INSTALL_DIR="/usr/local/mysql"
/etc/init.d/mysql
/etc/my.cnf
/etc/profile

删除/home/lenovo/znzm/tools/mysql目录:rm -rf /home/lenovo/znzm/tools/mysql
添加/home/lenovo/znzm/tools/mysql目录: mkdir /home/lenovo/znzm/tools/mysql
再次确认:ls -l /home/lenovo/znzm/tools

确认profile: ls -l /etc 确认存在
查看profile: sudo nano /etc/profile
	删除export PATH="$PATH:/usr/local/mysql/bin"
	
确认my.cnf: sudo nano /etc/my.cnf 忽略

确认/etc/init.d/mysql: sudo nano /etc/init.d/mysql 确认存在
删除:sudo rm -rf /etc/init.d/mysql
 
确认/usr/local/mysql目录: ls -l /usr/local/mysql 确认存在
删除:sudo rm -rf /usr/local/mysql

测试服务器安装MySQL成功

setup-mysql.sh

#!/bin/bash

export DEBIAN_FRONTEND="noninteractive"
sudo debconf-set-selections <<< "mysql-server mysql-server/root_password password rootpw"
sudo debconf-set-selections <<< "mysql-server mysql-server/root_password_again password rootpw"


sudo apt-key adv --keyserver pgp.mit.edu --recv-keys 5072E1F5
cat <<- EOF > /etc/apt/sources.list.d/mysql.list
deb http://repo.mysql.com/apt/ubuntu/ trusty mysql-5.7
EOF
sudo apt-get update

sudo apt-get install -y mysql-server-5.7

查看版本

mysqld --version

登录,并授权给root

mysql -u root -p
rootpw

GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'rootpw' WITH GRANT OPTION;
FLUSH PRIVILEGES;
sudo systemctl restart mysql

配置文件

sudo nano /etc/mysql/mysql.conf.d/mysqld.cnf
bind-address            = 0.0.0.0
sudo systemctl status mysql
sudo systemctl restart mysql

公司服务器安装MySQL成功

创建文件`setup-mysql.sh`: sudo nano /home/lenovo/znzm/tools/mysql/setup-mysql.sh

#!/bin/bash

export DEBIAN_FRONTEND="noninteractive"
sudo debconf-set-selections <<< "mysql-server mysql-server/root_password password rootpw"
sudo debconf-set-selections <<< "mysql-server mysql-server/root_password_again password rootpw"


sudo apt-key adv --keyserver pgp.mit.edu --recv-keys 5072E1F5
cat <<- EOF > /etc/apt/sources.list.d/mysql.list
deb http://repo.mysql.com/apt/ubuntu/ trusty mysql-5.7
EOF
sudo apt-get update

sudo apt-get install -y mysql-server-5.7

赋予权限:sudo chmod +x /home/lenovo/znzm/tools/mysql/setup-mysql.sh
运行脚本:sudo bash /home/lenovo/znzm/tools/mysql/setup-mysql.sh

运行失败。原因是安装禅道时已经安装。

尝试登录:/opt/zbox/bin/mysql -u root -P 3306 -p
显示版本:10.5.5-MariaDB

设置MariaDB

确认配置文件路径:sudo nano /opt/zbox/etc/mysql/my.cnf
确认启动开启zbox:/opt/zbox/zbox stop    /opt/zbox/zbox start

修改配置文件:sudo nano /opt/zbox/etc/mysql/my.cnf

bind-address = 0.0.0.0

关闭zobx: sudo /opt/zbox/zbox stop
开启zbox: sudo /opt/zbox/zbox start

Start Mysql fail. You can see the log /opt/zbox/logs/mysql_error.log
cat /opt/zbox/logs/mysql_error.log
Can't start server: Bind on TCP/IP port. Got error: 98: Address already in use,Do you already have another mysqld server running on port: 3306 

再次查看配置文件:sudo nano /opt/zbox/etc/mysql/my.cnf
	socket   = /opt/zbox/tmp/mysql/mysql.sock
    basedir  = /opt/zbox/run/mysql
查看/opt/zox下的tmp权限:ls -l /opt/zbox
重启sudo reboot
查看mysql进程:ps -aux|grep mysql
查看mariadb进程:ps -aux|grep mariadb
查看端口进程:sudo netstat -tunpl|grep 3306  确定进程ID是681
查看进程详情: ps -ef|grep 681
杀死进程:sudo kill 681
关闭zobx: sudo /opt/zbox/zbox stop
开启zbox: sudo /opt/zbox/zbox start

Navicat连接报错:lost connection to MySQL server at reading initial communication packet
sudo ufw allow 3306 还是不行

尝试登录:/opt/zbox/bin/mysql -u root -P 3306 -p
输入密码:

GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY '123456' WITH GRANT OPTION;
FLUSH PRIVILEGES;
exit;

关闭zobx: sudo /opt/zbox/zbox stop
开启zbox: sudo /opt/zbox/zbox start

局域网MySQL:
192.168.8.141
端口:3306
用户名:root
密码:123456

公司服务器安装Redis成功

确定地址:https://download.redis.io/releases/redis-6.2.2.tar.gz
确定当前目录:pwd
创建目录:mkdir redis
进入创建目录:cd redis
下载压缩文件:wget https://download.redis.io/releases/redis-6.2.2.tar.gz
记录压缩文件的位置:/home/lenovo/redis/redis-6.2.2.tar.gz
回到根目录:cd /
解压缩到/user/local下: sudo tar -zxvf /root/redis/redis-6.2.2.tar.gz -C /usr/local
来到local目录下:cd /usr/local   redis-6.2.2目录也在其下
更改redis-6.2.2的名称:sudo mv ./redis-6.2.2 ./redis
创建redis用户组:sudo groupadd redis
查看用户组:cat /etc/group
创建redis用户:sudo useradd -g redis redis
查看用户:cat /etc/passwd
把用户组和用户权限分配到刚才的redis目录:sudo chown -R redis:redis ./redis
进入redis目录:cd redis
安装gcc: sudo apt-get install gcc
查看gcc版本:gcc -v
安装make: sudo apt-get install make
执行命令:sudo make
执行安装命令:sudo make install
打开服务端:./src/redis-server
在另一个终端打开客户端进入redis目录: cd /usr/local/redis
在另一个终端打开客户端:./src/redis-cli
在另一个终端输入:ping
再打开一个终端,查看redis进程:ps -ef|grep redis
在redis客户端终端关闭:shutdown
在redis客户端终端退出:exit

确认redis.conf所在目录:ls -l /usr/local/redis
在etc目录下创建redis目录:sudo mkdir /etc/redis
把redis.conf文件拷贝到/etc/redis下:sudo cp /usr/local/redis/redis.conf /etc/redis
确认是否拷贝成功:ls -l /etc/redis
打开/etc/redis下的配置文件:sudo nano /etc/redis/redis.conf

port 6000
protected-mode no
bind * -::*
dir /var/lib/redis

创建服务文件:sudo nano /etc/systemd/system/redis.service

[Unit]
Description=Redis In-Memory Data Store
After=network.target

[Service]
User=redis
Group=redis
ExecStart=/usr/local/redis/src/redis-server /etc/redis/redis.conf
ExecStop=/usr/local/redis/src/redis-cli shutdown
Restart=always

[Install]
WantedBy=multi-user.target

创建目录:sudo mkdir /var/lib/redis
赋予权限: sudo chown redis:redis /var/lib/redis
其他人没有权限:sudo chmod 770 /var/lib/redis

启动redis: sudo systemctl start redis
查看redis状态:sudo systemctl status redis

本地可以连接但是远程不可以连接。
--sudo ufw allow 6379

局域网Redis:192.168.8.141:6000
密码:无
版本呢:6.2.2

局域网安装Redis成功

确定地址:https://download.redis.io/releases/redis-6.2.2.tar.gz
确定当前目录:pwd
创建目录:mkdir redis
进入创建目录:cd redis
下载压缩文件:wget https://download.redis.io/releases/redis-6.2.2.tar.gz
记录压缩文件的位置:/root/redis/redis-6.2.2.tar.gz
回到根目录:cd /
解压缩到/user/local下: sudo tar -zxvf /root/redis/redis-6.2.2.tar.gz -C /usr/local
来到local目录下:cd /usr/local   redis-6.2.2目录也在其下
更改redis-6.2.2的名称:mv ./redis-6.2.2 ./redis
创建redis用户组:groupadd redis
查看用户组:cat /etc/group
创建redis用户:useradd -g redis redis
查看用户:cat /etc/passwd
把用户组和用户权限分配到刚才的redis目录:sudo chown -R redis:redis ./redis
进入redis目录:cd redis
安装gcc: sudo apt-get install gcc
查看gcc版本:gcc -v
安装make: sudo apt-get install make
执行命令:make
执行安装命令:make install
打开服务端:./src/redis-server
在另一个终端打开客户端进入redis目录: cd /usr/local/redis
在另一个终端打开客户端:./src/redis-cli
在另一个终端输入:ping
再打开一个终端,查看redis进程:ps -ef|grep redis
在redis客户端终端关闭:shutdown
在redis客户端终端退出:exit

确认redis.conf所在目录:/usr/local/redis
在etc目录下创建redis目录:mkdir /etc/redis
把redis.conf文件拷贝到/etc/redis下:sudo cp /usr/local/redis/redis.conf /etc/redis
确认是否拷贝成功:ls /etc/redis
打开/etc/redis下的配置文件:nano /etc/redis/redis.conf

port 6000
protected-mode no
bind * -::*
dir /var/lib/redis

创建服务文件:nano /etc/systemd/system/redis.service

[Unit]
Description=Redis In-Memory Data Store
After=network.target

[Service]
User=redis
Group=redis
ExecStart=/usr/local/redis/src/redis-server /etc/redis/redis.conf
ExecStop=/usr/local/redis/src/redis-cli shutdown
Restart=always

[Install]
WantedBy=multi-user.target

创建目录:sudo mkkir /var/lib/redis
赋予权限: sudo chown redis:redis /var/lib/redis
其他人没有权限:sudo chmod 770 /var/lib/redis

启动redis: sudo systemctl start redis
查看redis状态:sudo systemctl status redis

本地可以连接但是远程不可以连接。
--sudo ufw allow 6379

安装TDengine成功

--准备邮箱
	https://exmail.qq.com/login
	darren@ddingsafe.com
--准备TDEngine官网
	https://www.taosdata.com/	
--查看本地客户端版本:
	./taos.exe -h 116.63.236.99 -u -p
	2.0.20.0
--登录服务器:192.168.8.141
--下载:TDengine-server-2.1.1.0-Linux-x64.deb
--安装:sudo dpkg -i TDengine-server-2.1.1.0-Linux-x64.deb
--启动:sudo systemctl start taosd
--检查:sudo systemctl status taosd
--登录:taos (默认用户名:root, 默认密码:taosdata)
--显示数据库:show databases
--确认接口地址:http://192.168.8.141:6041/rest/sql

部署智能照明网站

--登录服务器:192.168.8.141
--来到根目录:cd /
--查看:ls var
--sudo mkdir /var/www
--sudo mkdir /var/www/znzm
--使用FileZilla传网站文件
	permission denied
	sudo chmod -R 777 /var/www/znzm
--安装SDK
	sudo apt-get update
	sudo apt-get install apt-transport-https
	cd /tmp
	wget https://packages.microsoft.com/config/ubuntu/18.04/packages-microsoft-prod.deb
	sudo dpkg -i packages-microsoft-prod.deb
	sudo apt-get update
	sudo apt install dotnet-sdk-3.1
	dotnet --list-sdks 
--启动网站,来到/var/www/znzm
	dotnet DD.Api.dll
	http://192.168.8.141:5008/swagger/index.html

部署模拟设备网站

cd /var/www
ls
sudo mkdir mock
sudo chmod -R 777 mock

部署开放平台网站

sudo mdkir mock
sudo chmod -R 777 open