w3eee / blog Goto Github PK
View Code? Open in Web Editor NEW好像可以用来当博客
好像可以用来当博客
之前项目的golang是1.9, 也没用什么模块依赖管理的工具, 导致新的人来跑一下项目, 搭建环境过程总是有各种各样的问题, 因此我们就开始尝试一些依赖包管理工具. 但是体验了几个, 最后都感觉有点问题. 主要跟我们项目的结构也有关系吧. 项目结构其实也很简单, 就是使用了Grpc架构, 所有会有个编译协议的过程, 以及一些本地模块, 然后再配合项目依赖包管理工具用起来, 总是不顺.
后来发现golang1.11新增了个go mod 算是官方的依赖包管理, 然后拿来用了下, 虽然过程有点问题, 但都算是解决了吧 所以这里记录一下, 免得以后忘了.
go mod init userbase
// 初始化go mod 此命令会自动生成一个go.mod的文件go run main.go
, go mod 会自动搜寻项目的依赖包 然后添加到go.mod文件里面去. 不过执行这个命令最好是终端翻墙 不然会很慢就是了..以上就算基本用法吧 还是很简单的
我们在使用中发现, go mod的依赖包只能是某个host下的才有效, 比如github.com/xxx/xxx 之类的, 那么本地包怎么办呢? 总不能先把本地包上传到github上吧. 后来发现go mod提供了一个replace的功能, 可以用来替换为本地包. 以下举例说明, 比如自己的本地包项目名叫common
go mod init git.com/xxx/common
// 使用的时候也是 import git.com/xx/commonrequire( git.com/xxx/common v0.0.0 ) replace ( git.com/xxx/common v0.0.0 => /data/common // common项目所在的本地路径 )
grpc接口协议的基本项目结构就是 项目名/包名/xxx.proto
// 比如protobuf/user/user.proto
如果协议之间存在import的话 一般就是 import "项目名/包/xxx.proto"
协议编译的golang包其实也算是本地包了 所以就参考以上本地包的处理
那么解决方案就呼之欲出了 直接把项目名(或者协议项目在的目录)改个名字, 比如改成 protobuf.com
然后去go.mod里面用replace替换成本地的protobuf路径就可以了
protobuf.com v0.0.0 => /data/projects/go/protobuf.com
上一步把协议所在的目录改成了protobuf.com会导致用python编译出来的协议包没法用了. 后来我想了一个方案就是在编译协议之前先把它复制一遍 然后把目录名改成protobuf, 再把里面引用的protobuf.com也改掉 然后再生成协议 就行了
具体可以参看编译脚本
https://github.com/Geew/blog/blob/master/build_proto.py
算是个小hack处理吧
go.mod会自动对添加的依赖包进行排序, 有点奇怪. 而且会根据排序的结果, 优先以前面的依赖包的版本为准, 有点绕, 举例说一下. 比如之前的common包里面用到了包X v1.0, 然后在项目userbase也用到了X, 但是userbase的go.mod里面写X v2.0. 这个时候呢, go.mod会自动把userbase中的包X版本强制改成1.0的. 之前遇到这个, 没注意, 还查了好久. 不过一想, 这个机制还是很合理的.
经过以上的处理之后, golang的项目就可以随便放在任何地方了. 而且还有go.mod进行项目的依赖包管理, 可以指定用哪个版本的包. 至此, 项目的依赖管理就告一段落吧.
以上就是我们用到的go mod的实践, 感觉有些用法用得不够优雅, 可能也用错了, 如果有大佬有更方便更优雅的用法 欢迎不吝赐教, 谢谢了.
删除系统自带mysql5.1 如果安装的话
yum list installed | grep mysql
yum -y remove mysql-libs.x86_64
下载并安装源
wget dev.mysql.com/get/mysql-community-release-el6-5.noarch.rpm
yum localinstall mysql-community-release-el6-5.noarch.rpm
yum repolist all | grep mysql
# 查看启用情况
启用mysql57
vim /etc/yum.repos.d/mysql-community.repo
# 将57的enabled改成1, 56的改成0
安装并启动服务
yum install mysql-community-server
service start mysqld
配置
grep 'temporary password' /var/log/mysqld.log
# 查看临时密码
mysql -uroot -p
# 使用临时密码登录
ALTER USER 'root'@'localhost' IDENTIFIED BY 'Mdfd@ddwPass2!';
# 修改密码
添加用户
create user test identified by 'test';
grant all privileges on xxdb.* to test@'%' identified by 'test';
flush privileges;
https://www.jianshu.com/p/0626bbd975f3
ubuntu 开机启动服务
add
update-rc.d –f nginx defaults
remove
update-rc.d -f nginx remove
往rcx.d里面添加启动可执行脚本 x为当前系统runlevel
rcx.d目录下指向启动脚本的符号链接是由K或S+数字+服务名 所组成,中间这个数字十分重要,系统启动时按照这个数字递增执行所有S开头的脚本,系统关闭时按照这个数字递减执行所有K开头的脚本。
如何自定义符号链接? 启动脚本: 因为我刚才的运行级是2级 所以在/etc/rc.d/rc2.d 目录下运行
//重新定义nginx服务的脚本启动顺序
#ln -s /etc/init.d/nginx S99nginx
centos 开机启动服务
add 往/etc/init.d中添加启动程序
命令: chkconfig mysqld on 添加开机启动
服务启动相关
python 安装pylibmc
yum install memcached
install libmemcached0.32
wget https://launchpad.net/libmemcached/1.0/0.32/+download/libmemcached-0.32.tar.gz
tar xvf libmemcached-0.32.tar.gz
cd libmemcached-0.32
./configure
make && make install
install pylibmc
wget https://pypi.python.org/packages/f5/b8/6325cea86a71f25cea81e4d4ea2bc2838079e10f79b5ecacf0b639ca4bff/pylibmc-1.5.2.tar.gz#md5=fe80621781aede8c0dbe7f5a08a1ad7f
tar xvzf pylibmc-1.5.2.tar.gz
cd pylibmc-1.5.2
python2.7 setup.py install --with-libmemcached=/usr/local/lib
install pycurl
解决办法安装curl
[root@qilincaizhe-vmlnx ~]#wget http://curl.haxx.se/download/curl-7.24.0.tar.gz
[root@qilincaizhe-vmlnx ~]#tar -zxvf curl-7.24.0.tar.gz
[root@qilincaizhe-vmlnx ~]#cd curl-7.24
[root@qilincaizhe-vmlnx curl-7.24.0]#./configure
[root@qilincaizhe-vmlnx curl-7.24.0]#make
[root@qilincaizhe-vmlnx curl-7.24.0]#make install
然后
[root@qilincaizhe-vmlnx ~]wget http://pycurl.sourceforge.net/download/pycurl-7.19.0.tar.gz
[root@qilincaizhe-vmlnx ~]tar -zxvf pycurl-7.19.0.tar.gz
[root@qilincaizhe-vmlnx ~]cd pycurl-7.19.0
使用--curl-config=制定curl-config的路径
[root@qilincaizhe-vmlnx pycurl-7.19.0]python setup.py install --curl-config=/usr/local/bin/curl-config
Using /usr/local/bin/curl-config (libcurl 7.24.0)
running install
running build
running build_py
running build_ext
running install_lib
copying build/lib.linux-x86_64-2.7/pycurl.so -> /usr/lib/python2.7/site-packages
running install_data
running install_egg_info
Writing /usr/lib/python2.7/site-packages/pycurl-7.19.0-py2.7.egg-info
安装成功
install PIL
centos:
yum install zlib zlib-devel
yum install libjpeg libjpeg-devel
yum install freetype freetype-devel
3.download Image and install
wget http://effbot.org/downloads/Imaging-1.1.7.tar.gz
tar xzvf Imaging-1.1.7.tar.gz
cd Imaging-1.1.7
mv PIL PIL2
python2.7 selftest.py
install rabbitmq 3.7
update nodejs
Use n module from npm in order to upgrade node
sudo npm cache clean -f
sudo npm install -g n
sudo n stable
To upgrade to latest version (and not current stable) version, you can use
sudo n latest
npm
npm install -g cnpm --registry=https://registry.npm.taobao.org
update
git操作备注
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.