Ubuntu 16.04 系统基础开发环境搭建
1.安装 Git
sudo apt-get update
sudo apt-get install git
Do you want to continue? [Y/n] Y
git --version
2. 安装 UFW
sudo apt-get install ufw
sudo ufw enable
sudo ufw default deny
sudo ufw allow 22/tcp
sudo ufw allow 80/tcp
sudo ufw allow 3306/tcp
sudo ufw allow 27017/tcp
sudo ufw allow 6379/tcp
sudo ufw allow 8000:9000/tcp
3.安装 Nginx
sudo apt-get install build-essential
sudo apt-get install libtool
sudo apt-get update
sudo apt-get install libpcre3 libpcre3-dev
sudo apt-get install zlib1g-dev
sudo apt-get install openssl
wget http://nginx.org/download/nginx-1.14.2.tar.gz
tar -zxvf nginx-1.14.2.tar.gz
cd nginx-1.14.2
./configure --prefix=/usr/local/nginx
make
sudo make install
sudo /usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
ps -ef|grep nginx
curl -L http://127.0.0.1/index.html
vi ~/.profile
INSERT >>>>>>>
export PATH=$PATH:/usr/local/nginx/sbin
source ~/.profile
vi /etc/init.d/nginx.server
COPY INSERT >>>>>>>
sudo chmod +x /etc/init.d/nginx.server
sudo sysv-rc-conf nginx.server on
unable to resolve host iZs3y2byjpi9oxZ
解决方案:
vi /etc/hosts
INSERT >>>>>>>
127.0.0.1 iZs3y2byjpi9oxZ
/etc/init.d/nginx.server
#!/bin/sh
set -e
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
DESC="nginx daemon"
NAME=nginx
DAEMON=/usr/local/nginx/sbin/$NAME
SCRIPTNAME=/etc/init.d/$NAME.server
# If the daemon file is not found, terminate the script.
test -x $DAEMON || exit 0
d_start() {
$DAEMON || echo -n " already running"
}
d_stop() {
$DAEMON –s quit || echo -n " not running"
}
d_reload() {
$DAEMON –s reload || echo -n " could not reload"
}
case "$1" in
start)
echo -n "Starting $DESC: $NAME"
d_start
echo "."
;;
stop)
echo -n "Stopping $DESC: $NAME"
d_stop
echo "."
;;
reload)
echo -n "Reloading $DESC configuration..."
d_reload
echo "reloaded."
;;
restart)
echo -n "Restarting $DESC: $NAME"
d_stop
# Sleep for two seconds before starting again, this should give the
# Nginx daemon some time to perform a graceful stop.
sleep 2
d_start
echo "."
;;
*)
echo "Usage: $SCRIPTNAME {start|stop|restart|reload}" >&2
exit 3
;;
esac
exit 0
4.安装 NetCore
wget https://packages.microsoft.com/config/ubuntu/16.04/packages-microsoft-prod.deb -O packages-microsoft-prod.deb
sudo dpkg -i packages-microsoft-prod.deb
sudo apt-get update; \
sudo apt-get install -y apt-transport-https && \
sudo apt-get update && \
sudo apt-get install -y dotnet-sdk-3.1
dotnet --info
5.安装 MySQL
# wget https://downloads.mysql.com/archives/get/p/23/file/mysql-5.7.24-linux-glibc2.12-x86_64.tar.gz
wget https://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-5.7.24-linux-glibc2.12-x86_64.tar.gz
tar zxvf mysql-5.7.24-linux-glibc2.12-x86_64.tar.gz
sudo mv mysql-5.7.24-linux-glibc2.12-x86_64 /usr/local/mysql
vi /etc/my.cnf
COPY INSERT >>>>>>>
cd /usr/local/mysql
groupadd mysql
useradd -r -g mysql mysql
chown -R mysql:mysql ./
sudo bin/mysqld --initialize --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data
# copy initial password
[Note] A temporary password is generated for root@localhost: kiZI&a&kk6SQ
sudo ./support-files/mysql.server start
ps -ef|grep mysql
./bin/mysql -u root -p
Enter password: kiZI&a&kk6SQ
ALTER USER 'root' @'localhost' IDENTIFIED BY '123456';
CREATE USER 'root' @'%' IDENTIFIED BY '123456';
GRANT ALL ON *.* TO 'root' @'%';
FLUSH privileges;
sudo cp ./support-files/mysql.server /etc/init.d/mysql.server
sudo sysv-rc-conf mysql.server on
vi ~/.profile
INSERT >>>>>>>
export PATH=$PATH:/usr/local/mysql/bin
source ~/.profile
/etc/my.cnf
[mysqld]
port = 3306
basedir=/usr/local/mysql
datadir=/usr/local/mysql/data
max_connections=200
max_connect_errors=10
character-set-server=utf8mb4
default-storage-engine=INNODB
default_authentication_plugin=mysql_native_password
[mysql]
default-character-set=utf8mb4
[client]
port=3306
default-character-set=utf8mb4
6.安装 NodeJs
wget https://nodejs.org/dist/v14.15.1/node-v14.15.1-linux-x64.tar.xz
tar xf node-v14.15.1-linux-x64.tar.xz
sudo mv node-v14.15.1-linux-x64 /usr/local/nodejs
cd /usr/local/nodejs
ln -s /usr/local/nodejs/bin/node /usr/local/bin/
node -v
ln -s /usr/local/nodejs/bin/npm /usr/local/bin/
npm -v
npm config set registry https://registry.npm.taobao.org
# install pm2
npm install pm2@latest -g
ln -s /usr/local/nodejs/bin/pm2 /usr/local/bin/
sudo pm2 status
7.安装 MongoDB
wget -qO - https://www.mongodb.org/static/pgp/server-3.4.asc | sudo apt-key add -
echo "deb [ arch=amd64,arm64 ] http://repo.mongodb.org/apt/ubuntu xenial/mongodb-org/3.4 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-3.4.list
sudo apt-get update
sudo apt-get install -y mongodb-org
sudo service mongod start
sudo service mongod status
sudo service mongod stop
vi /etc/mongod.conf
EDIT >>>>>>>
# network interfaces
net:
port: 27017
#bindIp: 127.0.0.1
bindIp: 0.0.0.0
#security:
security:
authorization: enabled
sudo service mongod restart
ps -ef | grep mongod
# 进入数据库
mongo
# 用admin身份
use admin
# 创建超级管理员账号
db.createUser( {user: "admin",pwd: "admin",roles: [ { role: "userAdminAnyDatabase", db: "admin" } ]})
# 测试授权
db.auth("admin","admin")
# 建库授权
use testdb
# 创建数据库管理账号
db.createUser( {user: "root",pwd: "123456",roles: [ { role: "readWrite", db: "testdb" } ]})
# 授权用户
db.auth("root","123456")
# 数据测试
db.log.insert({"created":"db","name":"testdb"})
db.log.insert({"created":"user","name":"root"})
exit
# 开机自启
sudo systemctl enable mongod
/etc/mongod.conf
# mongod.conf
# for documentation of all options, see:
# https://docs.mongodb.com/v3.4/reference/configuration-options/
# systemLog Options:
systemLog:
destination: file
path: "/usr/local/mongodb/log/mongod.log"
logAppend: true
# processManagement Options:
processManagement:
fork: true
# net Options:
net:
port: 27017
#bindIp: 127.0.0.1
bindIp: 0.0.0.0
# security Options:
#security:
security:
authorization: enabled
# setParameter Options:
setParameter:
enableLocalhostAuthBypass: false
# storage Options:
storage:
dbPath: "/usr/local/mongodb/data"
journal:
enabled: true
# operationProfiling Options:
# replication Options:
# sharding Options:
# auditLog Options:
# snmp Options:
MongDB数据库角色对应如下:
- Read:允许用户读取指定数据库
- readWrite:允许用户读写指定数据库
- dbAdmin:允许用户在指定数据库中执行管理函数,如索引创建、删除,查看统计或访问system.profile
- userAdmin:允许用户向system.users集合写入,可以找指定数据库里创建、删除和管理用户
- clusterAdmin:只在admin数据库中可用,赋予用户所有分片和复制集相关函数的管理权限。
- readAnyDatabase:只在admin数据库中可用,赋予用户所有数据库的读权限
- readWriteAnyDatabase:只在admin数据库中可用,赋予用户所有数据库的读写权限
- userAdminAnyDatabase:只在admin数据库中可用,赋予用户所有数据库的userAdmin权限
- dbAdminAnyDatabase:只在admin数据库中可用,赋予用户所有数据库的dbAdmin权限。
- root:只在admin数据库中可用。超级账号,超级权限
7.安装 Redis
sudo apt-get install redis-server
Do you want to continue? [Y/n] Y
ps -ef|grep redis
vi /ect/redis/redis.conf
EDIT >>>>>>>
#bind 127.0.0.1
requirepass 123456
service redis-server restart
服务自启配置
sudo apt-get install sysv-rc-conf
# redis-server
sudo sysv-rc-conf redis-server on
# nginx.server
sudo sysv-rc-conf nginx.server on
# mysql.server
sudo sysv-rc-conf mysql.server on
# mongo
sudo systemctl enable mongod
实例软件的版本:
-
nginx-1.14.2.tar.gz
-
packages-microsoft-prod.deb
-
mysql-5.7.24-linux-glibc2.12-x86_64.tar.gz
-
node-v14.15.1-linux-x64.tar.xz